Friday, 19 October 2012

Final Code + Pictures

This is the code for my final Interactive Mouse Toy; I call it eyeball monsters.

//////////////////////////////// Below is the code




int x = 250; //X location
int y = 150; //Y location
int pupilx = 5;
int pupily = 6;
int s = 10;
int sun = 255; //sun opacity visible when released
int col = 255; //background colour
int bro = 0; //opacity visible when clicked
int grey =255;// grey parts of monster opacity
int grr = 1; //red in small eye


void setup(){
size(500,500);
frameRate(24);
smooth();
noCursor();
}

void draw(){
strokeWeight(1);
 noStroke();
//this is the code for the background and click monster

//beach and face
 fill (255,220,150,sun);
 rect (0,0,500,500);
 fill (60,30,10,bro);
 rect (0,0,500,500);

//big eye ring
 fill (102,170,255,sun);
 ellipse (x-400,y,750,500);
 ellipse (x+400,y,750,500);
 fill (20,bro);
 stroke(0,bro);
 strokeWeight (16);
 ellipse (x-400,y,750,500);
 ellipse (x+400,y,750,500);

//big eye outline
  strokeWeight(1);
  float o2 = map(mouseY, y-75, y+75, y-10, y+10);
  strokeWeight(4);
  stroke (0,bro);
  fill (255,0+(mouseX-pmouseX),0+(mouseX-pmouseX),bro);
  ellipse(x-270,o2,450,300);
  ellipse(x+270,o2,450,300);
  fill(255,220,70,sun);
  noStroke();
  ellipse(x-270,y,450,300);
  ellipse(x+270,y,450,300);
  //potential sun stars lines/triangles

//big pupil
  float i1 = map(mouseX, x-340, x-160, x-265, x-235);
  float i1b = map(mouseX, x+340, x+160, x+265, x+235);
  float i2 = map(mouseY, y-75, y+75, y-10, y+10);
   
//angryeyelines
stroke (255,0,0,bro);
strokeWeight(1);
 line (i1,i2,x-270,o2);
 line (i1-45,i2,x-495,o2);
 line (i1+45,i2,x-80,o2);
 line (i1,i2-45,x-270,o2-80);
 line (i1,i2+45,x-270,o2+80);
 line (i1-33,i2-33,x-373,o2-67);
 line (i1+33,i2+33,x-167,o2+65);
 line (i1-33,i2+33,x-373,o2+65);
 line (i1+33,i2-33,x-167,o2-65);

 line (i1b,i2,x+270,o2);
 line (i1b+45,i2,x+495,o2);
 line (i1b-45,i2,x+80,o2);
 line (i1b,i2+45,x+270,o2+80);
 line (i1b,i2-45,x+270,o2-80);
 line (i1b+33,i2+33,x+373,o2+67);
 line (i1b-33,i2-33,x+167,o2-65);
 line (i1b+33,i2-33,x+373,o2-65);
 line (i1b-33,i2+33,x+167,o2+65);


  noStroke();
  fill (20,bro);
  ellipse (i1,i2,100,100);
  ellipse (i1b,i2,100,100);
 
//face nose
 strokeWeight(16);
 stroke(0,bro);
 fill(60,30,20,bro);
 ellipse (x,500,600,200);
 fill (102,170,255,sun);
 ellipse (x,500,600,200);
 fill(0,bro);
 ellipse (100,500,250,100);
 ellipse (400,500,250,100);
 fill(255,220,70,sun);
 ellipse (100,500,250,100);
 ellipse (400,500,250,100);



//this is the start of the code for my monster   
//This is the shell of the eye 
 noStroke();
 strokeWeight(1);
 fill (150,grey);

 //legs
 triangle (x,y,250+mouseY,y+300,x+30,y);
 triangle (x,y,250-mouseY,y+300,x-30,y);
 triangle (251+mouseY,y+300,251+(mouseY*93/100),y+280,290+mouseY,y+320);
 triangle (249-mouseY,y+300,249-(mouseY*93/100),y+280,210-mouseY,y+320);

 //arms
 triangle (x-110,y,x-130,y,width-mouseX,height-mouseY);
 triangle (x+110,y,x+130,y,width-mouseX,height-mouseY);
 ellipse  (width-mouseX,height-mouseY,30,30);
 ellipse  (width-mouseX,height-mouseY,30,30);

 //grey eye shape
 ellipse (x,y,180,150);
 ellipse (x-90,y,80,40);
 ellipse (x+90,y,80,40);
 triangle (x,y,x-130,y,x-55,y-60);
 triangle (x,y,x-130,y,x-55,y+60);
 triangle (x,y,x+130,y,x+55,y+60);
 triangle (x,y,x+130,y,x+55,y-60);

//important floats
  float  x1 = map(mouseX, x-25, x+25, x-1, x+1);
  float x2 = map(mouseY, y-25, y+25, y-2, y+2);
//eyelashes 
 float zamberg = x1-25; // responsible for eyelashes
 while (zamberg<x1+25)
 {
 stroke(0);
 line (x1,x2,zamberg,x2+55);
 line (x1,x2,zamberg,x2-55);
 zamberg = zamberg+10;
 }
 
//This is the white (that turns red) eyeball part
  stroke(0);
  fill(255,255-(mouseX-pmouseX)*grr,255-(mouseX-pmouseX)*grr);
  ellipse(x1, x2, 100, 100);   
  
  

  
//This is the black pupil
 fill(0,0,0);
 float y1 = map(mouseX, x-25, x+25, x-pupilx, x+pupilx);
 float y2 = map(mouseY, y-25, y+25, y-pupily, y+pupily/2);

 stroke (255);
 line (x1,x2,y1,y2);
 line (x1-45,x2,y1-9,y2);
 line (x1+45,x2,y1+9,y2);
 line (x1,x2-45,y1,y2-9);
 line (x1,x2+45,y1,y2+9);
 line (x1-33,x2-33,y1,y2);
 line (x1+33,x2+33,y1,y2);
 line (x1-33,x2+33,y1,y2);
 line (x1+33,x2-33,y1,y2);

 noStroke();
 ellipse (y1,y2,30,30);
//this is the end of the code for my monster
}

void mousePressed(){
if (mousePressed == true){

  grey =100;
  bro = 255;
  grr = 0;
 
  col = 255;
  sun = 0;

}
}
void mouseReleased(){
  cursor (ARROW);
 
  grey =255;
  bro = 0;
  grr = 1;
 
  col = 255;
  sun = 255;
 
}

////////////////////////////////////////end of code.

Below are images of my working eyeball monsters mouse toy.






The small monster is interactive, his eye follows you and gets angry, and his limbs all move.
When the mouse is pressed and held the big monsters eyes move and get angry, they follow the small monsters gaze.

No comments:

Post a Comment