generated from mwc/project_drawing
Add demo with bouncing beach ball
This commit is contained in:
parent
4781d533ec
commit
514af40b47
|
@ -0,0 +1,33 @@
|
|||
from turtle import *
|
||||
from superturtle.movement import fly
|
||||
from superturtle.animation import animate
|
||||
from superturtle.easing import easeOutBounce
|
||||
|
||||
def nopen(distance):
|
||||
"Move with the pen up"
|
||||
penup()
|
||||
forward(distance)
|
||||
pendown()
|
||||
|
||||
def beachball(radius, n_seams=6):
|
||||
"""Draws a beach ball centered at the turtle's current position.
|
||||
When finished, leaves the turtle at the original position.
|
||||
"""
|
||||
left(90)
|
||||
nopen(radius)
|
||||
right(90)
|
||||
circle(radius)
|
||||
left(90)
|
||||
nopen(radius)
|
||||
right(90)
|
||||
|
||||
for seam in range(n_seams):
|
||||
circle(radius/2, 180)
|
||||
circle(radius/2, -180)
|
||||
right(360/n_seams)
|
||||
|
||||
for frame in animate(256, loop=True):
|
||||
x = frame.interpolate(-100, 100)
|
||||
y = frame.interpolate(200, -100, easing=easeOutBounce)
|
||||
fly(x, y)
|
||||
beachball(40)
|
Loading…
Reference in New Issue