xxxxxxxxxx
let forms = [];
let colors = ["#ef233c", "#d5f2e3", "#73ba9b", "#003e1f", "#d90429", "#ffda33"];
let stars = [];
function setup() {
createCanvas(1000, 750);
rectMode(CENTER);
let w = 25;
let n = 20;
for(let i=0; i<n; i++){
let nn = int(map(i, 0, n, 0, 20));
for(let j=0; j<nn; j++){
let x = (width * 0.5) - ((nn * w)/2) + j * w;
let y = (i * w * 1.25) + height * 0.05;
forms.push(new Form(x, y));
}
}
for(let i=0; i<60; i++){
stars.push(createVector(random(width), random(height), random(1, 10)));
}
}
function draw() {
background(10);
strokeWeight(1);
for(let s of stars){
let alph = noise(frameCount * 0.01 * s.z, s.z, s.y)*255;
stroke(255, alph);
line(s.x + (s.z * 0.5), s.y, s.x - (s.z * 0.5), s.y);
line(s.x, s.y + (s.z * 0.5), s.x, s.y - (s.z * 0.5));
}
for(let f of forms){
f.run();
}
}
class Form{
constructor(x, y){
this.x = x;
this.y = y;
this.setValues();
}
run(){
noFill();
stroke(this.col);
this.ss.run();
if(this.ss.isDead()){
this.setValues();
}
}
setValues(){
this.col = color(random(colors));
let rnd = int(random(3));
let s = random(10, 30);
if(rnd == 0){
this.ss = new Circle(this.x, this.y, s);
}
if(rnd == 1){
this.ss = new Square(this.x, this.y, s);
}
if(rnd == 2){
this.ss = new Cross(this.x, this.y, s);
}
}
}
class Circle{
constructor(x, y, s){
this.x = x;
this.y = y;
this.s = 0;
this.s0 = s*0.5;
this.s1 = s;
this.sw1 = s * 0.5;
this.sw = 1;
this.t = int(random(-200));
this.t1 = 80;
this.t2 = 80 + this.t1;
this.ang = int(random(2)) * PI * 0.25;
}
show(){
strokeWeight(this.sw);
circle(this.x, this.y, this.s);
}
move(){
if(0 <= this.t && this.t < this.t2){
let nrm = norm(this.t, 0, this.t1-1);
this.s = lerp(0, this.s0, nrm);
this.sw = lerp(1, this.sw1, nrm);
}
if(this.t1 <= this.t && this.t < this.t2){
let nrm = norm(this.t, this.t1, this.t2-1);
this.s = lerp(this.s0, this.s1, nrm);
this.sw = lerp(this.sw1, 0, nrm);
}
this.t ++;
}
isDead(){
return this.t > this.t2;
}
run(){
if(0 < this.t){
this.show();
}
this.move();
}
}
class Square extends Circle{
constructor(x, y, s, t){
super(x, y, s, t);
}
show(){
push();
translate(this.x, this.y);
rotate(this.ang);
strokeWeight(this.sw);
square(0, 0, this.s);
pop();
}
}
class Cross extends Circle{
constructor(x, y, s, t){
super(x, y, s, t);
}
show(){
push();
translate(this.x, this.y);
rotate(this.ang);
strokeWeight(this.sw);
line(0 + this.s*0.5, 0, 0 - this.s*0.5, 0);
line(0, 0 + this.s*0.5, 0, 0 - this.s*0.5);
pop();
}
}