From f10aebbbe4928f5964e837c22eec17c522bc0333 Mon Sep 17 00:00:00 2001 From: jwberent Date: Sun, 5 Oct 2025 14:21:52 -0400 Subject: [PATCH] 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. --- drawing.py | 136 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 84 insertions(+), 52 deletions(-) diff --git a/drawing.py b/drawing.py index a76c53a..5bd9dd2 100644 --- a/drawing.py +++ b/drawing.py @@ -11,7 +11,6 @@ def fly(forw): forward(forw) pendown() - def rectangle(height,width,col): dimensions = [width, height, width, height] fillcolor(col) @@ -21,7 +20,6 @@ def rectangle(height,width,col): left(90) end_fill() - def triangle_facing_right(height,col): top_of_tri = (height**2+height**2)**(1/2) fillcolor(col) @@ -50,70 +48,118 @@ def triangle_facing_left(height,col): left(135) end_fill() - def circ(radius): 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) -rectangle(250,150,"red") #this is the torso +draw_shirt(250,150,"red") right(90) fly(150) left(90) -rectangle(150,50,"blue") #this is the left leg -fly(100) -rectangle(150,50,"blue") #this is the right leg +draw_pants(150,50,"blue") fly(50) left(90) fly(350) right(180) -rectangle(150,50,"red") #this is right arm -right(90) -fly(300) -left(90) -rectangle(150,50,"red") #this is left arm +draw_arms(150,50,"red") right(180) fly(50) right(90) fly(230) left(90) -rectangle(10,30,"white") #this is the neck +draw_neck(10,30,"white") left(90) fly(5) right(90) fly(30) right(90) -circ(35) #this is the head -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 +draw_head_and_eyes(35,5) right(90) fly(25) right(90) fly(12) right(180) -triangle_facing_right(15,"black") #this is the mouth -left(180) -fly(15) -right(180) -triangle_facing_left(15,"black") #this is the mouth +draw_mouth(15,"black") fly(45) left(90) fly(60) left(90) -for num in [55,60,65,85]: #this is the hat - rectangle(10,num,"brown") - left(90) - fly(5) - right(90) +draw_hat(55,"brown") fly(400) right(180) -dot(200,"royalblue") #this is the moon +draw_moon(200,"royalblue") fly(200) right(90) fly(475) @@ -123,25 +169,11 @@ left(90) rectangle(800,300,"green") #this is the grass left(90) fly(100) -rectangle(150,100,"dodgerblue") #this is the house -fly(40) -rectangle(40,20,"white") #this is the door -left(180) -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 +draw_house(150,100,"dodgerblue",75,10) +for s in range (100): # this makes individual blades of grass + rectangle(5,3,"green") + fly(7) + input()