generated from mwc/project_drawing
	drawing.py
This commit is contained in:
		
							
								
								
									
										96
									
								
								drawing.py
									
									
									
									
									
								
							
							
						
						
									
										96
									
								
								drawing.py
									
									
									
									
									
								
							@@ -1,7 +1,7 @@
 | 
				
			|||||||
# drawing.py
 | 
					# drawing.py
 | 
				
			||||||
# ----------
 | 
					# ----------
 | 
				
			||||||
# Nelson Mason
 | 
					# Nelson Mason
 | 
				
			||||||
# updated 9-19-2025
 | 
					# updated 9-21-2025
 | 
				
			||||||
# Due by 9-29-2025
 | 
					# Due by 9-29-2025
 | 
				
			||||||
# (This is an animation of a sunrise.)
 | 
					# (This is an animation of a sunrise.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -14,64 +14,66 @@ from superturtle.animation import animate
 | 
				
			|||||||
# In the actual animation, the sun will start off entirely below the horizon,
 | 
					# In the actual animation, the sun will start off entirely below the horizon,
 | 
				
			||||||
# (where the sky meets the ground), hidden by the ground, and will slowly rise (move up the screen),
 | 
					# (where the sky meets the ground), hidden by the ground, and will slowly rise (move up the screen),
 | 
				
			||||||
# with the sun, sky, and ground changing color. The disk of the sun will
 | 
					# with the sun, sky, and ground changing color. The disk of the sun will
 | 
				
			||||||
# be apparent only in the sky, as it rises. The elapsed_time will be linked to the
 | 
					# be apparent only in the sky, as it rises. I will be using color shading techniques in the animation.
 | 
				
			||||||
# animation frames. I will be using color shading techniques in the animation.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def sky():    
 | 
					def sky():
 | 
				
			||||||
 | 
					    begin_fill() # draw the sky
 | 
				
			||||||
 | 
					    fillcolor("dark blue")   
 | 
				
			||||||
    for x in range(2):
 | 
					    for x in range(2):
 | 
				
			||||||
        forward(400)
 | 
					        forward(400)
 | 
				
			||||||
        left(90)        
 | 
					        left(90)        
 | 
				
			||||||
        forward(300)
 | 
					        forward(300)
 | 
				
			||||||
        left(90)
 | 
					        left(90)
 | 
				
			||||||
 | 
					    end_fill()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def ground():
 | 
					def ground():
 | 
				
			||||||
 | 
					    begin_fill() # draw the ground
 | 
				
			||||||
 | 
					    fillcolor("black")
 | 
				
			||||||
    for x in range(2):
 | 
					    for x in range(2):
 | 
				
			||||||
        forward(400)
 | 
					        forward(400)
 | 
				
			||||||
        right(90)        
 | 
					        right(90)        
 | 
				
			||||||
        forward(150)
 | 
					        forward(150)
 | 
				
			||||||
        right(90)
 | 
					        right(90)
 | 
				
			||||||
 | 
					 | 
				
			||||||
def sun():
 | 
					 | 
				
			||||||
    circle(75,360)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def sun_reposition():
 | 
					 | 
				
			||||||
    left(90)
 | 
					 | 
				
			||||||
    forward(20)
 | 
					 | 
				
			||||||
    right(90)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
penup() # reposition the turtle before drawing the 3 objects
 | 
					 | 
				
			||||||
right(180)
 | 
					 | 
				
			||||||
forward(200)
 | 
					 | 
				
			||||||
left(90)
 | 
					 | 
				
			||||||
forward(50)
 | 
					 | 
				
			||||||
left(90)
 | 
					 | 
				
			||||||
pendown()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
begin_fill() # draw the sky
 | 
					 | 
				
			||||||
fillcolor("dark blue")
 | 
					 | 
				
			||||||
sky()
 | 
					 | 
				
			||||||
end_fill()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
begin_fill() # draw the ground
 | 
					 | 
				
			||||||
fillcolor("black")
 | 
					 | 
				
			||||||
ground()
 | 
					 | 
				
			||||||
end_fill()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
penup()
 | 
					 | 
				
			||||||
right(90)
 | 
					 | 
				
			||||||
forward(150)
 | 
					 | 
				
			||||||
left(90)
 | 
					 | 
				
			||||||
forward(200)
 | 
					 | 
				
			||||||
pendown()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# for frame in animate(40, loop=True):
 | 
					 | 
				
			||||||
#   x = frame.interpolate(0,15)
 | 
					 | 
				
			||||||
for x in range(15):
 | 
					 | 
				
			||||||
    begin_fill() # draw the sun
 | 
					 | 
				
			||||||
    fillcolor("red")
 | 
					 | 
				
			||||||
    sun()
 | 
					 | 
				
			||||||
    sun_reposition()
 | 
					 | 
				
			||||||
    end_fill()
 | 
					    end_fill()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
input()
 | 
					def sun():
 | 
				
			||||||
 | 
					    begin_fill() # draw the sun
 | 
				
			||||||
 | 
					    fillcolor("red")
 | 
				
			||||||
 | 
					    circle(-62,360) 
 | 
				
			||||||
 | 
					    end_fill()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def sun_position(a): # this must be called to get the sun to move up (rise)
 | 
				
			||||||
 | 
					    penup()
 | 
				
			||||||
 | 
					    left(90)
 | 
				
			||||||
 | 
					    forward(a)
 | 
				
			||||||
 | 
					    right(90)
 | 
				
			||||||
 | 
					    pendown()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for frame in animate(frames=1000):
 | 
				
			||||||
 | 
					    penup() # reposition the turtle before drawing the sky
 | 
				
			||||||
 | 
					    right(180)
 | 
				
			||||||
 | 
					    forward(200)
 | 
				
			||||||
 | 
					    left(90)
 | 
				
			||||||
 | 
					    forward(50)
 | 
				
			||||||
 | 
					    left(90)
 | 
				
			||||||
 | 
					    pendown()
 | 
				
			||||||
 | 
					    sky()
 | 
				
			||||||
 | 
					    penup() # reposition the turtle before drawing the sun
 | 
				
			||||||
 | 
					    forward(200) # starting the drawing of the sun right on the horizon
 | 
				
			||||||
 | 
					    # makes it easier to calculate everything else
 | 
				
			||||||
 | 
					    pendown()
 | 
				
			||||||
 | 
					    a = frame.interval=200 # the frames-to-interval ratio controls the animation speed
 | 
				
			||||||
 | 
					    a = frame.interpolate(0, 275) # low and high positions of the sun as it rises
 | 
				
			||||||
 | 
					    sun_position(a)
 | 
				
			||||||
 | 
					    sun() # draws the sun   
 | 
				
			||||||
 | 
					    penup() # reposition the turtle before drawing the ground
 | 
				
			||||||
 | 
					    right(180)
 | 
				
			||||||
 | 
					    forward(200)
 | 
				
			||||||
 | 
					    left(90)
 | 
				
			||||||
 | 
					    forward(+a) # increment to get to the correct starting point for 
 | 
				
			||||||
 | 
					    # the next iteration(re-drawing) of the sun rising
 | 
				
			||||||
 | 
					    left(90)
 | 
				
			||||||
 | 
					    pendown()
 | 
				
			||||||
 | 
					    ground() # I want the ground to hide the sun (overlay), but not the sky (obviously)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					input()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user