xxxxxxxxxx
104
let r = 100;
let cyls;
function setup() {
createCanvas(400, 400, WEBGL);
cyls = [];
for (let t = 0; t < TWO_PI; t += TWO_PI / 12) {
let x = r * cos(t);
let y = r * sin(t);
let s = 50; // map(t, 0, TWO_PI, 50, 10);
cyls.push({
x: x,
y: y,
t: t,
s: s,
});
}
camera(200, -400, 800);
// saveGif("roller.gif", 8);
}
let ball_t = 0;
let ball_rot = 0;
function draw() {
// background(220);
orbitControl();
ambientLight(20);
pointLight(
100,
0,
0, // color
40,
-40,
0 // position
);
directionalLight(
20,
220,
20, // color
1,
1,
0 // direction
);
let _x = r * cos(ball_t);
let _y = r * sin(ball_t);
push();
noStroke();
normalMaterial();
ambientMaterial(20, 220, 20);
translate(0, 0, -250);
plane(1800);
pop();
// for (let t = 0; t < TWO_PI; t += TWO_PI / 12) {
for (let cyl of cyls) {
// let x = r * cos(t);
// let y = r * sin(t);
push();
normalMaterial();
// ambient materials reflect under any light
ambientMaterial(255, 0, 255);
// emissive materials show the same color regardless of light
emissiveMaterial(0, 0, 0);
// specular materials reflect the color of the light source
// and can vary in 'shininess'
shininess(10);
specularMaterial(0, 0, 0);
translate(cyl.x, 0, cyl.y);
rotateY(HALF_PI);
let _d = dist(_x, _y, cyl.x, cyl.y);
let _s = map(_d, 0, 250, 50, 10);
cylinder(25, _s);
pop();
}
push();
normalMaterial();
// ambient materials reflect under any light
ambientMaterial(0, 0, 255);
// emissive materials show the same color regardless of light
emissiveMaterial(0, 0, 0);
// specular materials reflect the color of the light source
// and can vary in 'shininess'
shininess(255);
specularMaterial(0, 0, 20);
translate(_x, -50, _y);
rotate(ball_t);
rotateX(ball_rot);
sphere(25);
pop();
ball_t += PI / 256;
ball_rot -= PI / 256;
}