xxxxxxxxxx
107
/*
RANDOM and noise
*/
let t = 0;
let sx,sy,sa,sp;
class Star{
constructor(x,y,a,spd){
this.x = x;
this.y = y;
this.a = a;
this.spd = 0;
}
reborn(){
this.x = random(width);
this.y = random(-height/2,0);
this.a = random(0,PI/4);
this.spd = random(10,20);
}
move(){
this.x = this.x + this.spd*cos(this.a)
this.y = this.y + this.spd*sin(this.a)
}
display(){
push();
fill(255);
ellipse(this.x,this.y,5);
pop();
}
}
function setup() {
createCanvas(800, 800);
randomSeed(100);
noiseSeed(1000);
sx = random(width);
sy = random(0,height/2);
sa = random(0,TAU); // 2pi
sp = random(1,20);
bx = 50;
}
function draw() {
background(20);
noStroke();
// noFill();
// stroke(255);
// stars
stars = []
for (let i = 0; i < 1000; i++) {
stars.push(new Star(random(width),random(-height/2,0),random(0,PI/4),random(10,20)))
}
fill(200,100,255);
let mx = cos(frameCount*0.001)*width;
let my = sin(frameCount*0.001)* width/2;
let ms = 500+cos(frameCount*0.05)*100;
// ellipse(mx+width/2, my+height,ms)
ellipse(width/2, height*3/4,ms)
fill(255);
for(let s = 0; s < stars.length;s++) {
stars[s].move();
stars[s].display();
if(stars[s].x > width || stars[s].x < 0||stars[s].y>height||stars[s].y<0) {
stars[s].reborn();
}
}
t = t+0.05
sx = sx + sp * cos(sa);
sy = sy + sp * sin(sa);
// for (let j = 0; j <1000; j++) {
// ex = noise(t+j)*width;
// ey = noise(t+j+100)*height;
// ellipse(ex,ey,5)
// }
ellipse(sx,sy,10);
if (sx > width || sx < 0||sy>height||sy<0){
sx = random(width);
sy = random(0,height/2);
sa = random(0,TAU); // 2pi
sp = random(1,20);
}
beginShape();
vertex(0,height);
for (let x = 0; x < width; x++) {
let v = noise((x+frameCount)*0.01) * width/2+width/2;
// ellipse(x,v,5);
vertex(x,v);
}
vertex(width, height)
endShape();
fill(200,0,0)
bx = (bx + 2)%width;
let by = noise((bx+frameCount)*0.01) * width/2+width/2;
ellipse(bx,by-25,50);
}