My third commit will consist of my third round of changes. What has changed during my third commit were my functions. In this attempt I was given feedback to consider how can I add more parameters or loops to my existing code. I did both by adding customizable parameters to allow a house and sun of any color. I also added a for loop that gives me three houses of different color instead of one.

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.
This commit is contained in:
angelotr
2025-10-05 17:35:20 -04:00
parent eaf4735298
commit 6966760b2b
4 changed files with 85 additions and 54 deletions

View File

@@ -1,61 +1,84 @@
# drawing.py
# ----------
# By ____(you)___________
# By Angelo Trelles
#
# (Briefly describe what this program does.)
# 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=800, height=600)
screen.setup(width=1000, height=600)
screen.bgcolor("skyblue")
pen = turtle.Turtle()
pen.speed(0)
pen.hideturtle()
# draw house
def draw_house():
# house base
# 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(-100, -200)
pen.goto(x, -200)
pen.pendown()
draw_square(pen, 200, color="black", fill="lightgrey")
draw_square(pen, 200, color="black", fill=base_color)
# roof (lowered)
# roof
pen.penup()
pen.goto(-100, -200)
pen.goto(x, -200)
pen.pendown()
draw_triangle(pen, 200, color="black", fill="brown")
draw_triangle(pen, 200, color="black", fill=roof_color)
# door
pen.penup()
pen.goto(-30, -200)
pen.goto(x + 70, -200)
pen.pendown()
draw_rectangle(pen, 60, 100, color="black", fill="darkred")
draw_rectangle(pen, 60, 100, color="black", fill=door_color)
# windows (lowered)
# windows (left and right)
pen.penup()
pen.goto(-80, -210)
pen.goto(x + 20, -210)
pen.pendown()
draw_square(pen, 40, color="black", fill="lightblue")
draw_square(pen, 40, color="black", fill=window_color)
pen.penup()
pen.goto(40, -210)
pen.goto(x + 140, -210)
pen.pendown()
draw_square(pen, 40, color="black", fill="lightblue")
draw_square(pen, 40, color="black", fill=window_color)
# draw sun (stationary)
def draw_sun():
# draw stationary sun
def draw_sun(x=300, y=180, sun_color="yellow"):
pen.penup()
pen.goto(250, 180) # top-right corner
pen.goto(x, y)
pen.pendown()
draw_circle(pen, 50, color="black", fill="yellow")
draw_circle(pen, 50, color="black", fill=sun_color)
# main
draw_house()
draw_sun()
# --- main scene ---
def main():
# draw the sun (customizable color)
draw_sun(sun_color="yellow")
turtle.done()
# 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()