generated from mwc/project_drawing
92 lines
2.8 KiB
Python
92 lines
2.8 KiB
Python
# drawing.py
|
|
# ----------
|
|
# Nelson Mason
|
|
# updated 9-23-2025
|
|
# Due by 9-29-2025
|
|
# (This is an animation of a sunrise.)
|
|
|
|
from turtle import *
|
|
from superturtle.animation import animate
|
|
|
|
# define 3 objects
|
|
# sky, ground, sun
|
|
# 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),
|
|
# with the sun, sky, and ground changing color. The disk of the sun will
|
|
# be apparent only in the sky, as it rises. I will be using color shading techniques in the animation.
|
|
|
|
# I played around with the RGB settings. I left out drawing the sun
|
|
# casting a shadow on the ground while rising.
|
|
# Perhaps for another project?
|
|
|
|
# YOU CAN'T BEAT MOTHER NATURE FOR A SUNRISE!
|
|
|
|
def rectangle(b, c, d, e, f): # draws the sky first, then after the sun is drawn, the ground
|
|
for x in range(2): # as the sun rises sky color changes from black to blue, ground changes
|
|
# from black to dark green
|
|
begin_fill()
|
|
fillcolor(d, e, f)
|
|
forward(b)
|
|
left(90)
|
|
forward(c)
|
|
left(90)
|
|
end_fill()
|
|
|
|
def sun():
|
|
begin_fill() # draw the sun
|
|
fillcolor(1, a/550, 0) # as the sun rises sun color changes from red to orange
|
|
circle(-75,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=550, loop=True): # close Turtle Graphic to end the loop
|
|
a = frame.interval=1100 # the frames-to-interval ratio controls the animation speed
|
|
a = frame.interpolate(0, 275) # low and high positions of the sun as it rises
|
|
|
|
b=400 # rectangle width
|
|
c=300 # rectangle sky height
|
|
d=0.05 # for RGB
|
|
e=0.05 # for RGB
|
|
f=a/275 # for RGB
|
|
g=0.05 # for RGB
|
|
h=a/1100 # for RGB
|
|
i=0.05 # for RGB
|
|
j=c/2 # rectangle ground height
|
|
|
|
penup() # reposition the turtle before drawing the sky
|
|
right(180)
|
|
forward(200)
|
|
left(90)
|
|
forward(50)
|
|
left(90)
|
|
pendown()
|
|
rectangle(b,c,d,e,f) # draws the 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()
|
|
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
|
|
forward(150)
|
|
left(90)
|
|
pendown()
|
|
# I want the ground to hide the sun (overlay), but not the sky (obviously)
|
|
rectangle(b,j,g,h,i) # draws the ground (call function with parameters by position)
|
|
penup()
|
|
left(90)
|
|
forward(j)
|
|
right(90)
|
|
|
|
input() |