xxxxxxxxxx
44
// The Coding Train / Daniel Shiffman
// Video: https://youtu.be/O1mYw-3Wl_Q
let angle = 0;
let cam;
function setup() {
createCanvas(400, 300, WEBGL);
cam = createCapture(VIDEO);
cam.size(320, 240);
cam.hide();
}
function draw() {
background(175);
// Add a directional light
let dx = mouseX - width / 2;
let dy = mouseY - height / 2;
let v = createVector(dx, dy, 0);
v.div(100);
directionalLight(255, 255, 255, v);
// Add push and pop so rotate only affects box
push();
rotateX(angle);
rotateY(angle * 0.3);
rotateZ(angle * 1.2);
texture(cam);
box(100);
pop();
// Add a plane at bottom
translate(0, 100);
rotateX(HALF_PI);
ambientMaterial(255, 255, 255);
// Add noStroke to remove wireframe
noStroke();
plane(500, 500);
angle += 0.03;
}