generated from mwc/project_drawing
drawing.py
This commit is contained in:
109
drawing.py
109
drawing.py
@@ -1,7 +1,7 @@
|
|||||||
# drawing.py
|
# drawing.py
|
||||||
# ----------
|
# ----------
|
||||||
# Nelson Mason
|
# Nelson Mason
|
||||||
# updated 9-22-2025
|
# updated 9-23-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.)
|
||||||
|
|
||||||
@@ -21,32 +21,22 @@ from superturtle.animation import animate
|
|||||||
|
|
||||||
# YOU CAN'T BEAT MOTHER NATURE FOR A SUNRISE!
|
# YOU CAN'T BEAT MOTHER NATURE FOR A SUNRISE!
|
||||||
|
|
||||||
def sky():
|
def rectangle(b, c, d, e, f): # draws the sky first, then after the sun is drawn, the ground
|
||||||
begin_fill() # draw the sky
|
for x in range(2): # as the sun rises sky color changes from black to blue, ground changes
|
||||||
fillcolor(0.05, 0.05, a/275) # as the sun rises sky color changes from black to blue
|
# from black to dark green
|
||||||
for x in range(2):
|
begin_fill()
|
||||||
forward(400)
|
fillcolor(d, e, f)
|
||||||
left(90)
|
forward(b)
|
||||||
forward(300)
|
left(90)
|
||||||
left(90)
|
forward(c)
|
||||||
end_fill()
|
left(90)
|
||||||
|
end_fill()
|
||||||
def ground():
|
|
||||||
begin_fill() # draw the ground
|
|
||||||
fillcolor(0.05, a/1100, 0.05) # as the sun rises ground color changes from black to dark green
|
|
||||||
for x in range(2):
|
|
||||||
forward(400)
|
|
||||||
right(90)
|
|
||||||
forward(150)
|
|
||||||
right(90)
|
|
||||||
end_fill()
|
|
||||||
|
|
||||||
|
|
||||||
def sun():
|
def sun():
|
||||||
begin_fill() # draw the sun
|
begin_fill() # draw the sun
|
||||||
fillcolor(1, a/550, 0) # as the sun rises sun color changes from red to orange
|
fillcolor(1, a/550, 0) # as the sun rises sun color changes from red to orange
|
||||||
circle(-75,360)
|
circle(-75,360)
|
||||||
end_fill()
|
end_fill()
|
||||||
|
|
||||||
def sun_position(a): # this must be called to get the sun to move up (rise)
|
def sun_position(a): # this must be called to get the sun to move up (rise)
|
||||||
penup()
|
penup()
|
||||||
@@ -55,31 +45,48 @@ def sun_position(a): # this must be called to get the sun to move up (rise)
|
|||||||
right(90)
|
right(90)
|
||||||
pendown()
|
pendown()
|
||||||
|
|
||||||
for frame in animate(frames=550, loop=True):
|
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.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
|
a = frame.interpolate(0, 275) # low and high positions of the sun as it rises
|
||||||
penup() # reposition the turtle before drawing the sky
|
|
||||||
right(180)
|
b=400 # rectangle width
|
||||||
forward(200)
|
c=300 # rectangle sky height
|
||||||
left(90)
|
d=0.05 # for RGB
|
||||||
forward(50)
|
e=0.05 # for RGB
|
||||||
left(90)
|
f=a/275 # for RGB
|
||||||
pendown()
|
g=0.05 # for RGB
|
||||||
sky()
|
h=a/1100 # for RGB
|
||||||
penup() # reposition the turtle before drawing the sun
|
i=0.05 # for RGB
|
||||||
forward(200) # starting the drawing of the sun right on the horizon
|
j=c/2 # rectangle ground height
|
||||||
# makes it easier to calculate everything else
|
|
||||||
pendown()
|
penup() # reposition the turtle before drawing the sky
|
||||||
sun_position(a)
|
right(180)
|
||||||
sun() # draws the sun
|
forward(200)
|
||||||
penup() # reposition the turtle before drawing the ground
|
left(90)
|
||||||
right(180)
|
forward(50)
|
||||||
forward(200)
|
left(90)
|
||||||
left(90)
|
pendown()
|
||||||
forward(+a) # increment to get to the correct starting point for
|
rectangle(b,c,d,e,f) # draws the sky
|
||||||
# the next iteration(re-drawing) of the sun rising
|
penup() # reposition the turtle before drawing the sun
|
||||||
left(90)
|
forward(200) # starting the drawing of the sun right on the horizon
|
||||||
pendown()
|
# makes it easier to calculate everything else
|
||||||
ground() # I want the ground to hide the sun (overlay), but not the sky (obviously)
|
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()
|
input()
|
||||||
Reference in New Issue
Block a user