Hello,
I can't figure out how to extract the data from the points created from an SVG loaded within an RG object.
The points seem to be created correctly (the println(points.length); line returns a positive number, not a null). However when calling the mousePressed function, I receive a NullPointerException message.
Actually this could be a syntax error too, I am not sure how to deal with arrays of objects...
Any help welcome !
I can't figure out how to extract the data from the points created from an SVG loaded within an RG object.
The points seem to be created correctly (the println(points.length); line returns a positive number, not a null). However when calling the mousePressed function, I receive a NullPointerException message.
Actually this could be a syntax error too, I am not sure how to deal with arrays of objects...
Any help welcome !
- import geomerative.*;
- RShape s;
- RShape polyshp;
- RPoint[] points;
- void setup() {
- size(640, 480, JAVA2D);
- RG.init(this);
- RG.ignoreStyles(true);
- s = RG.loadShape("BelgiumC.svg");
- rectMode(CENTER);
- smooth();
- }
- void draw() {
- background(192);
- strokeWeight(1);
- fill(128, 128, 0);
- stroke(0, 0, 0);
- polyshp = RG.polygonize(s);
- RG.shape(polyshp, 0, 0, 0.9 * width, 0.9 * height);
- RPoint[] points = s.getPoints(); // capture points
- println(points.length);
- stroke(255, 0, 0);
- fill(255, 255, 255);
- translate(0,0,0);
- for (int i = 0; i < points.length ; i = i + 50) {
- rect(((points[i].x) * (width/ s.width)), ((points[i].y) * (height/ s.height)), 10, 10);
- }
- }
- void mousePressed() {
- for (int i = 0; i < points.length ; i++) {
- println(points[i].x+" "+points[i].y);
- }
- }
1