From e8aff3394e4d58f462b0c38da76793c7f85b842e Mon Sep 17 00:00:00 2001 From: James Turk Date: Tue, 30 Apr 2024 20:06:01 -0500 Subject: [PATCH] demo that you can animate any property --- src/doodles/examples/clock.py | 17 +++++++++++++---- src/doodles/lines.py | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/doodles/examples/clock.py b/src/doodles/examples/clock.py index ab3445d..acfe4a6 100644 --- a/src/doodles/examples/clock.py +++ b/src/doodles/examples/clock.py @@ -1,17 +1,26 @@ import time +import math from doodles import Circle, Color, Line, Group def color_func(t): - print("updating color") cycle = [Color.RED, Color.ORANGE, Color.GREEN, Color.BLUE] return cycle[int(t) % 4] +def size_func_factory(min_size, factor): + def size_function(t): + return math.sin(t) * factor + min_size + + return size_function + + def create(): g = Group().pos(400, 300) - Circle(g).radius(300).color(Color.BLACK).z(1) - Circle(g).radius(290).color(Color.BROWN).z(10) + Circle(g).color(Color.BLACK).z(1).animate("radius", size_func_factory(260, 50)) + Circle(g).z(10).animate("color", color_func).animate( + "radius", size_func_factory(250, 50) + ) Circle(g).radius(20).color(Color.BLACK).z(50) # Line(g).vec( # lambda: time.time() % 60 / 60 * 360, @@ -19,4 +28,4 @@ def create(): # ).z(100) l = Line(g).vec(0, 200).z(100).animate("degrees", lambda t: t % 60 / 60 * 360) - l.animate("color", color_func) + # l.animate("color", color_func) diff --git a/src/doodles/lines.py b/src/doodles/lines.py index 88a1281..623c276 100644 --- a/src/doodles/lines.py +++ b/src/doodles/lines.py @@ -81,7 +81,7 @@ class Line(Doodle): """ Alternate setter, like calling vec(new_degrees, old_magnitude). """ - magnitude = math.sqrt(self._offset_vec[0]**2 + self._offset_vec[1]**2) + magnitude = math.sqrt(self._offset_vec[0] ** 2 + self._offset_vec[1] ** 2) return self.to( magnitude * math.cos(math.radians(degrees)), magnitude * math.sin(math.radians(degrees)),