generated from mwc/project_drawing
	What got me stuck in the beginning was how can I add more parameters or loops to my existing code. What I figured out was that by adding more parameters and loops to my existing code I would be able to create a drawing that would give me three house and a sun with customizable color of my choosing. A strategy I used to get unstuck was to continue using ideas from previous lessons about parameters and trial and error to see where things went right and wrong. What I wonder is how can I use super turtle to create an animated sun. What I want to learn more about is how to properly use super turtle. Since I have more houses and sun with customizable color my future project idea could be to create three houses and a sun with customizable coloring but this time using super turtle to creaete an animated rising sun.
		
			
				
	
	
		
			84 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# 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() |