コード例 #1
0
ファイル: Garden.py プロジェクト: oflatt/bearlydancing
    def drawwood(self, time, settings, screen, scale, bottomypos,
                 currentxscroll, endscroll):
        shelfheight = 7 * scale
        shelfdepth = 18 * scale
        shelfdepthoffset = 7 * scale
        shelfyoffset = 2 * scale
        frontcolor = (127, 88, 26)
        left = 10 * scale - currentxscroll
        shelfwidth = max(endscroll - scale * 10, screen.get_width() / 2)

        frontrect = Rect(left, bottomypos - shelfheight + shelfyoffset,
                         shelfwidth, shelfheight)

        # draw depth
        depthplist = [(frontrect[0], frontrect[1]),
                      (frontrect[0] + shelfdepthoffset,
                       frontrect[1] - shelfheight),
                      (frontrect[0] + frontrect.width + shelfdepthoffset,
                       frontrect[1] - shelfheight),
                      (frontrect[0] + frontrect.width, frontrect[1])]
        gfxdraw.filled_polygon(screen, depthplist,
                               variables.brighten(frontcolor, 13))

        # draw front
        gfxdraw.box(screen, frontrect, frontcolor)

        # draw right side
        rsideplist = [
            depthplist[-2], depthplist[-1],
            (frontrect[0] + frontrect.width, frontrect[1] + shelfheight),
            (depthplist[-2][0], depthplist[-2][1] + shelfheight)
        ]
        gfxdraw.filled_polygon(screen, rsideplist,
                               variables.brighten(frontcolor, -3))
コード例 #2
0
ファイル: Garden.py プロジェクト: oflatt/pythonRpgProject
    def drawwood(self, time, settings, screen, scale, currentxscroll, bottomypos):

        shelfwidth = currentxscroll + screen.get_width()
        
        
        shelfheight = 7*scale
        shelfdepth = 18*scale
        shelfdepthoffset = 7*scale
        shelfyoffset = 2*scale
        frontcolor = (127, 88, 26)

        frontrect = Rect(-currentxscroll+10*scale, bottomypos-shelfheight+shelfyoffset, 80*scale, shelfheight)

        # draw depth
        depthplist = [(frontrect[0], frontrect[1]),
                      (frontrect[0]+shelfdepthoffset, frontrect[1]-shelfheight),
                      (frontrect[0]+frontrect.width+shelfdepthoffset,
                       frontrect[1]-shelfheight),
                      (frontrect[0]+frontrect.width, frontrect[1])]
        gfxdraw.filled_polygon(screen, depthplist, variables.brighten(frontcolor, 13))
        
        # draw front
        gfxdraw.box(screen, frontrect, frontcolor)

        # draw right side
        rsideplist = [depthplist[-2], depthplist[-1],
                      (frontrect[0]+frontrect.width, frontrect[1]+shelfheight),
                      (depthplist[-2][0], depthplist[-2][1]+shelfheight)]
        gfxdraw.filled_polygon(screen, rsideplist, variables.brighten(frontcolor, -3))
コード例 #3
0
ファイル: shopplants.py プロジェクト: oflatt/bearlydancing
def makestarter():
    # make the starter flower
    petal_list = [(0.0, 0.0)]
    petal_numofpoints = 13
    for x in range(petal_numofpoints):
        petal_list.append((x, 4 * math.sin(x / petal_numofpoints * math.pi)))

    middlecolor = (241, 252, 63)
    middletexture = Texture(brighten(middlecolor, -50),
                            0.2,
                            0.05,
                            0.05,
                            acceptedcolors=[middlecolor])

    middleradius = 2.5
    middlelist = listarc(-middleradius, 0, middleradius * 2, middleradius, 8)
    middleshape = PlantShape(middlelist, middlecolor,
                             brighten(middlecolor, -30))

    # set the texture of the middle of the flower to fill in some dark pixels
    middleshape = middleshape.destructiveset("textures", [middletexture])

    middlenode = PlantNode([middleshape], 1, math.pi / 20)

    petal_shape = PlantShape(petal_list, (0, 0, 200), (0, 0, 120))
    petalnode = PlantNode([petal_shape], 5, math.pi * 2 / 5)

    starter_flower = PlantNode([bigstem_plantshape],
                               1,
                               math.pi / 10,
                               children=[middlenode, petalnode])

    return ShopPlant("blue flower", starter_flower, 0)
