We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm trying to animate a line drawing. This article helped me to do it: https://forum.processing.org/one/topic/make-a-dot-follow-a-svg-path.html But - I have an SVG with strokes in different colors. How can I read it so the slowly painted image looks like the sourcefile in the end? (The draw order or z-index is also interesting. ) I could not find any explanation how to get and use the stroke-color with geomerative anywhere. Best regards Jens
Answers
Can you share your sketch code and a link to a sample SVG file?
SVG files vary a lot -- the kind you are trying to animate makes a big difference.
Is this specifically a geomerative library question?
I create the SVG in inkscape. This is not necessarily a geomerative library question. I just found the code mentioned above that uses it. Perhaps it is possible to do this without the library(?)
Here is an svg i made for this test:
jensdreske.de/stuff/draw_svg_test/data/apple.svg
Here is the code:
Well, it looks like geomerative element does return that stroke color information. Have you tried using it?
https://github.com/rikrd/geomerative/blob/master/src/geomerative/RSVG.java#L430
No, I didn't try yet. Sorry, my programming skills are too poor. I just tried to read the "style" string in the svg like this:
This returns strings like this: 10 path4298 opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.41732287;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1
(I don't know how to get only the "stroke"-attribute however.)
I have no idea how to apply your suggestion using geomerative. I guess I could get the stroke-color somehow when the sketch loops through the children of Rshape (void exvert, line 76 code below) and store the colors somewhere, but I have no idea how to access this attribute? Could you give me a hint or some pseudocode how to do it? best regards Jens
Yeah! I got it :-)
Here is the complete sketch. It loads a .svg draws the stroke-paths in their original color and width, adjustable speed. Hit a key to start saving the pencil animation as a targa sequence with transparent background. strokes are drawn as little curve-segments, not ideal but the strokes look better. (the first and last few vertices are invisible though) suggestions welcome. best regards Jens
@royal_orchestra -- congratulations on solving the problem!
Thanks also for sharing your solution. It looks like the key SVG color information for each child shape was in:
Thanks, I'm happy it works. SInce the code above has some limitations here is an update with working opacity handling that produces nice lines without breaks and some other improvements. In case someone is interested in pencil animation.
What's missing now is a scribble effect that converts filled shapes to a vector- stroke that looks like drawn by hand. It seems the geomerative library is the way to go but the learning curve is hard...
Sounds interesting! Might be worth a separate question thread. I've got some ideas about how to tackle that -- and somebody might have done it already.
Shorter way to extract alpha: Instead of
rgb >> 24 & 0xff
, go w/rgb >>> 24
. *-:)Thanks! I opened a new thread: https://forum.processing.org/two/discussion/19052/how-to-convert-a-svg-fill-to-a-scribbled-stroke-path