Skip to content

Commit

Permalink
Merge pull request #138 from chris-greening/add-animate-feature
Browse files Browse the repository at this point in the history
Add animate repeat feature
  • Loading branch information
chris-greening authored Apr 7, 2023
2 parents 4a01aeb + d9b4427 commit 92ce83c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="spyrograph",
version="0.22.1",
version="0.23.0",
author="Chris Greening",
author_email="chris@christophergreening.com",
description="Library for drawing spirographs in Python",
Expand Down
25 changes: 14 additions & 11 deletions spyrograph/core/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,20 @@ def _draw_animation(
screen_color: str = "white", exit_on_click: bool = False,
color: str = "black", width: Number = 1,
frame_pause: Number = 0.1, screen: "turtle.Screen" = None,
screen_coords = (0, 0), padding: Number = 100
screen_coords = (0, 0), padding: Number = 100, repeat: bool = False
) -> None:
for shape in shapes_arr:
if screen is not None:
turtles.shape_turtle.clear()
screen, turtles = shape.trace(
screen = screen, screen_size = screen_size,
screen_color = screen_color,
color = color, width=width, screen_coords=screen_coords,
padding=padding
)
time.sleep(frame_pause)
while True:
for shape in shapes_arr:
if screen is not None:
turtles.shape_turtle.clear()
screen, turtles = shape.trace(
screen = screen, screen_size = screen_size,
screen_color = screen_color,
color = color, width=width, screen_coords=screen_coords,
padding=padding
)
time.sleep(frame_pause)
if not repeat:
break
if exit_on_click:
turtle.Screen().exitonclick()
7 changes: 5 additions & 2 deletions spyrograph/core/_trochoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def animate(
screen_color: str = "white", exit_on_click: bool = False,
color: str = "black", width: Number = 1,
frame_pause: Number = 0.1, screen: "turtle.Screen" = None, screen_coords = (0, 0),
padding: Number = 100
padding: Number = 100, repeat: bool = False
) -> List["_Trochoid"]:
"""
Animate a sequence of _Trochoid shapes with varying input parameters,
Expand Down Expand Up @@ -420,6 +420,9 @@ def animate(
Existing turtle screen.
padding : Number
Padding on the outside of the image
repeat : bool, optional
If True, infinitely repeat the animation so it starts over from the
beginning, default is False.
Returns
-------
Expand All @@ -442,7 +445,7 @@ def animate(
shapes_arr=shapes_arr, screen_size=screen_size,
screen_color=screen_color, exit_on_click=exit_on_click, color=color,
width=width, frame_pause=frame_pause, screen=screen,
screen_coords=screen_coords, padding=padding
screen_coords=screen_coords, padding=padding, repeat=repeat
)
return shapes_arr

Expand Down

0 comments on commit 92ce83c

Please sign in to comment.