# drawing.py # ---------- # By Angelo Trelles # # This program allows me to create a drawing of a house and a sun. The code is split # into two files for organization. Shapes.py contains functions to draw basic shapes # such as squares, rectangles, trianlges, and circles. Each function includes # options for size, outline color, and fill color so they can be reused in # different ways. The second file, drawing.py, uses the functions to draw a complete # scene that includes a house with a roof, windows, and a door, along with a sun # in the corner. The project shows how to use functions, loops, and parameters to # make drawings customizable. import turtle from shapes import draw_square, draw_triangle, draw_rectangle, draw_circle # setup screen = turtle.Screen() screen.setup(width=1000, height=600) screen.bgcolor("skyblue") pen = turtle.Turtle() pen.speed(0) pen.hideturtle() # first house with color options def draw_house(x, base_color="lightgrey", roof_color="brown", door_color="darkred", window_color="lightblue"): # base position pen.penup() pen.goto(x, -200) pen.pendown() draw_square(pen, 200, color="black", fill=base_color) # roof pen.penup() pen.goto(x, -200) pen.pendown() draw_triangle(pen, 200, color="black", fill=roof_color) # door pen.penup() pen.goto(x + 70, -200) pen.pendown() draw_rectangle(pen, 60, 100, color="black", fill=door_color) # windows (left and right) pen.penup() pen.goto(x + 20, -210) pen.pendown() draw_square(pen, 40, color="black", fill=window_color) pen.penup() pen.goto(x + 140, -210) pen.pendown() draw_square(pen, 40, color="black", fill=window_color) # draw stationary sun def draw_sun(x=300, y=180, sun_color="yellow"): pen.penup() pen.goto(x, y) pen.pendown() draw_circle(pen, 50, color="black", fill=sun_color) # --- main scene --- def main(): # draw the sun (customizable color) draw_sun(sun_color="yellow") # a loop to draw multiple houses with different colors (customizable color options) colors = [ ("lightgrey", "brown", "darkred", "lightblue"), ("lightyellow", "red", "blue", "white"), ("lightgreen", "purple", "darkblue", "yellow") ] x_position = -400 for base, roof, door, window in colors: draw_house(x_position, base, roof, door, window) x_position += 300 turtle.done() # to run program main()