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
예제 #2
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 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
예제 #4
0
def createSierpinskiTriangle(size, order):
    whole = GCompound()

    def createTriangle(size, order, dx, dy):
        if order == 0:
            drawTriangle(size, dx, dy, whole)

        else:
            createTriangle(size / 2, order - 1, dx,
                           300)  #dy - 4/(math.sqrt(3) * size)
            createTriangle(
                size / 2, order - 1, dx - size / 4,
                dy + 4 * math.sqrt(3) / size - 2 * (4 / (math.sqrt(3) * size)))
            createTriangle(
                size / 2, order - 1, dx + size / 4,
                dy + 4 * math.sqrt(3) / size - 2 * (4 / (math.sqrt(3) * size)))

    createTriangle(size, order, 0, 0)
    gw.add(whole, GWINDOW_WIDTH / 2, GWINDOW_HEIGHT / 2)
예제 #5
0
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)