Compare commits

...

2 Commits

Author SHA1 Message Date
Chris Proctor bf2d2b0774 Add demos 2025-06-26 13:00:45 -04:00
Chris Proctor 02902dac51 ADjust ellipse starting angle 2025-06-26 13:00:31 -04:00
4 changed files with 35 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

View File

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body style="background-image: url(demo.gif); background-repeat: cover;">
</body>
</html>

View File

@ -0,0 +1,26 @@
from ellipse import ellipse
from superturtle.animation import animate
from superturtle.easing import easeInOutCubic
from turtle import color, fillcolor, begin_fill, end_fill
n_frames = 128
def is_even(n):
return n % 2 == 0
def set_colors(n):
"Sets the color and fill color to white when n is even, otherwise black."
if is_even(n):
color('white')
fillcolor('white')
else:
color('black')
fillcolor('black')
for frame in animate(n_frames, loop=True, gif_filename="demo.gif"):
for r in reversed(range(2, 30)):
set_colors(r)
with frame.rotate(0, 360, r, n_frames - r, easing=easeInOutCubic):
begin_fill()
ellipse(5 * r, 10 * r, 128)
end_fill()

View File

@ -12,15 +12,16 @@ def ellipse(rx, ry, num_points, points_to_draw=None):
the +x direction, and ends in the same position and heading.
"""
radians()
φstart = get_angle(rx, ry, num_points, 0) / 2
fly(rx)
left(π/2)
left(π/2 - φstart)
for i in range(points_to_draw or num_points):
φi = get_angle(rx, ry, num_points, i)
di = get_distance(rx, ry, num_points, i)
print(i, φi, di)
left(φi)
forward(di)
left(-π/2)
left(-π/2 + φstart)
fly(-rx)
degrees()