コード例 #4
0
ファイル: shopplants.py プロジェクト: oflatt/bearlydancing
def testcactus():
    spikecolor = (80, 80, 80)

    body_list = [(0, 0)]
    body_numofpoints = 20
    roundedness = 3.5
    for x in range(body_numofpoints):
        body_list.append(
            (x, -(5 * math.sin(x**roundedness / body_numofpoints**roundedness *
                               math.pi / 2 + math.pi / 2))))

    cactuscolor = (29, 183, 55)
    cactuslinecolor = brighten(cactuscolor, -20)
    spiketexture = Texture(spikecolor, 0.1, 0.2, 0.05)
    spiketexture.acceptedcolorsspawn = [cactuscolor, cactuslinecolor]

    bodylineshapes = []
    number_of_lines = 2
    for i in range(number_of_lines):
        bodylinelist = scalepointlist(body_list,
                                      1 - ((i + 1) / (number_of_lines + 1)), 1)
        rightlinelist = flippointlist(bodylinelist)
        bodylinelist = linelist_to_shapelist(bodylinelist)
        rightlinelist = linelist_to_shapelist(rightlinelist)
        bodylineshapes.append(
            PlantShape(bodylinelist,
                       brighten(cactuscolor, -40),
                       cactuslinecolor,
                       completelistp=True,
                       textures=[spiketexture]))
        bodylineshapes.append(
            PlantShape(rightlinelist,
                       brighten(cactuscolor, -40),
                       cactuslinecolor,
                       completelistp=True,
                       textures=[spiketexture]))

    body_shape = PlantShape(body_list, cactuscolor,
                            brighten(cactuslinecolor, -20))
    body_shape = body_shape.destructiveset("textures", [spiketexture])
    body_node = PlantNode([body_shape] + bodylineshapes,
                          1,
                          math.pi / 5,
                          children=[])
    body_node = body_node.destructiveset("shiftchance", 0.0)
    body_node = body_node.destructiveset("widthvariance", 0.4)
    body_node = body_node.destructiveset("heightvariance", 0.4)

    body_node3 = copy.deepcopy(body_node)
    body_node2 = copy.deepcopy(body_node)
    body_node2 = body_node2.destructiveset("repeatnumseparate", 5)
    body_node2 = body_node2.destructiveset("brancharea", 1)
    body_node2 = body_node2.destructiveset("children", [body_node3])

    body_node = body_node.destructiveset("children", [body_node2])

    return ShopPlant("testcactus", body_node, 40)
コード例 #5
0
def drawpot(potwidth):
    potcolor = brighten(randomnicecolor(), -100)

    potheight = int(potwidth * 1.5)

    surface = pygame.Surface((potwidth + 1, potheight + 1), pygame.SRCALPHA)
    midx = (potwidth / 2)
    rimheight = potheight / 2

    toparc = listarc(0, rimheight / 2, potwidth, rimheight / 2, int(potwidth))
    toparclowered = []
    for i in range(len(toparc)):
        toparclowered.append(toparc[i].copy())
        toparclowered[i][1] += 2

    bottomarc = listarc(potwidth, rimheight / 2, -potwidth, -rimheight / 2,
                        int(potwidth))

    #for i in range(len(bottomarc)):
    #    bottomarc[i][1] = math.ceil(bottomarc[i][1])

    rim = toparc + bottomarc

    for i in range(len(rim)):
        rim[i][0] = round(rim[i][0])

    basearc = listarc(potwidth / 6, potheight - 1 - rimheight / 2,
                      potwidth - 2 * potwidth / 6, -rimheight / 6,
                      int(potwidth))
    baselist = [bottomarc[2], bottomarc[-3]] + basearc
    # draw the base of the pot
    pygame.gfxdraw.filled_polygon(surface, baselist, brighten(potcolor, 20))

    # draw the inside of pot
    pygame.gfxdraw.filled_polygon(surface, rim, potcolor)
    # draw soil
    pygame.gfxdraw.filled_polygon(surface, toparclowered + bottomarc,
                                  dirtcolor)
    # draw rim of pot
    pygame.gfxdraw.polygon(surface, rim, brighten(potcolor, 30))

    return surface
