Untitled
unknown
plain_text
a year ago
3.4 kB
5
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(x,y): penup() goto(-65,-185) color("white") begin_fill() for i in range(2): forward(100) right(90) forward(50) right(90) end_fill() draw_shapes() goto(x,y) color("black") pendown() pensize(2) for i in range(4): forward(30) right(90) #goto(-130,-175) square #goto(-95,-175) circle #goto(-63, -175) triangle def user_click(x, y): print(str(x) + ", " + str(y)) if x > -150 and x < 0 and y < -150 and y > -200: if x > -155 and x < -135 and y > -170 and y < -150: canvas.chosen_shape = "square" select_shape(-130,-175) elif x > -130 and x < -100 and y > -170 and y < -150: canvas.chosen_shape = "circle" select_shape(-95, -175) elif x > -90 and x < -70 and y > -170 and y < -150: canvas.chosen_shape = "triangle" select_shape(-63,-175) if x > -125 and x < 150 and y > -70 and y < 150: 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 = "" canvas.onclick(user_click) speed(0) draw_background() draw_shapes()
Editor is loading...
Leave a Comment