Mouse Following Characters

New Media 100 lab assignment: Make a character that follows the mouse. I created a flock of birds for this assignment

function setup() 
{
 createCanvas(1000,1000); 
 bird0 = new Bird();
 bird1 = new Bird();
 bird2 = new Bird();
 bird3 = new Bird();
}

function draw() 
{
 background(200,200,200);
 bird0.display();
 bird1.display();
 bird2.display();
 bird3.display();
 
 
}

function Bird()
{
 this.x = random(0, width);
 this.y = random(0, height);
 this.speedx = random(3);
 this.speedy = random(3);
 this.direction = 1;
 this.size = random(10,80);
 this.wingstate = 0;
 this.wingmax = size;
 this.down = true;
 
 this.display = function()
 {
 if(mouseX > this.x)
 this.x = this.x+ this.speedx;
 else
 this.x = this.x - this.speedx;
 
 if(mouseY > this.y)
 this.y = this.y + this.speedy;
 else
 this.y = this.y - this.speedy;
 
 fill(0);
 ellipse(this.x, this.y, this.size*2, this.size*0.5);
 
 triangle(this.x+this.size/2*this.direction, this.y+this.size/6, this.x+(this.size+(this.size/3))*this.direction,this.y + this.size/4, this.x+this.size/1.5*this.direction, this.y-this.size/4.8);
 triangle(this.x, this.y+this.size/6, this.x+(this.size+(this.size/2))*-this.direction, this.y + this.size/2, this.x+this.size/2*-this.direction, this.y-this.size/4.5);
 
 if(this.down)
 this.wingstate = this.wingstate + 2;
 else
 this.wingstate = this.wingstate-2;
 
 if(this.wingstate > this.size)
 this.down = false;
 if(this.wingstate < this.size *-1)
 this.down = true;
 
 if(this.x> mouseX)
 this.direction = -1;
 if(this.x < mouseX)
 this.direction = 1;
 
 triangle(this.x - (this.size/2), this.y, this.x+(this.size/2), this.y, this.x-(this.direction*50), this.y+this.wingstate);
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *