fractalkitty looking for math? fractalkitty.com

100 days of code

wormSheep

#trig#classes#interactive#animation#animals

dArraynMoversoMover

let dArray=[];
let nMovers=0;
let m;
let b;
function setup(){
  createCanvas(windowWidth,windowHeight);
  background(0);
  frameRate(5)
  stroke(255)
  strokeWeight(0.2)
  
}

function draw(){
  background(0,0,0,2)
  noFill()
  circle(width/2,height/2,width/3-20*sin(frameCount/500))
  circle(width/2,height/2,width/2-20*sin(frameCount/500))
   circle(width/2,height/2,width/1.5+20*sin(frameCount/500))
  fill(200,230,200+55*cos(frameCount/10),10)
  stroke(200,230,200+55*cos(frameCount/10))
  for (let i=0;i<nMovers;i++){
    dArray[i].move(mouseX,mouseY)
    dArray[i].display()
  }
}

function mousePressed(){
  dArray.push(new oMover());
  nMovers++;
  
}

class oMover{
  constructor(){
    this.x = mouseX;
    this.y= mouseY;
  }
  move(x,y){
    m=(this.y-y)/(this.x-x+0.0001);
    b=y-m*x;
    this.x=this.x-(this.x-x)/400;
    this.y=m*this.x+b;
  }
  display(){
    push()
    circle(this.x,this.y,10);
    pop()
  }
}