コード例 #6
0
ファイル: rdrawsoil.py プロジェクト: oflatt/pythonRpgProject
def drawpot(potwidth):
    potcolor = brighten(randomnicecolor(), -100)
    
    potheight = int(potwidth*1.5)
    
    surface = pygame.Surface((potwidth+1, potheight+1), pygame.SRCALPHA)
    midx = (potwidth/2)
    rimheight = potheight/2

    toparc = listarc(0, rimheight/2, potwidth, rimheight/2, int(potwidth))
    toparclowered = []
    for i in range(len(toparc)):
        toparclowered.append(toparc[i].copy())
        toparclowered[i][1] += 2

    bottomarc = listarc(potwidth, rimheight/2, -potwidth, -rimheight/2, int(potwidth))

    #for i in range(len(bottomarc)):
    #    bottomarc[i][1] = math.ceil(bottomarc[i][1])
    
    rim = toparc + bottomarc

    for i in range(len(rim)):
        rim[i][0] = round(rim[i][0])



    basearc = listarc(potwidth/6, potheight-1-rimheight/2, potwidth-2*potwidth/6, -rimheight/6, int(potwidth))
    baselist = [bottomarc[2], bottomarc[-3]] + basearc
    # draw the base of the pot
    pygame.gfxdraw.filled_polygon(surface, baselist, brighten(potcolor, 20))

    # draw the inside of pot
    pygame.gfxdraw.filled_polygon(surface, rim, potcolor)
    # draw soil
    pygame.gfxdraw.filled_polygon(surface, toparclowered+bottomarc, dirtcolor)
    # draw rim of pot
    pygame.gfxdraw.polygon(surface, rim, brighten(potcolor, 30))

    return surface
コード例 #7
0
ファイル: drawplant.py プロジェクト: oflatt/pythonRpgProject
def drawplant(head_node):
    devprint("drawing plant")
    
    surface = Surface((40, 43), SRCALPHA)
    rootpos = (surface.get_width()/2, surface.get_height()-3)
    
    
    # the stack has the node, the currentx, and the currenty for each node in it
    # currentx and currenty are without resizing of the surface
    stack = []
    # keeps track of offset needed because of resizing the surface
    resizeoffset = (0, 0)

    for i in range(head_node.repeatnumseparate):
        stack.append(head_node)
        firstx = potwidth * random.random() * head_node.brancharea + rootpos[0]
        stack.append(firstx)
        stack.append(rootpos[1])
        stack.append(math.pi/2) # base angle strait up to start with
    
    callcount = 0

    while len(stack) != 0 and callcount < 1000:
        
        callcount += 1
        base_angle = stack.pop()
        currenty = stack.pop()
        currentx = stack.pop()
        node = stack.pop()
        
        randomspacings = [0]
        spacingLength = 0
        for i in range(node.repeatnumcircle-1):
            randomspacings.append(random.uniform(node.anglespace-node.anglevariance*node.anglespace, node.anglespace+node.anglevariance*node.anglespace))
            spacingLength += randomspacings[i+1]

        startspacing = random.uniform(-node.anglevariance*node.anglespace, node.anglevariance*node.anglespace)/2 * random.choice((-1, 1))
        
        # start angle so that it points up on average
        angle = base_angle + startspacing - (spacingLength/2)  + node.angleoffset*random.choice((-1, 1))

        # update the random spacing to be final angles
        for i in range(len(randomspacings)):
            angle = angle + randomspacings[i]
            randomspacings[i] = angle

        for i in range(node.repeatnumcircle):
            # draw all the plantshapes at this angle
            # pick a random angle out of the list
            angle = randomspacings.pop(random.randint(0, len(randomspacings)-1))

            widthscalar = 1 + random.random()*node.widthvariance
            heightscalar = 1 + random.random()*node.heightvariance

            # now add the current node
            surface, mainltranslated, mainloffset, new_resize_offset = surface_with_node(surface, node, angle, (currentx, currenty), resizeoffset,  widthscalar, heightscalar)
            resizeoffset = new_resize_offset

            
            # find the new currentx and currenty
            mainlistlen = len(mainltranslated)

            
            # add all the children at the current position
            for childnode in node.children:
                futureindexpositions = getfuturenodeindexpositions(childnode.repeatnumseparate, mainlistlen, childnode.brancharea)
                for i in range(childnode.repeatnumseparate):
                    futurex = mainltranslated[futureindexpositions[i]][0]+mainloffset[0]
                    futurey = mainltranslated[futureindexpositions[i]][1]+mainloffset[1]
                    stack.append(childnode)
                    stack.append(futurex)
                    stack.append(futurey)
                    futureangle = listangleatindex(mainltranslated, futureindexpositions[i])
                    stack.append(futureangle)

    finalsurfaceanchor = (rootpos[0] + resizeoffset[0], rootpos[1]+resizeoffset[1])
                
    # draw dirt clumps at bottom
    clumpradius = 4
    clumprange = 14
    clumpnum = 4
    
    for i in range(clumpnum):
        gfxdraw.filled_circle(surface, int(finalsurfaceanchor[0] + i * clumprange/clumpnum - clumprange/2)+1,
                       int(finalsurfaceanchor[1]),
                       int(random.uniform(clumpradius/3, clumpradius)),
                        brighten(dirtcolor, -10))
        
    return surface, finalsurfaceanchor 
