xxxxxxxxxx
/******************
Code by Vamoss
Original code link:
https://openprocessing.org/sketch/2400701
Author links:
http://vamoss.com.br
http://twitter.com/vamoss
http://github.com/vamoss
******************/
var cometas = [];
var step = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
cometas.push(new Cometa(50, 0.7, true));
cometas.push(new Cometa(50, PI+0.7, true));
var total = 150;
const PHI = (1 + sqrt(5))/2; //golden ratio
for(var i = 10; i < total; i++){
var radius = sqrt(i * PHI) * 22;
var angle = i * PHI * TAU;
cometas.push(new Cometa(radius, angle));
}
}
function draw() {
background(255);
noStroke();
var time = frameCount / 30;
var ease = (sin(sin(sin(time)*2)*2)+1)/2;
step += 1.5 * ease;
cometas.forEach((cometa, i) => {
const r = (1+(cometas.length-i)*0.005);
var angleMax = map(sqrt(i), 0, sqrt(cometas.length), PI/4, 0.1);
if(cometa.special){
angleMax *= 2.5;//no tail = 0.015
}
for(var a = 0; a < angleMax; a += 0.01){
const x = sin(cometa.a + a - step) * cometa.r + width/2;
const y = cos(cometa.a + a - step) * cometa.r + height/2;
var length = map(a, 0, angleMax, 23, 5);// * r;
if(cometa.special){
fill(255, 0, 0);
length *= 1.5;
}else{
fill(0);
}
circle(x, y, length);
}
/*
const x2 = sin(cometa.a - step) * cometa.r + width/2;
const y2 = cos(cometa.a - step) * cometa.r + height/2;
fill(255);
circle(x2, y2, 15 * r);
*/
})
}
class Cometa {
constructor(r, a, special){
this.r = r;
this.a = a;
this.special = special;
}
}