xxxxxxxxxx
34
var angle = 0;
function setup() {
createCanvas(400, 300, WEBGL);
// Still a 2D plane - just unlocking 3D
// perspective
rectMode(CENTER);
//angleMode(DEGREES); // Makes rotation
// MUCH slower
}
function draw() {
background(175);
fill(255, 0, 150); // pink
// translate(mouseX-width/2, mouseY-height/2); // weird behaving
// if translate before rotate
// no pixel accuracy
// cursor not on image
// subtract out starting point
translate(0, 0);
// use mouseX position to update
// box() position along Z axis
rotateX(angle); // need this function before
// you draw rect!!!
rotateY(angle*0.3); // Rotating along
// X and Y axes
rotateZ(angle*1.2); // All three axes spin
//rect(0, 0, 150, 150);
torus(100, 10); // adds a 3D shape with defaults
// Can change width, height, and depth
angle += 0.03;
}