コード例 #8
0
ファイル: rdrawsoil.py プロジェクト: oflatt/pythonRpgProject
import pygame, random, math
from pygame import Rect

from .pointlist import listarc
from variables import brighten, randomnicecolor


dirtcolor = brighten((89, 55, 15), -10)
# a "pot" is just a lump on the ground to grow stuff in
def drawpot(potwidth):
    potcolor = brighten(randomnicecolor(), -100)
    
    potheight = int(potwidth*1.5)
    
    surface = pygame.Surface((potwidth+1, potheight+1), pygame.SRCALPHA)
    midx = (potwidth/2)
    rimheight = potheight/2

    toparc = listarc(0, rimheight/2, potwidth, rimheight/2, int(potwidth))
    toparclowered = []
    for i in range(len(toparc)):
        toparclowered.append(toparc[i].copy())
        toparclowered[i][1] += 2

    bottomarc = listarc(potwidth, rimheight/2, -potwidth, -rimheight/2, int(potwidth))

    #for i in range(len(bottomarc)):
    #    bottomarc[i][1] = math.ceil(bottomarc[i][1])
    
    rim = toparc + bottomarc
コード例 #9
0
def makecabinet(gamename):
    width = 28
    height = 48
    # make it bigger in case cropped off
    surface = pygame.Surface((width+3, height), pygame.SRCALPHA)

    # the width of the front of the cabinet from the left edge to the right edge of the controls
    frontwidth = randint(int(width/2), int(width * 0.75))
    widthleft = width-frontwidth
    backwidth = min(frontwidth / 4, widthleft)

    cabinetheight = height*0.7

    topoffrontypos = height - cabinetheight

    topedgeoffset = frontwidth / 10
    topedgeheight = frontwidth / 4
    # right, left, bottom left, bottom right (counter-clockwise)
    topfront = ((backwidth+frontwidth+topedgeoffset, topoffrontypos),
                (backwidth+topedgeoffset, topoffrontypos),
                (backwidth, topoffrontypos+topedgeheight),
                (backwidth+frontwidth, topoffrontypos+topedgeheight))
    displayheight = int((height - topfront[-1][1]) / 2.3)
    buttonareaheight = displayheight/4
    coinareaheight = int((height - topfront[-1][1]) - displayheight - buttonareaheight)
    
    frontdisplayarea = (topfront[-1], topfront[-2],
                        (topfront[-2][0], topfront[-2][1]+displayheight),
                        (topfront[-1][0], topfront[-1][1]+displayheight))

    screenshrink = 2
    screenarea = ((frontdisplayarea[0][0]-screenshrink, frontdisplayarea[0][1]+screenshrink),
                  (frontdisplayarea[1][0]+screenshrink, frontdisplayarea[1][1]+screenshrink),
                  (frontdisplayarea[2][0]+screenshrink, frontdisplayarea[2][1]-screenshrink),
                  (frontdisplayarea[3][0]-screenshrink, frontdisplayarea[3][1]-screenshrink))

    coinslotxoffset = frontwidth/4

    
    
    buttonsarea = (frontdisplayarea[-1], frontdisplayarea[-2],
                   (frontdisplayarea[-2][0]+coinslotxoffset, frontdisplayarea[-2][1] + buttonareaheight),
                   (frontdisplayarea[-1][0]+coinslotxoffset, frontdisplayarea[-1][1] + buttonareaheight))

    coinslotarea = (buttonsarea[-1], buttonsarea[-2],
                    (buttonsarea[-2][0], buttonsarea[-2][1] + coinareaheight),
                    (buttonsarea[-1][0], buttonsarea[-1][1] + coinareaheight))

    yoffsetback = backwidth / 3
    backx = topfront[1][0]-backwidth
    sidearea = (topfront[1],
                (backx, topfront[1][1] - yoffsetback),
                (backx,  coinslotarea[-2][1]-yoffsetback*((coinslotarea[-2][0]-backx)/float(backwidth))),
                coinslotarea[-2])

    toparea = ((sidearea[1][0]+frontwidth, sidearea[1][1]),
               sidearea[1],
               sidearea[0],
               ((sidearea[0][0] + frontwidth), sidearea[0][1]))

    
    machinecolor = variables.randomnicecolor()

    pygame.gfxdraw.filled_polygon(surface, sidearea, machinecolor)
    
    screenbordercolor = variables.randomnicecolor()

    pygame.gfxdraw.filled_polygon(surface, toparea, variables.brighten(random.choice((machinecolor, screenbordercolor)), -20))
    
    pygame.gfxdraw.filled_polygon(surface, topfront, variables.brighten(random.choice((machinecolor, screenbordercolor)), -40))

    pygame.gfxdraw.filled_polygon(surface, frontdisplayarea, screenbordercolor)
    pygame.gfxdraw.filled_polygon(surface, screenarea, variables.BLACK)

    pygame.gfxdraw.filled_polygon(surface, buttonsarea, variables.brighten(screenbordercolor, -50))

    # draw buttons on button area
    
    buttonsy = buttonsarea[0][1] + (buttonareaheight/3)
    buttonxmin = buttonsarea[-2][0]
    buttonxwidth = buttonsarea[0][0]-buttonxmin
    pygame.gfxdraw.circle(surface, int(buttonxmin + buttonxwidth * 0.2), int(buttonsy), int(buttonxwidth*0.05), variables.RED)
    pygame.gfxdraw.circle(surface, int(buttonxmin + buttonxwidth * 0.35), int(buttonsy), int(buttonxwidth*0.05), variables.RED)
    pygame.gfxdraw.circle(surface, int(buttonxmin + buttonxwidth * 0.7), int(buttonsy), int(buttonxwidth*0.05), variables.BLUE)

    coinslotareacolor = variables.brighten(machinecolor, -30)
    pygame.gfxdraw.filled_polygon(surface, coinslotarea, coinslotareacolor)
    pygame.gfxdraw.polygon(surface, coinslotarea, variables.brighten(coinslotareacolor, -20))

    # draw coin slot
    coinslotareaw = (coinslotarea[0][0]-coinslotarea[1][0])
    coinslotareah = (coinslotarea[2][1]-coinslotarea[1][1])
    coinslotrect = Rect(int(coinslotarea[1][0] + coinslotareaw/3), int(coinslotarea[0][1] + coinslotareah*0.3), coinslotareaw  * 0.3, coinslotareah * 0.4)
    pygame.gfxdraw.box(surface, coinslotrect, (40, 40, 40))

    return surface
