xxxxxxxxxx
66
let blue_shades = [100, 255, 171, 182, 220, 40, 56, 102, 209];
let fade;
let fadeAmount = 1
let coordinates = [];
let fractalNum = [];
let crystalNum = 40;
function setup() {
createCanvas(500, 500);
CrystalCoord(crystalNum);
fade = 0;
}
function draw() {
background(0);
for(let i=0; i<crystalNum; i++) {
push();
translate(coordinates[i], coordinates[i+1]);
drawCrystal(fractalNum[i]);
pop();
}
push();
translate(width/2, height/2);
drawCrystal(10);
pop();
}
function star(x, y, radius1, radius2, npoints) {
let angle = TWO_PI / npoints;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}
function drawCrystal(spin) {
for(let i=0; i<spin; i++) {
rotate(frameCount/-1000);
if (fade<0) fadeAmount=0.005;
if (fade>255) fadeAmount=-0.005;
fade += fadeAmount;
fill(0, 0, blue_shades[i], fade);
star(0, 0, ((10*spin + 70) - 10 *i)/2.333, ((10*spin + 70) - 10*i), 4);
}
}
function CrystalCoord(num) {
for(let i = 0; i<num; i++) {
coordinates[i] = random(0, width);
coordinates[i+1] = random(0, height);
fractalNum[i] = random(0, 10);
}
}