Loading...
Logo
Processing Forum
Hey,
i would like to animate a SVG file with processing,

Pshape as Geomerative can interpret single shapes in such files.

Maybe the Elements are defined in a index within the file, so i could contact them.
Is it possible to refer to different Elements in a Svg file and for example move them from one to another point or change the shape by code?

greets
run.dos.run

Replies(2)

In InkScape or Illustrator, you can take the each element or group of elements, and put them in a top-level group (using group / ungroup).  This grouping is represented in the internal hierarchy of the file.  Then, using Geomerative, you can use the top level groupings as an organizational tool.

For example, this code recursively navigates through all the paths associated with a shape:
import geomerative.*;

void setup(){
  size(800, 600);
  RG.init(this);

  RShape shp = RG.loadShape("test.svg");
  grabAllPaths(shp,0);
}

void navPaths(RShape shp)
{
  if (shp.paths != null) {
    println(level + ": " + shp.paths.length);
  } else {
    println(level + ": null");
  }
  if (shp.children != null) {
    for (int i =0 ; i < shp.children.length; ++i) {
      navPaths(shp.children[i]);
    }
  }
}

In InkScape, I created a test SVG file with 3 rectangles.  It prints this when I run this on it

0: null
1: null
2: 1
2: 1
2: 1
3 paths


I then grouped two of the rectangles into a group.  Now I get this:

0: null
1: null
2: 1
2: null
3: 1
3: 1
3 paths

So the grouping is represented in the file.  I could treat the level "2" elements as my animation units.


in illustrator you can also make different layers, then in processing you can get the layer.
I used this method before and it's really nice.