Untitled
unknown
plain_text
a year ago
3.6 kB
7
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")
# 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):
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)
elif selected_shape == "circle":
goto(-95,-175)
elif selected_shape == "triangle":
goto(-63, -175)
color("black")
pendown()
pensize(2)
for i in range(4):
forward(30)
right(90)
def user_click(x, y):
print(str(x) + ", " + str(y))
if x > -150 and x < 0 and y < -150 and y > -200:
# they are trying to change the shape
if x > -155 and x < -135 and y > -170 and y < -150:
print("changing to square")
canvas.chosen_shape = "square"
print(canvas.chosen_shape)
elif x < -95 and x > -65 and y < -175 and y > -145:
canvas.chosen_shape = "circle"
elif x < -63 and x > -33 and y < -175 and y > -145:
print("changing to triangle")
canvas.chosen_shape = "triangle"
if x > -125 and x < 150 and y > -70 and y < 150:
print(canvas.chosen_shape)
# they are trying to draw in the square
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)
# canvas variables
canvas = getscreen()
canvas.chosen_color = "green"
canvas.chosen_shape = "triangle"
canvas.onclick(user_click)
speed(0)
draw_background()
draw_shapes()
select_shape(canvas.chosen_shape)Editor is loading...
Leave a Comment