コード例 #10
0
ファイル: rdrawarcade.py プロジェクト: oflatt/bearlydancing
def makecabinet(gamename):
    width = 28
    height = 48
    # make it bigger in case cropped off
    surface = pygame.Surface((width + 3, height), pygame.SRCALPHA)

    # the width of the front of the cabinet from the left edge to the right edge of the controls
    frontwidth = randint(int(width / 2), int(width * 0.75))
    widthleft = width - frontwidth
    backwidth = min(frontwidth / 4, widthleft)

    cabinetheight = height * 0.7

    topoffrontypos = height - cabinetheight

    topedgeoffset = frontwidth / 10
    topedgeheight = frontwidth / 4
    # right, left, bottom left, bottom right (counter-clockwise)
    topfront = ((backwidth + frontwidth + topedgeoffset,
                 topoffrontypos), (backwidth + topedgeoffset, topoffrontypos),
                (backwidth, topoffrontypos + topedgeheight),
                (backwidth + frontwidth, topoffrontypos + topedgeheight))
    displayheight = int((height - topfront[-1][1]) / 2.3)
    buttonareaheight = displayheight / 4
    coinareaheight = int((height - topfront[-1][1]) - displayheight -
                         buttonareaheight)

    frontdisplayarea = (topfront[-1], topfront[-2],
                        (topfront[-2][0], topfront[-2][1] + displayheight),
                        (topfront[-1][0], topfront[-1][1] + displayheight))

    screenshrink = 2
    screenarea = ((frontdisplayarea[0][0] - screenshrink,
                   frontdisplayarea[0][1] + screenshrink),
                  (frontdisplayarea[1][0] + screenshrink,
                   frontdisplayarea[1][1] + screenshrink),
                  (frontdisplayarea[2][0] + screenshrink,
                   frontdisplayarea[2][1] - screenshrink),
                  (frontdisplayarea[3][0] - screenshrink,
                   frontdisplayarea[3][1] - screenshrink))

    coinslotxoffset = frontwidth / 4

    buttonsarea = (frontdisplayarea[-1], frontdisplayarea[-2],
                   (frontdisplayarea[-2][0] + coinslotxoffset,
                    frontdisplayarea[-2][1] + buttonareaheight),
                   (frontdisplayarea[-1][0] + coinslotxoffset,
                    frontdisplayarea[-1][1] + buttonareaheight))

    coinslotarea = (buttonsarea[-1], buttonsarea[-2],
                    (buttonsarea[-2][0], buttonsarea[-2][1] + coinareaheight),
                    (buttonsarea[-1][0], buttonsarea[-1][1] + coinareaheight))

    yoffsetback = backwidth / 3
    backx = topfront[1][0] - backwidth
    sidearea = (topfront[1], (backx, topfront[1][1] - yoffsetback),
                (backx, coinslotarea[-2][1] - yoffsetback *
                 ((coinslotarea[-2][0] - backx) / float(backwidth))),
                coinslotarea[-2])

    toparea = ((sidearea[1][0] + frontwidth, sidearea[1][1]), sidearea[1],
               sidearea[0], ((sidearea[0][0] + frontwidth), sidearea[0][1]))

    machinecolor = variables.randomnicecolor()

    pygame.gfxdraw.filled_polygon(surface, sidearea, machinecolor)

    screenbordercolor = variables.randomnicecolor()

    pygame.gfxdraw.filled_polygon(
        surface, toparea,
        variables.brighten(random.choice((machinecolor, screenbordercolor)),
                           -20))

    pygame.gfxdraw.filled_polygon(
        surface, topfront,
        variables.brighten(random.choice((machinecolor, screenbordercolor)),
                           -40))

    pygame.gfxdraw.filled_polygon(surface, frontdisplayarea, screenbordercolor)
    pygame.gfxdraw.filled_polygon(surface, screenarea, variables.BLACK)

    pygame.gfxdraw.filled_polygon(surface, buttonsarea,
                                  variables.brighten(screenbordercolor, -50))

    # draw buttons on button area

    buttonsy = buttonsarea[0][1] + (buttonareaheight / 3)
    buttonxmin = buttonsarea[-2][0]
    buttonxwidth = buttonsarea[0][0] - buttonxmin
    pygame.gfxdraw.circle(surface, int(buttonxmin + buttonxwidth * 0.2),
                          int(buttonsy), int(buttonxwidth * 0.05),
                          variables.RED)
    pygame.gfxdraw.circle(surface, int(buttonxmin + buttonxwidth * 0.35),
                          int(buttonsy), int(buttonxwidth * 0.05),
                          variables.RED)
    pygame.gfxdraw.circle(surface, int(buttonxmin + buttonxwidth * 0.7),
                          int(buttonsy), int(buttonxwidth * 0.05),
                          variables.BLUE)

    coinslotareacolor = variables.brighten(machinecolor, -30)
    pygame.gfxdraw.filled_polygon(surface, coinslotarea, coinslotareacolor)
    pygame.gfxdraw.polygon(surface, coinslotarea,
                           variables.brighten(coinslotareacolor, -20))

    # draw coin slot
    coinslotareaw = (coinslotarea[0][0] - coinslotarea[1][0])
    coinslotareah = (coinslotarea[2][1] - coinslotarea[1][1])
    coinslotrect = Rect(int(coinslotarea[1][0] + coinslotareaw / 3),
                        int(coinslotarea[0][1] + coinslotareah * 0.3),
                        coinslotareaw * 0.3, coinslotareah * 0.4)
    pygame.gfxdraw.box(surface, coinslotrect, (40, 40, 40))

    return surface
