Animating a line #121
Answered
by
cduck
PieterMostert
asked this question in
Q&A
Animating a line
#121
-
I've tried modify the example in the README to animate the endpoints of a line, but nothing happens:
Am I doing something wrong, or is this a bug? Either way, I'd appreciate advice on how to get this to work. |
Beta Was this translation helpful? Give feedback.
Answered by
cduck
Mar 5, 2024
Replies: 1 comment 1 reply
-
This is a bug because the underlying SVG tag used by Workaround: import drawsvg as draw
d = draw.Drawing(400, 200, origin='center',
animation_config=draw.types.SyncedAnimationConfig(
# Animation configuration
duration=8, # Seconds
show_playback_progress=True,
show_playback_controls=True))
class Line(draw.DrawingBasicElement):
'''A line element that uses the SVG <line> tag.
The endpoints of this custom Line element can be animated. This is a workaround because `drawsvg.Line`
cannot be animated.'''
TAG_NAME = 'line'
def __init__(self, x1, y1, x2, y2, **kwargs):
super().__init__(x1=x1, y1=y1, x2=x2, y2=y2, **kwargs)
line = Line(0, 0, 0, 200, stroke_width=4, stroke='red') # Moving line
line.add_key_frame(0, x1=0, y1=0, x2=200, y2=0)
line.add_key_frame(8, x1=0, y1=200, x2=0, y2=0)
d.append(line)
d.display_inline() # Display as interactive SVG |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cduck
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a bug because the underlying SVG tag used by
Line
is<path>
, not<line>
. I've opened issue #122 for this.Workaround: