def drawFlowerz(size,angle,diamondAngle): #draws flower, with size being the height of one diamond and angle  being the rotation of the flower
    f=GCompound()
    numDiamonds=360//diamondAngle
    theta=angle
    for i in range(numDiamonds):
        f.add(drawDiamond(size,theta,colors[i],diamondAngle))
        theta+=diamondAngle
    return f
Exemple #2
0
	def createRedCross(w, h):
		cross = GCompound()
		rect_1 = GRect(-w / 2, -h / 2, LONG_SIDE, SHORT_SIDE)
		rect_1.setFilled(True)
		rect_1.setColor('red')
		cross.add(rect_1)
		rect_2 = GRect(-h / 2, -w / 2, SHORT_SIDE, LONG_SIDE)
		rect_2.setFilled(True)
		rect_2.setColor('red')
		cross.add(rect_2)
		return cross
def createButton(s):# makes a button with the string s
    button=GCompound()
    buttonSize=75
    label=GLabel(s)
    label.setColor("white")
    label.setFont("8px 'Sans-Serif'")
    c=GOval(-(label.getWidth()+20)//2,-buttonSize//2,label.getWidth()+20,buttonSize)
    c.setFillColor("black")
    c.setFilled(True)
    button.add(c)
    button.add(label,-label.getWidth()//2,0)
    return button
Exemple #4
0
    def create_rocket():
        """
        Function to create the compound rocket object. Including the core,
        1 fin on each side, and a nose cap. Should return the compound object.
        """
        rocket = GCompound()
        core = create_filled_rect(0, 0, ROCKET_WIDTH, ROCKET_HEIGHT, "oldlace")
        rocket.add(core, -ROCKET_WIDTH / 2, -ROCKET_HEIGHT)

        # Add your code below to add more pieces to the rocket!

        return rocket
def create_object():
    """
    Creates the original DVD Logo. Code from here will be moved into
    the new class that you are creating.
    """

    width = 200
    height = 200

    obj = GCompound()

    cube = GRect(0, 0, width, height)
    cube.set_filled(True)
    cube.set_color(random_color())
    obj.add(cube)

    dvdtext = GLabel("DVD")
    dvdtext.set_font("bold 60px 'serif'")
    obj.add(dvdtext, width / 2 - dvdtext.get_width() / 2, height / 2 - 10)

    vidtext = GLabel("video")
    vidtext.set_font("bold 50px 'serif'")
    vidtext.set_color("white")
    obj.add(vidtext, width / 2 - vidtext.get_width() / 2,
            height / 2 + vidtext.get_ascent())

    return obj
def createSierpinskiTriangle(size, order):
    if order == 0:  #base case
        return drawTriangle(size)
    else:
        gc = GCompound()
        s = (size / (2 * sqrt(3)))
        sx = s * cos(radians(30))
        sy = s * sin(radians(30))
        gc.add(createSierpinskiTriangle(size / 2, order - 1), 0, -s)
        gc.add(createSierpinskiTriangle(size / 2, order - 1), sx, sy)
        gc.add(createSierpinskiTriangle(size / 2, order - 1), -sx, sy)
        return gc
def createBall():  # Create ball
    global ball

    ball = GCompound()
    head = filledCircle(-diameter // 2, -diameter // 2, diameter, "yellow")
    ball.add(head)
    mouth = filledCircle(-diameter / 10, diameter / 8, diameter / 5, "black")
    ball.add(mouth)
    lefteye = filledCircle(-diameter / 4, -diameter / 4, diameter / 8, "blue")
    ball.add(lefteye)
    righteye = filledCircle(diameter / 8, -diameter / 4, diameter / 8, "blue")
    ball.add(righteye)
    '''
    return face 

    ball = GOval(GWINDOW_WIDTH//2 - (BALL_SIZE//2), 300, BALL_SIZE, BALL_SIZE)
    ball.setFilled(True)
    ball.setColor("black")
    '''
    gw.add(ball, GWINDOW_WIDTH / 2, GWINDOW_HEIGHT / 2)
def createBeehive(puzzle):
    global beehive
    cell = None
    puzzle = puzzle.upper()
    """
    Creates a GCompound that contains the objects necessary to display
    the beehive structure for the Spelling Bee.  The puzzle parameter
    is a seven-letter string that defines the labels on the hexagons.
    The first letter goes in the center hexagon; each subsequent letter
    goes in a hexagon whose center is HEX_SEP pixels from the center at
    angles of 30, 90, 150, 210, 270, and 330 degrees as the letters
    move counterclockwise around the hexagon.
    """
    beehive = GCompound()  # Create GCompund
    cell = createHexagon(HEX_SIDE)
    cell.setFilled(True)
    cell.setColor(CENTER_HEX_COLOR)
    beehive.add(cell)  # Add center cell
    letter = GLabel(puzzle[0])
    letter.setFont(LABEL_FONT)
    beehive.add(letter,
                cell.getX() - letter.getWidth() / 2,
                cell.getY() + HEX_LABEL_DY)  # Add center letter

    for i in range(6):  # Add other cells and letters
        cell = createHexagon(HEX_SIDE)
        cell.setFilled(True)
        cell.setColor(OUTER_HEX_COLOR)
        cell.movePolar(HEX_SEP, 30 + 60 * i)
        beehive.add(cell)
        letter = GLabel(puzzle[i + 1])
        letter.setFont(LABEL_FONT)
        beehive.add(letter,
                    cell.getX() - letter.getWidth() / 2,
                    cell.getY() + HEX_LABEL_DY)

    shuffle = createHexagon(HEX_SIDE)  # Create shuffle button
    shuffle.setFilled(True)
    shuffle.setColor(CENTER_HEX_COLOR)
    shuffle.movePolar(HEX_SEP * 1.75, -120)
    beehive.add(shuffle)
    letter = GLabel("SHUFFLE")
    letter.setFont("12px bold 'Helvetica Neue','Sans-Serif'")
    beehive.add(letter,
                shuffle.getX() - letter.getWidth() / 2,
                shuffle.getY() + letter.getAscent() / 2)

    return beehive  # Return completed beehive
def DrawHexagon(puzzle):
    angle = 30
    figure = GCompound()
    figureinside = GCompound()
    hexagon = createHexagon(HEX_SIDE)
    hexagon.setFilled(True)
    hexagon.setColor(CENTER_HEX_COLOR)
    figureinside.add(hexagon)
    labelinside = GLabel(puzzle[0])
    labelinside.setFont(LABEL_FONT)
    figureinside.add(labelinside, -0.38 * labelinside.getWidth(), HEX_LABEL_DY)
    figure.add(figureinside)

    for i in range(1, 7):

        figureinside = GCompound()
        hexagon = createHexagon(HEX_SIDE)
        hexagon.setFilled(True)
        hexagon.setColor(OUTER_HEX_COLOR)
        figureinside.add(hexagon)
        labelinside = GLabel(puzzle[i])
        labelinside.setFont(LABEL_FONT)
        figureinside.add(labelinside, -0.38 * labelinside.getWidth(),
                         HEX_LABEL_DY)
        figureinside.movePolar(HEX_SEP, angle)
        angle += 60
        figure.add(figureinside)
    gw.add(figure, GWINDOW_WIDTH / 2, GWINDOW_HEIGHT / 2)
def createBeehive(puzzle):

    #This function takes the parameter as string and outputs the beehive
    angle = 30
    figure = GCompound(
    )  #This will store the whole beehive and is the output of the function in the end
    figureinside = GCompound(
    )  #This will store the intermediate values to be put into figure
    hexagon = createHexagon(HEX_SIDE)
    hexagon.setFilled(True)
    hexagon.setColor(CENTER_HEX_COLOR)
    figureinside.add(hexagon)
    labelinside = GLabel(puzzle[0])

    labelinside.setFont(LABEL_FONT)
    figureinside.add(
        labelinside, -0.5 * labelinside.getWidth(), HEX_LABEL_DY
    )  #Using -0.5 times label width tends to center the label more
    figure.add(figureinside)

    for i in range(1, 7):

        figureinside = GCompound()
        hexagon = createHexagon(HEX_SIDE)
        hexagon.setFilled(True)
        hexagon.setColor(OUTER_HEX_COLOR)
        figureinside.add(hexagon)
        labelinside = GLabel(puzzle[i])
        labelinside.setFont(LABEL_FONT)
        labelinside.setLocation(-0.5 * labelinside.getWidth(), HEX_LABEL_DY)
        figureinside.add(labelinside)
        figureinside.movePolar(HEX_SEP, angle)
        angle += 60
        figure.add(figureinside)

    return figure