Add demo with bouncing beach ball

This commit is contained in:
Chris Proctor 2025-05-25 22:06:38 -04:00
parent 4781d533ec
commit 514af40b47
1 changed files with 33 additions and 0 deletions

33
demo.py Normal file
View File

@ -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)