Following up on this… Could someone please try to see if the following code loads on your end?
If I keep the P2D renderer for texture() to work I would get an error, and if I remove it for the polygon properties to work then texture() would not load .
Wiggler w;
PImage flag;
void setup() {
size(800,800,P2D);
w = new Wiggler();
}
void draw() {
w.display();
w.wiggle();
}
class Wiggler {
//The PShape to be wiggled
PShape spain;
//It's location
float x,y;
Wiggler() {
x = width/2;
y = height/2;
spain = createShape();
spain.beginShape();
flag = loadImage("spain-flag.jpg");
texture(flag);
spain.noFill();
spain.stroke(255);
spain.strokeWeight(3);
//draw Spain as a polygon and distort the flag inside the polygon
spain.vertex(100,-250,480,0);
spain.vertex(-250,-250,0,160);
spain.vertex(-250,-150,0,240);
spain.vertex(-150,-150,0,240);
spain.vertex(-150,150,0,600);
spain.vertex(-50,250,360,800);
spain.vertex(0,200,400,800);
spain.vertex(150,150,520,800);
spain.vertex(250,50,800,440);
spain.vertex(200,0,800,400);
spain.vertex(300,-250,800,160);
spain.endShape(CLOSE);
}
void wiggle() {
//To iterate over the vertices of a PShape, you can loop from 0 to the total number
//of vertices (getVertexCount()). Assuming a PShape "s", this would look something
//like:
for(int i = 0; i < spain.getVertexCount(); i++) {
//The vertices can be retrieved as PVector objects with getVertex().
PVector vspain = spain.getVertex(i);
//You could then move that vertex by manipulating the PVector and setting new
//values with setVertex().
vspain.x += random(-0.5,0.5);
vspain.y += random(-0.5,0.5);
spain.setVertex(i,vspain.x,vspain.y);
}
}
void display() {
pushMatrix();
translate(x,y);
shape(spain);
popMatrix();
}
}