fractalkitty looking for math? fractalkitty.com

100 days of code

chickenStep

#random#classes#image#interactive#animation#animals

starAnStepsstepAmakeStepsStar

let t=0,dx=10,dy=10;
let starA=[];
let nSteps = 50;
let stepA=[];
let p;
function preload(){
  p=loadImage('/assets/smallchicken.png')
  
}
function setup(){   
  noCursor();
  cnv=createCanvas(windowWidth,windowHeight); 
  angleMode(DEGREES);
  n=int(width/3);
  for(let i=0;i<n;i++){
    starA.push(new Star())
  }
  dx=random(width/10,width/3)
  dy=random(width/20,height/10)
  makeSteps()
}
function draw(){
  background(0);
  t=frameCount/10
  translate(width/2,height/2);
  fill(255);
  push()
  rotate(t)
  for(let i=0;i<n;i++){
    starA[i].move();
    starA[i].display();
  }
  pop()
  makeSteps()
  a=dx*5;
  b=dy*4
  push()
    image(p,mouseX-width/2-50,mouseY-height/2-50,dx,dx)
  pop()
}

function makeSteps(){
  stroke(57, 199, 204)
  fill(57, 199, 204)
  push()
  scale(1,-1)
  for (let i=0;i<nSteps;i++){
    x=-width/2
    rect(-width/2+dx*(i-1),-height/2+dy*i,dx,-2*height)
  }
  pop()
}

class Star{
  constructor(){
    this.x=random(-width,width);
    this.y=random(-height,height);
    this.r=random(0,width/2)
  }
  display(){
    circle(this.x,this.y,3);
  }
  move(){
      this.x=this.x
      this.y=this.y;
  }
}
function mousePressed(){
  dx=random(width/10,width/3)
  dy=random(width/20,height/10)
}