Animating a SVG path
Posted by Dan Nafe on Mar 12, 2007
My goal is to end up with a QTmovie of a progressively drawn path.
I have drawn a squiggly line in Inkscape and saved it as an svg file
My code (below) draws the line/path all at once. I need to draw it frame by frame.
What am i doing wrong?
svg = ximport("svg")
size(800,600)
speed(25)
def setup():
global i, c1, points, countPoints, oldPoint
points = []
path = svg.parse(open("drawing.svg").read())
i = 0
countPoints = 0
c1 = color(1,1,1,1)
fill(c1)
rect(0,0,WIDTH,HEIGHT)
c1 = color(0,1,0,0.66)
for point in path:
points.append(point)
countPoints += 1
oldPoint = points[0]
def draw():
global i, c1, points, countPoints, oldPoint
fill(c1)
rect (0,0, HEIGHT, WIDTH)
nofill()
stroke(1,0,0)
strokewidth(2)
autoclosepath(close=False)
beginpath(oldPoint)
drawpath(points[i])
endpath(points[i])
oldPoint = points[i]
if i < countPoints -1:
i += 1
Awesome stuff
How does this work if I have 2 or more paths in the same svg file?
;-) Thanks
Posted by Tom De Smedt on Mar 16, 2007
Hi Dan,
Try out the following code: