xxxxxxxxxx
37
let d = 150;
let loc;
let vel;
let sph = d/2;
function setup() {
createCanvas(600, 600, WEBGL);
loc = createVector(0, 0, 0);
vel = createVector(random(1, 3), random(1, 3), random(1, 3));
}
function draw() {
background(220);
loc.add(vel);
noFill()
rotateY(PI/4.0)
box(2*d);
push()
stroke(5);
fill(255, 0, 0);
translate(loc.x, loc.y, loc.z);
if (loc.x > d - sph || loc.x < -d + sph) {
vel.x *= -1;
}
if (loc.y > d - sph || loc.y < -d + sph) vel.y *= -1;
if (loc.z > d - sph || loc.z < -d + sph) vel.z *= -1;
sphere(sph);
pop();
/*
*/
}