/**
* Wiggling.
*
* Press 'w' to start wiggling, space to restore
* original positions.
*/
PShape cube;
float cubeSize = 450;
float circleRad = 400;
int circleRes = 15;
float noiseMag = 1;
boolean wiggling = false;
void setup() {
size(displayWidth,displayHeight, P3D);
createCube();
}
void createCube() {
cube = createShape(GROUP);
PShape face;
// Front face
face = createShape();
face.beginShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face.beginContour();
face.vertex(-cubeSize/2, -cubeSize/2, +cubeSize/2);
face.vertex(+cubeSize/2, -cubeSize/2, +cubeSize/2);
face.vertex(+cubeSize/2, +cubeSize/2, +cubeSize/2);
face.vertex(-cubeSize/2, +cubeSize/2, +cubeSize/2);
face.endContour();
face.beginContour();
for (int i = 0; i < circleRes; i++) {
float angle = TWO_PI * i / circleRes;
float x = circleRad * sin(angle);
float y = circleRad * cos(angle);
float z = +cubeSize/2;
face.vertex(x, y, z);
}
face.endContour();
face.endShape(CLOSE);
cube.addChild(face);
// Back face
face = createShape();
face.beginShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face.beginContour();
face.vertex(+cubeSize/2, -cubeSize/2, -cubeSize/2);
face.vertex(-cubeSize/2, -cubeSize/2, -cubeSize/2);
face.vertex(-cubeSize/2, +cubeSize/2, -cubeSize/2);
face.vertex(+cubeSize/2, +cubeSize/2, -cubeSize/2);
face.endContour();
face.beginContour();
for (int i = 0; i < circleRes; i++) {
float angle = -TWO_PI * i / circleRes;
float x = circleRad * sin(angle);
float y = circleRad * cos(angle);
float z = -cubeSize/2;
face.vertex(x, y, z);
}
face.endContour();
face.endShape(CLOSE);
cube.addChild(face);
* Wiggling.
*
* Press 'w' to start wiggling, space to restore
* original positions.
*/
PShape cube;
float cubeSize = 450;
float circleRad = 400;
int circleRes = 15;
float noiseMag = 1;
boolean wiggling = false;
void setup() {
size(displayWidth,displayHeight, P3D);
createCube();
}
void createCube() {
cube = createShape(GROUP);
PShape face;
// Front face
face = createShape();
face.beginShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face.beginContour();
face.vertex(-cubeSize/2, -cubeSize/2, +cubeSize/2);
face.vertex(+cubeSize/2, -cubeSize/2, +cubeSize/2);
face.vertex(+cubeSize/2, +cubeSize/2, +cubeSize/2);
face.vertex(-cubeSize/2, +cubeSize/2, +cubeSize/2);
face.endContour();
face.beginContour();
for (int i = 0; i < circleRes; i++) {
float angle = TWO_PI * i / circleRes;
float x = circleRad * sin(angle);
float y = circleRad * cos(angle);
float z = +cubeSize/2;
face.vertex(x, y, z);
}
face.endContour();
face.endShape(CLOSE);
cube.addChild(face);
// Back face
face = createShape();
face.beginShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face.beginContour();
face.vertex(+cubeSize/2, -cubeSize/2, -cubeSize/2);
face.vertex(-cubeSize/2, -cubeSize/2, -cubeSize/2);
face.vertex(-cubeSize/2, +cubeSize/2, -cubeSize/2);
face.vertex(+cubeSize/2, +cubeSize/2, -cubeSize/2);
face.endContour();
face.beginContour();
for (int i = 0; i < circleRes; i++) {
float angle = -TWO_PI * i / circleRes;
float x = circleRad * sin(angle);
float y = circleRad * cos(angle);
float z = -cubeSize/2;
face.vertex(x, y, z);
}
face.endContour();
face.endShape(CLOSE);
cube.addChild(face);