Geomerative's basics drive me crazy !
in
Contributed Library Questions
•
2 years ago
Hello,
I have problems with very basic things which are neither clearly documented in the reference nor illustrated with specific examples.
I have an SVG file including several paths. I want to put each path at a different place on the screen. Therefore I try to use pushMatrix() and popMatrix() around scale(), translate() and shape(RShape). However these push/pop instructions seem to be ignored. Therefore each path's position depends on position of the previous path which is very annoying. So I try to use geomerative's own translate and scale methods instead but it doesn't succeed : neither scaling nor translation is applied.
What's wrong ???????
I have problems with very basic things which are neither clearly documented in the reference nor illustrated with specific examples.
I have an SVG file including several paths. I want to put each path at a different place on the screen. Therefore I try to use pushMatrix() and popMatrix() around scale(), translate() and shape(RShape). However these push/pop instructions seem to be ignored. Therefore each path's position depends on position of the previous path which is very annoying. So I try to use geomerative's own translate and scale methods instead but it doesn't succeed : neither scaling nor translation is applied.
What's wrong ???????
- import processing.xml.*;
- import processing.opengl.*;
- import geomerative.*;
- //shapes
- RShape globalShape;
- RShape antwerp;
- RShape brussels;
- RShape oostVlaanderen;
- RShape westVlaanderen;
- RShape hainaut;
- RShape liege;
- RShape brabantWallon;
- RShape vlaamsBrabant;
- RShape limburg;
- RShape eupenMalmedy;
- RShape namur;
- RShape luxembourg;
- //positions for translation of children shapes (copied from SVG file's "M" field)
- float [][] positions = {{272.25576,92.861556}, {192.34967,123.16782}, {101.81014,41.658534}, {186.51245,43.969483}, {239.98491,21.830983},
- {308.79471,52.679144}, {313.47918,192.20721}, {64.091409,128.70649}, {258.13293,154.62728}, {234.57174,131.58658}, {330.07627,129.19335}, {360.70501,153.26992}};
- color [] myColor = {color(255, 0, 0), color(0, 255, 0), color(0, 200, 255), color(255, 255, 0)};
- void setup(){
- frameRate(1);
- size(800, 600);
- smooth();
- // VERY IMPORTANT: Allways initialize the library before using it
- RG.init(this);
- RG.ignoreStyles(true);
- globalShape = RG.loadShape("test.svg");
- westVlaanderen = RG.centerIn(globalShape.children[2], g);
- vlaamsBrabant = RG.centerIn(globalShape.children[0], g);
- oostVlaanderen = RG.centerIn(globalShape.children[3], g);
- antwerp = RG.centerIn(globalShape.children[4], g);
- brussels = RG.centerIn(globalShape.children[1], g);
- limburg = RG.centerIn(globalShape.children[5], g);
- hainaut = RG.centerIn(globalShape.children[7], g);
- liege = RG.centerIn(globalShape.children[10], g);
- brabantWallon = RG.centerIn(globalShape.children[9], g);
- eupenMalmedy = RG.centerIn(globalShape.children[11], g);
- namur = RG.centerIn(globalShape.children[8], g);
- luxembourg = RG.centerIn(globalShape.children[6], g);
- //initial drawing
- stroke(0, 0, 0, 255);
- scale(0.3, 0.3);
- strokeWeight(2);
- fill(225, 0, 0);
- background(255);
- translate(width/2, height/2);
- RG.shape(westVlaanderen);
- westVlaanderen.translate(positions[2][0], positions[2][1]);
- westVlaanderen.scale(1.0);
- RG.shape(oostVlaanderen);
- oostVlaanderen.translate(400., 200.);
- oostVlaanderen.scale(0.1);
- antwerp.translate(positions[3][0],positions[3][1]);
- antwerp.scale(0.1);
- RG.shape(antwerp);
- limburg.translate(positions[4][0], positions[4][1]);
- limburg.scale(0.1);
- RG.shape(limburg);
- liege.translate(positions[1][0], positions[1][1]);
- liege.scale(0.1);
- RG.shape(liege);
- eupenMalmedy.translate(positions[5][0], positions[5][1]);
- eupenMalmedy.scale(0.1);
- RG.shape(eupenMalmedy);
- luxembourg.translate(positions[7][0], positions[7][1]);
- luxembourg.scale(0.1);
- RG.shape(luxembourg);
- RG.shape(namur);
- namur.translate(positions[10][0], positions[10][1]);
- namur.scale(0.1);
- RG.shape(brabantWallon);
- brabantWallon.translate(positions[9][0], positions[9][1]);
- brabantWallon.scale(0.1);
- RG.shape(vlaamsBrabant);
- vlaamsBrabant.translate(positions[11][0], positions[11][1]);
- vlaamsBrabant.scale(0.1);
- RG.shape(hainaut);
- hainaut.translate(positions[8][0], positions[8][1]);
- hainaut.scale(0.1);
- RG.shape(brussels);
- brussels.translate(positions[6][0], positions[6][1]);
- brussels.scale(0.1);
- }
- void draw(){
- /*
- old way to do it - functions but every shape's position depends on previous shape
- stroke(0, 0, 0, 0);
- strokeWeight(0);
- scale(0.3, 0.3);
- background(255);
- translate(width/2, height/2);
- RG.shape(westVlaanderen);
- translate(470, 3);
- fill(myColor[int(random(0, 4))]);
- RG.shape(oostVlaanderen);
- //translate(501, -203);
- fill(myColor[int(random(0, 4))]);
- //scale(0.87);
- RG.shape(antwerp);
- translate(500, 295);
- fill(myColor[int(random(0, 4))]);
- scale(1.12, 1.12);
- RG.shape(limburg);
- translate(104, 449);
- fill(myColor[int(random(0, 4))]);
- scale(0.96, 0.96);
- RG.shape(liege);
- translate(380, 96);
- fill(myColor[int(random(0, 4))]);
- scale (1.1);
- RG.shape(eupenMalmedy);
- translate(-400, 456);
- fill(myColor[int(random(0, 4))]);
- scale(1.41, 1.41);
- RG.shape(luxembourg);
- translate(-270, -180);
- fill(myColor[int(random(0, 4))]);
- scale (0.93, 0.93);
- RG.shape(namur);
- translate(-128, -309);
- fill(myColor[int(random(0, 4))]);
- scale(0.5, 0.5);
- RG.shape(brabantWallon);
- translate(-27, -310);
- fill(myColor[int(random(0, 4))]);
- scale(1.44, 1.44);
- RG.shape(vlaamsBrabant);
- //translate(-485, 460);
- fill(myColor[int(random(0, 4))]);
- scale (1.45, 1.45);
- RG.shape(hainaut);
- //translate(270, -320);
- fill(myColor[int(random(0, 4))]);
- scale (0.23, 0.23);
- RG.shape(brussels);
- */
- }
1