Untitled

 avatar
unknown
plain_text
a year ago
2.9 kB
4
Indexable
# create a function that makes the background
def draw_background():
    bgcolor("white")
    penup()
    pensize(6)
    goto(-150,150)
    pendown()
    forward(300)
    left(180)
    forward(300)
    left(90)
    forward(250)
    left(90)
    forward(300)
    left(90)
    forward(250)
    seth(180)
    pensize(1)
    penup()
    goto(-110,-130)
    write("Choose Shape", font=("Arial", 12,"bold"), align="center")
    select_shape(canvas.chosen_shape)
    
# create a function that draws the square
def draw_square(square_color, x,y):
    penup()
    goto(x,y)
    color(square_color)
    pendown()
    begin_fill()
    for i in range(4):
        forward(30)
        left(90)
    end_fill()
    penup()

# create a function that draws the circle 
def draw_circle(circle_color, x,y):
    penup()
    goto(x,y)
    color(circle_color)
    pendown()
    begin_fill()
    circle(15)
    end_fill()

# create a function that draws the triangle
def draw_triangle(triangle_color, x,y):
    penup()
    goto(x,y)
    color(triangle_color)
    pendown()
    begin_fill()
    circle(15,360,3)
    end_fill()
    penup()

# create a function that creates the circle button
def circle_button():
    penup()
    goto(-110,-150)
    color("black")
    begin_fill()
    circle(10)
    end_fill()

# create a function that creates the square button
def square_button():
    penup()
    goto(-135,-170)
    color("black")
    begin_fill()
    for i in range(4):
        forward(20)
        right(90)
    end_fill()

# create a function that creates the triangle button
def triangle_button():
    penup()
    goto(-78,-152)
    color("black")
    begin_fill()
    circle(12,360,3)
    end_fill()

# create a function that puts all the buttons together
def draw_shapes():
    square_button()
    circle_button()
    triangle_button()

def select_shape(selected_shape):
    print("here")
    penup()
    goto(-180,-190)
    color("white") 
    begin_fill()
    for i in range(2):
        forward(100)
        right(90)
        forward(50)
        right(90)
    end_fill()
    draw_shapes()
    
    if selected_shape == "square":
        goto(-130,-175)
    
    color("black")
    pendown()
    
    for i in range(4):
        forward(30)
        right(90)    

def user_click(x, y):
    
    # if the user has clicked in the drawing area, run this code
    if canvas.chosen_shape == "square":  
        
        draw_square(canvas.chosen_color, x, y)
    
    elif canvas.chosen_shape == "circle":
        draw_circle(canvas.chosen_color, x, y)
    
    elif canvas.chosen_shape == "triangle":
        draw_triangle(canvas.chosen_color, x, y)
    # else, if the user has clicked below a certain y value,
     
     
# canvas variables
canvas = getscreen()
canvas.chosen_color = "green"
canvas.chosen_shape = "square"
canvas.onclick(user_click)

speed(0)    
draw_background()
draw_shapes()
Editor is loading...
Leave a Comment