I added the individual blades of grass by using a loop. I also made more functions to help the readability of my code.

I already reached my 3 checkpoints but wanted to make my code better.  I was stuck on how to add more functions instead of just hard coding everything.  I figured out how to do this by breaking the code up into smaller parts based on what each portion of the code does.
This commit is contained in:
jwberent
2025-10-05 14:21:52 -04:00
parent cc91047769
commit f10aebbbe4

View File

@@ -11,7 +11,6 @@ def fly(forw):
forward(forw) forward(forw)
pendown() pendown()
def rectangle(height,width,col): def rectangle(height,width,col):
dimensions = [width, height, width, height] dimensions = [width, height, width, height]
fillcolor(col) fillcolor(col)
@@ -21,7 +20,6 @@ def rectangle(height,width,col):
left(90) left(90)
end_fill() end_fill()
def triangle_facing_right(height,col): def triangle_facing_right(height,col):
top_of_tri = (height**2+height**2)**(1/2) top_of_tri = (height**2+height**2)**(1/2)
fillcolor(col) fillcolor(col)
@@ -50,70 +48,118 @@ def triangle_facing_left(height,col):
left(135) left(135)
end_fill() end_fill()
def circ(radius): def circ(radius):
circle(radius,360) #found in section 1 link of Typeface Problem set instructions circle(radius,360) #found in section 1 link of Typeface Problem set instructions
def draw_shirt(height,width,shirt_color):
rectangle(height,width,shirt_color)
def draw_pants(height,width,pants_color):
rectangle(height,width,pants_color)
fly(height-width)
rectangle(height,width,pants_color)
def draw_arms(height,width,arms_color):
rectangle(height,width,arms_color)
right(90)
fly(2*height)
left(90)
rectangle(height,width,arms_color)
def draw_neck(height,width,neck_color):
rectangle(height,width,neck_color)
def draw_head_and_eyes(head_size,eye_size):
circ(head_size)
left(90)
fly(head_size+5)
left(90)
fly(head_size/3)
right(180)
circ(eye_size)
fly(5*eye_size)
circ(eye_size)
def draw_mouth(size,color):
triangle_facing_right(size,color)
left(180)
fly(size)
right(180)
triangle_facing_left(size,color)
def draw_hat(size,color):
for num in [size,size+5,size+10,size+30]:
rectangle(10,num,color)
left(90)
fly(5)
right(90)
def draw_moon(size,color):
dot(size,color)
def draw_house(length,width,color,roof_size,window_size):
rectangle(length,width,"dodgerblue")
fly((width/2)-10)
rectangle((width/2)-10,20,"white")
left(180)
fly(10)
right(90)
fly(width)
right(90)
for r in [window_size,window_size]:
circ(r)
fly(window_size*4)
left(180)
fly(width+35)
right(90)
fly(width/2)
right(90)
triangle_facing_left(roof_size,"gray")
fly(roof_size)
triangle_facing_right(roof_size,"gray")
right(90)
fly(length)
left(90)
fly(60)
speed(100) speed(100)
rectangle(250,150,"red") #this is the torso draw_shirt(250,150,"red")
right(90) right(90)
fly(150) fly(150)
left(90) left(90)
rectangle(150,50,"blue") #this is the left leg draw_pants(150,50,"blue")
fly(100)
rectangle(150,50,"blue") #this is the right leg
fly(50) fly(50)
left(90) left(90)
fly(350) fly(350)
right(180) right(180)
rectangle(150,50,"red") #this is right arm draw_arms(150,50,"red")
right(90)
fly(300)
left(90)
rectangle(150,50,"red") #this is left arm
right(180) right(180)
fly(50) fly(50)
right(90) right(90)
fly(230) fly(230)
left(90) left(90)
rectangle(10,30,"white") #this is the neck draw_neck(10,30,"white")
left(90) left(90)
fly(5) fly(5)
right(90) right(90)
fly(30) fly(30)
right(90) right(90)
circ(35) #this is the head draw_head_and_eyes(35,5)
left(90)
fly(40)
left(90)
fly(12)
right(180)
circ(5) #this is the left eye
fly(25)
circ(5) #this is the right eye
right(90) right(90)
fly(25) fly(25)
right(90) right(90)
fly(12) fly(12)
right(180) right(180)
triangle_facing_right(15,"black") #this is the mouth draw_mouth(15,"black")
left(180)
fly(15)
right(180)
triangle_facing_left(15,"black") #this is the mouth
fly(45) fly(45)
left(90) left(90)
fly(60) fly(60)
left(90) left(90)
for num in [55,60,65,85]: #this is the hat draw_hat(55,"brown")
rectangle(10,num,"brown")
left(90)
fly(5)
right(90)
fly(400) fly(400)
right(180) right(180)
dot(200,"royalblue") #this is the moon draw_moon(200,"royalblue")
fly(200) fly(200)
right(90) right(90)
fly(475) fly(475)
@@ -123,25 +169,11 @@ left(90)
rectangle(800,300,"green") #this is the grass rectangle(800,300,"green") #this is the grass
left(90) left(90)
fly(100) fly(100)
rectangle(150,100,"dodgerblue") #this is the house draw_house(150,100,"dodgerblue",75,10)
fly(40) for s in range (100): # this makes individual blades of grass
rectangle(40,20,"white") #this is the door rectangle(5,3,"green")
left(180) fly(7)
fly(10)
right(90)
fly(100)
right(90)
for r in [10,10]: #this is the windows to the house
circ(r)
fly(40)
left(180)
fly(135)
right(90)
fly(50)
right(90)
triangle_facing_left(75,"gray") #this is the roof
fly(75)
triangle_facing_right(75,"gray") #this is the roof
input() input()