xxxxxxxxxx
let cat;
let positions = [];
// Load the file and create a p5.Geometry object.
function preload() {
cat = loadModel('cat_v3.stl');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
const total = 200;
const radius = 200;
for(var i = 0; i < total; i++){
const distance = lerp(2, 3.5, Math.random());
const x = sin(i/total*TWO_PI) * (radius + random(-50, 50));
const z = cos(i/total*TWO_PI) * (radius + random(-50, 50));
const y = lerp(-20, 20, Math.random());
const vel = Math.random() + 0.1;
positions.push({x, y, z, vel})
}
}
function draw() {
ambientLight(255, 100, 0);
pointLight(
255, 100, 0, // color
40, -40, 0 // position
);
directionalLight(
0,255,0, // color
1, 1, 0 // direction
);
background(255, 187, 0);
const bounds = 1;
const mouseXRot = map(mouseX, 0, width, PI/2-bounds, -PI/2+bounds, true);
const mouseYRot = map(mouseY, 0, height, -PI/2+bounds, PI/2-bounds, true);
push();
translate(10, 0);
rotateZ(PI);
rotateX(-PI/6);
rotateY(mouseXRot);
rotateX(mouseYRot);
translate(-10, 0);
fill(255);
model(cat);
pop();
push();
noFill();
stroke(0);
rotateX(PI/6);
rotateY(mouseXRot);
rotateX(mouseYRot);
positions.forEach(p => {
push();
rotateY(p.vel * (-frameCount / 100));
translate(p.x, p.y, p.z);
stroke(255);
box(5);
pop();
})
pop();
}