plankton
_Created for the [May 2021 CodePen Challenge](https://codepen.io/challenges/2021/May)_
let p=[];
let n=500;
function setup(){
createCanvas(windowWidth,windowHeight);
strokeWeight(0.5);
for(let i=0;i<n;i++){
p.push(new plankton());
}
}
function draw(){
background(0,10,50);
translate(width/2,height/2);
t=frameCount/1200
rotate(t*3)
for (let i = 0;i<n;i++){
p[i].move();
p[i].display();
}
}
class plankton{
constructor(){
this.x1=randomGaussian(-width/2,width/2);
this.y1=randomGaussian(-height/2,height/2);
this.type = int(random(1,4.2))
this.size = int(random(3,20))
this.radius = random(100,400)
this.x=this.x1;
this.y=this.y1;
}
move(){
this.x = this.x1*cos(t*this.type-this.radius)-this.x1*sin(this.type*t)-this.x/4*sin(t+this.x1);
this.y = this.y1*cos(t/this.size)+this.y1*sin(t+this.radius)*cos(t/5+this.x1);
}
display(){
push()
rotate(t/1000*this.size)
if (this.type === 1){
stroke(255);
fill(0,180-this.x/2,200+this.y/2);
circle(this.x,this.y,this.size);
noStroke()
fill(190,120,90+this.y/2,90);
circle(this.x,this.y,this.size/2);
fill(190+this.x/2,190,90,90);
circle(this.x,this.y,this.size/4);
}
if (this.type === 2){
push()
rotate(this.radius*2)
fill(this.x/10,180-this.x/2,200+this.y/2);
stroke(0,180-this.x/2,200+this.y/2);
for(let j=0;j<this.size;j++){
push()
rotate(j/50+this.x/1000);
rect(this.x,this.y+j*2,this.size/5,this.size/20)
pop()
}
pop()
}
if (this.type ===3){
push()
rotate(this.radius*2)
stroke(255)
noFill()
for(let j=0;j<this.type;j++){
push()
arc(this.x, this.y+j, this.size*4, this.size*4, 0, TWO_PI/(this.size/2))
pop()
}
pop()
}
if (this.type ===4){
stroke(255)
push()
translate(this.x,this.y)
for (let j=0;j<this.size*2;j++){
rotate(j)
point(j/4,j/4)
}
pop()
}
pop()
}
}
function mouseClicked(){
p=[];
for(let i=0;i<n;i++){
p.push(new plankton());
}
}