Monster[] monsters; //monsters array
int numMonsters = 98; //number of monsters
void setup() {
smooth();
background(255);
size (600, 400);
monsters= new Monster[numMonsters];
for(int i=0;i<numMonsters;i++) //for loop. creating a new monster everytime. i starts as 0, then, for every i, there's a new monster. i increases by 1, as long as it's less than numMonster, which is 98.
{
monsters[i] = new Monster(); //for every monster, there's a new monster
}
}
void draw() {
background(255);
for(int i=0;i<numMonsters;i++)
{
monsters[i].recolor(i); //calling the function of color
monsters[i].move(); //calling the function of move
monsters[i].display(); //display function
}
}
class Monster {
int locx;
int locy;
int mouthsize = 2;
color c;
//constructing the monster, same as ex. L
Monster() {
locx = (int)random(0,600);
locy = (int)random(0,400);
c=color(0);
}
void display () {
fill(c);
ellipse(locx, locy, 60, 60);
fill(255);
ellipse(locx-17, locy-13, 10, 10);
ellipse(locx+17, locy-13, 10, 10);
if ((mouseX > (locx-25)) && (mouseX < (locx+25)) && (mouseY > (locy-25)) && (mouseY < (locy+25)))
mouthsize = 20;
else
mouthsize=2;
ellipse (locx, locy+10, mouthsize, 30);
}
void move()
{
locx=(int)(locx+(random(-3,4)));
locy=(int)(locy+(random(-3,4)));
if((locx>600)||(locx<0)||(locy>400)||(locy<0))
{
locx=(int)random(0,600);
locy=(int)random(0,400);
}
}
void recolor(int k) //color funciton. recoloring the monsters. each monster is a diff shade of pink.
{
c=color(2*(k+100),2*(k+10),k/2+80);
}
}Lena-M
on Sunday, Nov 23, 2008 – 5:32 pm