demo that you can animate any property
This commit is contained in:
parent
ec7bbad372
commit
e8aff3394e
@ -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)
|
||||
|
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user