let otterArray = []
let nOtters=1;
let t=0;
function setup(){
createCanvas(windowWidth,windowHeight);
angleMode(DEGREES);
otterArray.push(new Otter(0,0,1));
}
function draw(){
background(30,30,100);
t=frameCount/10
translate(width/2,height/2);
for (let i=0;i<nOtters;i++){
otterArray[i].display();
}
}
function makeOtter(){
stroke(206, 178, 156)
fill(156, 128, 106);//tail
triangle(-5,40,5,40,0,100);
ellipse(0,0,30,100)//body
ellipse(10,50,10,40)
ellipse(-10,50,10,40)
push()
rotate(-30)
translate(-48,52)
ellipse(0,0,20,10)
pop()
push()
rotate(30)
translate(48,52)
ellipse(0,0,20,10)
pop()
fill(100)
circle(0,-20,10)
fill(156, 128, 106);
ellipse(-10,-20,12,8)
ellipse(10,-20,12,8)
ellipse(0,-50,35,30)
fill(217, 192, 173)
ellipse(0,-44,13,12)
fill(0)
ellipse(0,-44,7,5)
ellipse(-10,-51,6,4)
ellipse(10,-51,6,4)
fill(255)
noStroke()
ellipse(-11,-51,2,1)
ellipse(9,-51,2,1)
stroke(0)
strokeWeight(0.5)
line(-10,-47,10,-40)
line(-10,-40,10,-47)
line(-10,-44,10,-44)
}
class Otter{
constructor(x,y,r){
this.x=x;
this.y=y;
this.r=r;
}
display(){
push()
translate(this.x+70*sin(t),this.y+30*sin(t))
rotate(360*sin(t*this.r+this.x));
translate(50*sin(t),30*cos(t));
makeOtter();
pop()
}
}
function mousePressed(){
otterArray.push(new Otter(mouseX-width/2,mouseY-height/2,random(-2,2)));
nOtters = nOtters+1;
if (nOtters>20){
otterArray=[];
setup();
nOtters=1;
}
}