Untitled

 avatar
unknown
plain_text
a year ago
5.3 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)
    for i in range(2):
        forward(300)
        left(90)
        forward(250)
        left(90)
    seth(180)
    pensize(1)
    penup()
    goto(-110,-130)
    write("Choose Shape", font=("Arial", 12,"bold"), align="center")
    goto(110,-130)
    write("Choose Color", 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(-50,-185)
    color("white") 
    begin_fill()
    for i in range(2):
        forward(120)
        right(90)
        forward(52)
        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 select_color(selected_color):
    penup()
    goto(170,-190)
    seth(180)
    color("white") 
    begin_fill()
    for i in range(2):
        forward(200)
        right(90)
        forward(52)
        right(90)
    end_fill()
    draw_palette()
    
    if selected_color == "red":
        goto(55,-145)
        
    elif selected_color == "orange":
        goto(85,-145)
    
    elif selected_color == "yellow":
        goto(115,-145)
    
    elif selected_color == "green":
        goto(145,-145)
    
    elif selected_color == "blue":
        goto(175,-145)
    
    
        
    color("black")
    pendown()
    pensize(2)
    
    for i in range(4):
        forward(30)
        left(90)  
    

def draw_colors(x,y, color_choice):
    penup()
    goto(x,y)
    color(color_choice)
    begin_fill()
    for i in range(4):
        forward(20)
        right(90)
    end_fill()
    
def draw_palette():
    seth(180)
    draw_colors(50,-170, "red")
    draw_colors(80,-170, "orange")
    draw_colors(110,-170, "yellow")
    draw_colors(140,-170, "green")
    draw_colors(170,-170, "blue")

def user_click(x, 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: 
            canvas.chosen_shape = "square"
            
        elif x > -130 and x < -100 and y > -170 and y < -150: 
            canvas.chosen_shape = "circle"
            
        elif x > -90 and x < -70 and y > -170 and y < -150:
            canvas.chosen_shape = "triangle"
        select_shape(canvas.chosen_shape)
        
    if x > 0 and x < 190 and y < -150 and y > -200:
        # they are trying to change the color
        if x > 30 and x < 50 and y > -170 and y < -150: 
            canvas.chosen_color = "red"
        if x > 60 and x < 80 and y > -170 and y < -150: 
            canvas.chosen_color = "orange"
        if x > 90 and x < 105 and y > -170 and y < -150: 
            canvas.chosen_color = "yellow"
        if x > 120 and x < 140 and y > -170 and y < -150: 
            canvas.chosen_color = "green"
        if x > 150 and x < 170 and y > -170 and y < -150: 
            canvas.chosen_color = "blue"
        select_color(canvas.chosen_color)
    
    if x > -125 and x < 150 and y > -70 and y < 150:
        # 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 = ""
canvas.chosen_shape = ""
canvas.onclick(user_click)

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