コード例 #11
0
def drawplant(head_node):
    devprint("drawing plant")
    
    surface = Surface((40, 43), SRCALPHA)
    rootpos = (surface.get_width()/2, surface.get_height()-3)
    
    
    # the stack has the node, the currentx, and the currenty for each node in it
    # currentx and currenty are without resizing of the surface
    stack = []
    # keeps track of offset needed because of resizing the surface
    resizeoffset = (0, 0)

    for i in range(head_node.repeatnumseparate):
        stack.append(head_node)
        firstx = potwidth * random.random() * head_node.brancharea + rootpos[0]
        stack.append(firstx)
        stack.append(rootpos[1])
        stack.append(math.pi/2) # base angle strait up to start with
    
    callcount = 0

    while len(stack) != 0 and callcount < 1000:
        
        callcount += 1
        base_angle = stack.pop()
        currenty = stack.pop()
        currentx = stack.pop()
        node = stack.pop()
        
        randomspacings = [0]
        spacingLength = 0
        for i in range(node.repeatnumcircle-1):
            randomspacings.append(random.uniform(node.anglespace-node.anglevariance*node.anglespace, node.anglespace+node.anglevariance*node.anglespace))
            spacingLength += randomspacings[i+1]

        startspacing = random.uniform(-node.anglevariance*node.anglespace, node.anglevariance*node.anglespace)/2 * random.choice((-1, 1))
        
        # start angle so that it points up on average
        angle = base_angle + startspacing - (spacingLength/2)  + node.angleoffset*random.choice((-1, 1))

        # update the random spacing to be final angles
        for i in range(len(randomspacings)):
            angle = angle + randomspacings[i]
            randomspacings[i] = angle

        for i in range(node.repeatnumcircle):
            # draw all the plantshapes at this angle
            # pick a random angle out of the list
            angle = randomspacings.pop(random.randint(0, len(randomspacings)-1))

            widthscalar = 1 + random.random()*node.widthvariance
            heightscalar = 1 + random.random()*node.heightvariance

            # now add the current node
            surface, mainltranslated, mainloffset, new_resize_offset = surface_with_node(surface, node, angle, (currentx, currenty), resizeoffset,  widthscalar, heightscalar)
            resizeoffset = new_resize_offset

            
            # find the new currentx and currenty
            mainlistlen = len(mainltranslated)

            
            # add all the children at the current position
            for childnode in node.children:
                futureindexpositions = getfuturenodeindexpositions(childnode.repeatnumseparate, mainlistlen, childnode.brancharea, childnode.branchoffset)
                for i in range(childnode.repeatnumseparate):
                    futurex = mainltranslated[futureindexpositions[i]][0]+mainloffset[0]
                    futurey = mainltranslated[futureindexpositions[i]][1]+mainloffset[1]
                    stack.append(childnode)
                    stack.append(futurex)
                    stack.append(futurey)
                    futureangle = listangleatindex(mainltranslated, futureindexpositions[i])
                    stack.append(futureangle)

    finalsurfaceanchor = (rootpos[0] + resizeoffset[0], rootpos[1]+resizeoffset[1])
                
    # draw dirt clumps at bottom
    clumpradius = 4
    clumprange = 14
    clumpnum = 4
    
    for i in range(clumpnum):
        gfxdraw.filled_circle(surface, int(finalsurfaceanchor[0] + i * clumprange/clumpnum - clumprange/2)+1,
                       int(finalsurfaceanchor[1]),
                       int(random.uniform(clumpradius/3, clumpradius)),
                        brighten(dirtcolor, -10))
        
    return surface, finalsurfaceanchor 
