generated from mwc/project_drawing
	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.
		
			
				
	
	
		
			183 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			183 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# drawing.py
 | 
						|
# ----------
 | 
						|
# By James Berent
 | 
						|
#
 | 
						|
# (This will make a person and the person will stand next to a house)
 | 
						|
 | 
						|
from turtle import *
 | 
						|
 | 
						|
def fly(forw):
 | 
						|
    penup()
 | 
						|
    forward(forw)
 | 
						|
    pendown()
 | 
						|
 | 
						|
def rectangle(height,width,col):
 | 
						|
    dimensions = [width, height, width, height]
 | 
						|
    fillcolor(col)
 | 
						|
    begin_fill()
 | 
						|
    for dim in dimensions:
 | 
						|
        forward(dim)
 | 
						|
        left(90)
 | 
						|
    end_fill()
 | 
						|
 | 
						|
def triangle_facing_right(height,col):
 | 
						|
    top_of_tri = (height**2+height**2)**(1/2)
 | 
						|
    fillcolor(col)
 | 
						|
    begin_fill()
 | 
						|
    forward(height)
 | 
						|
    left(180)
 | 
						|
    fly(height)
 | 
						|
    right(90)
 | 
						|
    forward(height)
 | 
						|
    right(135)
 | 
						|
    forward(top_of_tri)
 | 
						|
    right(135)
 | 
						|
    fly(height)
 | 
						|
    left(180)
 | 
						|
    end_fill()
 | 
						|
 | 
						|
def triangle_facing_left(height,col):
 | 
						|
    top_of_tri = (height**2+height**2)**(1/2)
 | 
						|
    fillcolor(col)
 | 
						|
    begin_fill()
 | 
						|
    forward(height)
 | 
						|
    left(90)
 | 
						|
    forward(height)
 | 
						|
    left(135)
 | 
						|
    forward(top_of_tri)
 | 
						|
    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)
 | 
						|
draw_shirt(250,150,"red")
 | 
						|
right(90)
 | 
						|
fly(150)
 | 
						|
left(90)
 | 
						|
draw_pants(150,50,"blue")
 | 
						|
fly(50)
 | 
						|
left(90)
 | 
						|
fly(350)
 | 
						|
right(180)
 | 
						|
draw_arms(150,50,"red")
 | 
						|
right(180)
 | 
						|
fly(50)
 | 
						|
right(90)
 | 
						|
fly(230)
 | 
						|
left(90)
 | 
						|
draw_neck(10,30,"white") 
 | 
						|
left(90)
 | 
						|
fly(5)
 | 
						|
right(90)
 | 
						|
fly(30)
 | 
						|
right(90)
 | 
						|
draw_head_and_eyes(35,5)
 | 
						|
right(90)
 | 
						|
fly(25)
 | 
						|
right(90)
 | 
						|
fly(12)
 | 
						|
right(180)
 | 
						|
draw_mouth(15,"black")
 | 
						|
fly(45)
 | 
						|
left(90)
 | 
						|
fly(60)
 | 
						|
left(90)
 | 
						|
draw_hat(55,"brown")
 | 
						|
fly(400)
 | 
						|
right(180)
 | 
						|
draw_moon(200,"royalblue")
 | 
						|
fly(200)
 | 
						|
right(90)
 | 
						|
fly(475)
 | 
						|
right(90)
 | 
						|
fly(300)
 | 
						|
left(90)
 | 
						|
rectangle(800,300,"green") #this is the grass
 | 
						|
left(90)
 | 
						|
fly(100)
 | 
						|
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()
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
    
 |