xxxxxxxxxx
// falling prims
// by tony zito 10/9/21
var cubes = [];
function setup() {
width = 600;
height = 600;
margin = 50;
createCanvas(width, height, WEBGL);
background(randomColor());
numObjects = 18;
for (let i = 0; i < numObjects; i++) {
var cube = {
x: random(-width / 2 + margin, width / 2 - margin),
y: random(-height / 2 + margin, height / 2 - margin),
z: random(10),
size: random(50, 100),
rotXSpeed: random(0, .02),
rotYSpeed: random(0, .02),
color: randomColor()
}
tooClose = false;
for (let j = 0; j < cubes.length; j++) {
other = cubes[j];
// print("dist: " + dist(cube.x,cube.y,other.x,other.y));
if (dist(cube.x, cube.y, other.x, other.y) < cube.size + other.size) {
tooClose = true;
print("too close!");
break;
}
}
if (!tooClose) {
print("adding cube to array");
cubes.push(cube);
}
}
}
function draw() {
clear();
// for (let i = 0; i < cubes.size; i++) {
// // create cubes
// let cube = cubes[i];
// print("cube " + i + " : " + cube.x +", " + cube.y + " -- " cube.size);
// }
for (i = 0; i < cubes.length; i++) {
push();
// print("cube " + i + " : " + cubes[i].x + ", " + cubes[i].y + " -- " + cubes[i].size);
// noStroke();
stroke(cubes[i].color);
fill(cubes[i].color);
translate(cubes[i].x, ((cubes[i].y + frameCount) % height - (height / 2)), cubes[i].z);
rotateX(frameCount * cubes[i].rotXSpeed);
rotateY(frameCount * cubes[i].rotYSpeed);
cone(cubes[i].size);
pop();
}
}
function randomColor() {
r = random(255); // r is a random number between 0 - 255
g = random(255); // g is a random number betwen 100 - 200
b = random(255); // b is a random number between 0 - 100
a = random(100, 200); // a is a random number between 200 - 255
return color(r, g, b, a);
}