コード例 #12
0
def adddancearrows(GR):
    # duplicate and rotate the left arrow
    leftdancearrow = GR["leftdancearrow"]["img"]
    rightdancearrow = variables.transformrotate(leftdancearrow, 180)
    downdancearrow = variables.transformrotate(leftdancearrow, 270)
    updancearrow = variables.transformrotate(leftdancearrow, 90)

    leftdancearrowdark = leftdancearrow.copy()
    rightdancearrowdark = rightdancearrow.copy()
    updancearrowdark = updancearrow.copy()
    downdancearrowdark = downdancearrow.copy()

    pygame.PixelArray(leftdancearrow).replace(
        (255, 255, 255), variables.brighten(variables.notes_colors[0], -40))
    pygame.PixelArray(rightdancearrow).replace(
        (255, 255, 255), variables.brighten(variables.notes_colors[3], -40))
    pygame.PixelArray(updancearrow).replace(
        (255, 255, 255), variables.brighten(variables.notes_colors[2], -40))
    pygame.PixelArray(downdancearrow).replace(
        (255, 255, 255), variables.brighten(variables.notes_colors[1], -40))

    pygame.PixelArray(leftdancearrowdark).replace(
        (255, 255, 255), variables.brighten(variables.notes_colors[0], -100))
    pygame.PixelArray(rightdancearrowdark).replace(
        (255, 255, 255), variables.brighten(variables.notes_colors[3], -100))
    pygame.PixelArray(updancearrowdark).replace(
        (255, 255, 255), variables.brighten(variables.notes_colors[2], -100))
    pygame.PixelArray(downdancearrowdark).replace(
        (255, 255, 255), variables.brighten(variables.notes_colors[1], -100))

    pygame.PixelArray(leftdancearrow).replace((0, 0, 0),
                                              variables.notes_colors[0])
    pygame.PixelArray(rightdancearrow).replace((0, 0, 0),
                                               variables.notes_colors[3])
    pygame.PixelArray(updancearrow).replace((0, 0, 0),
                                            variables.notes_colors[2])
    pygame.PixelArray(downdancearrow).replace((0, 0, 0),
                                              variables.notes_colors[1])

    pygame.PixelArray(leftdancearrowdark).replace(
        (0, 0, 0), variables.brighten(variables.notes_colors[0], -50))
    pygame.PixelArray(rightdancearrowdark).replace(
        (0, 0, 0), variables.brighten(variables.notes_colors[3], -50))
    pygame.PixelArray(updancearrowdark).replace(
        (0, 0, 0), variables.brighten(variables.notes_colors[2], -50))
    pygame.PixelArray(downdancearrowdark).replace(
        (0, 0, 0), variables.brighten(variables.notes_colors[1], -50))

    GR["leftdancearrow"]["img"] = leftdancearrow
    addsurfaceGR(GR, rightdancearrow, "rightdancearrow")
    addsurfaceGR(GR, updancearrow, "updancearrow")
    addsurfaceGR(GR, downdancearrow, "downdancearrow")

    addsurfaceGR(GR, leftdancearrowdark, "leftdancearrowdark")
    addsurfaceGR(GR, rightdancearrowdark, "rightdancearrowdark")
    addsurfaceGR(GR, updancearrowdark, "updancearrowdark")
    addsurfaceGR(GR, downdancearrowdark, "downdancearrowdark")
コード例 #13
0
import pygame, random, math
from pygame import Rect

from .pointlist import listarc
from variables import brighten, randomnicecolor

dirtcolor = brighten((89, 55, 15), -10)


# a "pot" is just a lump on the ground to grow stuff in
def drawpot(potwidth):
    potcolor = brighten(randomnicecolor(), -100)

    potheight = int(potwidth * 1.5)

    surface = pygame.Surface((potwidth + 1, potheight + 1), pygame.SRCALPHA)
    midx = (potwidth / 2)
    rimheight = potheight / 2

    toparc = listarc(0, rimheight / 2, potwidth, rimheight / 2, int(potwidth))
    toparclowered = []
    for i in range(len(toparc)):
        toparclowered.append(toparc[i].copy())
        toparclowered[i][1] += 2

    bottomarc = listarc(potwidth, rimheight / 2, -potwidth, -rimheight / 2,
                        int(potwidth))

    #for i in range(len(bottomarc)):
    #    bottomarc[i][1] = math.ceil(bottomarc[i][1])