Error with getVertex() from SVG file
in
Programming Questions
•
8 months ago
Hello,
I have successfully loaded a svg file (just using an octagon) I created with Illustrator CS5. My goals are to move the vertices around once loaded; however, I receive an array out of bound exception directed at
duplicate = shapes[i].getVertex(j);
My code is below:
-----------------------------------------------------------------------------------------------------------
PShape squiggle;
PShape[] shapes;
PVector duplicate;
void setup() {
size(800, 800);
smooth();
shapeMode(CENTER);
squiggle = loadShape("octagon1.svg");
shapes = squiggle.getChildren();
squiggle.disableStyle();
noLoop();
}
void draw() {
background(255);
for (int i = 0; i < shapes.length; i++) {
int v = shapes[i].getVertexCount();
println("vertex count: " + v);
println("shapes.length: " + shapes.length);
for (int j = 0; j < 8; j++) {
duplicate = shapes[i].getVertex(j);
println("duplicate x is: " + duplicate.x);
duplicate.x += random(-1, 1);
duplicate.y += random(-1, 1);
shapes[i].setVertex(j, duplicate);
// int code = shapes[i].getVertexCode(j);
// println("vertex code for vertex #" + j + ": " + code);
}
shape(shapes[i]);
}
}
1