Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*Wish to play with a cat? Then, here you go!
 
  Try to make the kitten pounce!
  Programmer: Dominique Watt
 
  You can move your mouse, and you'll move a toy mouse on screen! (it's a cute little connection no?)
  Move the mouse left and right and taunt the kitty!
  (Moving the mouse up and down causes the cat's butt to move a little)
  Clicking the screen causes the toy to squeek!
  Pressing the button cause the mouse to switch colours?
  Go ahead! Try and make the kitten pounce on the mouse!
 
 */
 
void setup()
{
  //Setting the size of the program
  size(400, 400);
}
void draw()
{ 
  //setting background colour, setting frameRate to make the program not freeze when actions happen
  frameRate(60);
  noStroke();
  background(255);

  /*FLOOR SECTION*/
  
  //Floor colour
  fill(18,24,38);
  rect(0, 190, 400, 270);
  
  //Cat floor shadows
  fill(150);
  ellipse(200, 240, 100, 22);
  ellipse(200, 222, 100, 20);

  /*WALL SECTION*/
  
  //Wall colour
  noStroke();
  fill(8,60,98);
  rect(0, 0, 400, 180);

  //The BIG window frame
  fill(255);
  noStroke();
  rect(65, 15, 280, 130);

  //BIG window frame details
  noFill();
  stroke(0);
  line(65, 15, 80, 30);
  line(330, 30, 344, 15);
  line(79, 130, 65, 144);
  line(344, 144, 330, 130);

  /*OUTSIDE WINDOW BACKGROUND*/
  fill(18,1,36);
  noStroke();
  rect(80, 30, 250, 100);

  /*PRETTY MOON SECTION*/
  
  //drawing the moon and brightness layers, moving mouse adjusts brightness slightly
  fill(255);
  noStroke();
  ellipse(200, 70, 10, 10);
  fill(255, 255, 255, 180+(mouseX*0.03));
  ellipse(200, 70, 20, 20);
  fill(255, 255, 255, 160+(mouseX*0.03));
  ellipse(200, 70, 30, 30);
  fill(255, 255, 255, 140+(mouseX*0.03));
  ellipse(200, 70, 40, 40);
  fill(255, 255, 255, 120+(mouseX*0.03));
  ellipse(200, 70, 50, 50);
  fill(255,255,255,100+(mouseX*0.03));
  ellipse(200,70,60,60);

  /*PRETTY STARS SECTION (it's all just stars)*/
  
  //drawing stars, moving mouse causes some to brighten or disappear

  fill(255, 255, 255, 220);
  noStroke();
  ellipse(100, 50, 5, 5);
  fill(255, 255, 255, 100-mouseX);
  ellipse(100, 50, 7, 7);

  fill(255, 255, 255, 220+mouseX);
  ellipse(250, 100, 5, 5);
  fill(255, 255, 255, 100+mouseX);
  ellipse(250, 100, 7, 7);

  fill(255, 255, 255, 220-mouseX);
  ellipse(130, 100, 3, 3);
  fill(255, 255, 255, 100-mouseX);
  ellipse(130, 100, 5, 5);

  fill(255, 255, 255, 220+mouseX);
  ellipse(300, 60, 3, 3);
  fill(255, 255, 255, 100+mouseX);
  ellipse(300, 60, 5, 5);

  fill(255, 255, 255, 220+mouseX);
  ellipse(280, 120, 5, 5);
  fill(255, 255, 255, 100-mouseX);
  ellipse(280, 120, 7, 7);
  
  fill(255, 255, 255, 220-mouseX);
  ellipse(150, 70, 3, 3);
  fill(255, 255, 255, 100+mouseX);
  ellipse(150, 70, 6, 6);

  fill(255, 255, 255, 220-mouseX);
  ellipse(260, 60, 3, 3);
  fill(255, 255, 255, 100-mouseX);
  ellipse(260, 60, 6, 6);
    
  /* FRAMED MOUSE PHOTO IN THE CORNER*/
  
  //Frame's background
  fill(255);
  rect(0, 20, 46, 56);
  fill(150);
  rect(5, 25, 36, 46);
  noStroke();
  
  //Framed mouse's body
  fill(0);
  ellipse(20, 58, 30, 25);
  
  //Framed mouse's head
  fill(20);
  ellipse(20, 40, 20, 20);
  fill(255);
  
  //Framed mouse's ears
  ellipse(13, 30, 5, 5);
  ellipse(28, 30, 5, 5);
  
  //Framed mouse's eyes
  ellipse(15+(mouseX*0.01), 40, 3, 3);
  ellipse(23+(mouseX*0.01), 40, 3, 3);
  
  //Framed mouse's nose
  ellipse(20,47,2,2);

  /* THE ACTUAL CAT SECTION*/
  
  //Tail, uses frame count plus sin functions to make it move
  noFill();
  stroke(150);
  strokeWeight(5);
  curve(sin(frameCount*0.05)*200, 150, 200, 100, 180, 200, sin(frameCount*0.05)*150, 240);

  //Cat's body
  noStroke();
  fill(85);
  ellipse(200+(mouseX*0.01), 200+(mouseY*0.01), 70, 70);
  fill(90);
  ellipse(200, 210, 60, 50);

  //Cat's ears
  
  //Right ear
  fill(35);
  triangle(207+(mouseX*0.01), 200, 227+(mouseX*0.01), 185, 230+(mouseX*0.01), 215);
  fill(252, 176, 212);
  triangle(205+(mouseX*0.01), 210, 225+(mouseX*0.01), 190, 226+(mouseX*0.01), 215);

  //Left ear
  fill(35);
  triangle(170+(mouseX*0.01), 215, 177.5+(mouseX*0.01), 184, 205+(mouseX*0.01), 210);
  fill(252, 176, 212);
  triangle(174+(mouseX*0.01), 213, 178.5+(mouseX*0.01), 190, 195+(mouseX*0.01), 210);

  //Cat's Head
  noStroke();
  fill(90);
  ellipseMode(CENTER);
  ellipse(200+(mouseX*0.01), 220, 67, 48);

  //The cat's unique marking
  fill(255);
  ellipse(200+(mouseX*0.01), 205, 20, 15);
  fill(30);
  ellipse(205+(mouseX*0.01), 205, 10, 5);
  fill(255);

  //Cat snout
  ellipse(200+(mouseX*0.02), 230, 15, 15);

  //The cat's eyes
  ellipse(180+(mouseX*0.03), 225, 7, 7);
  ellipse(210+(mouseX*0.03), 225, 7, 7);

  //Cat's eye-brows (for the expressions)
  ellipse(215+(mouseX*0.02), 220, 15, 5);
  ellipse(185+(mouseX*0.02), 220, 15, 5);

  //Cat's mouth
  strokeWeight(1);
  stroke(0);
  line(200+(mouseX*0.02), 230, 203+(mouseX*0.02), 233);
  line(200+(mouseX*0.02), 230, 197+(mouseX*0.02), 233);

  //Cat's nose
  fill(0);
  triangle(197+(mouseX*0.02), 227, 200+(mouseX*0.02), 230, 203+(mouseX*0.02), 227);

  //CAT WHISKERS
  line(205+(mouseX*0.02), 230, 213+(mouseX*0.02), 235);
  line(205+(mouseX*0.02), 230, 215+(mouseX*0.02), 230);
  line(195+(mouseX*0.02), 230, 187+(mouseX*0.02), 235);
  line(195+(mouseX*0.02), 230, 185+(mouseX*0.02), 230);  

  //CAT PAWS
  fill(255);
  noStroke();
  ellipse(225+(mouseX*0.01), 240, 20, 15);
  ellipse(175+(mouseX*0.01), 240, 20, 15);

  /* MOUSE SECTION */

  //Shadow under mouse
  fill(100);
  ellipse(mouseX, 310, 30, 20);

  //Toy Mouse body
  fill(255);
  ellipse(mouseX, 300, 25, 35);
  
  //Toy Mouse ears
  fill(150);
  ellipse(mouseX+10, 290, 6, 5);
  ellipse(mouseX-10, 290, 6, 5);
  
  //Toy Mouse eyes
  ellipse(mouseX-6, 287, 2, 2);
  ellipse(mouseX+6, 287, 2, 2);
  
  //Toy Mouse tail
  curve(mouseX+20, 280, mouseX+10, 320, mouseX, 310, mouseX+30, 400);

  //Fireflies in the background, adds a little touch of beauty, framecount and sin functions used to make them move
  fill(255);
  ellipse(130+(frameCount % 200), 91 + sin(frameCount * 0.03) * 30, 4, 4);
  fill(255, 255, 255, 30);
  ellipse(130+(frameCount % 200), 91 + sin(frameCount * 0.03) * 32, 20 + cos(frameCount*0.03), 20 + cos(frameCount*0.03));

  fill(255);
  ellipse(90 + (frameCount * 0.95 % 240), 80 + cos(frameCount * 0.02) * 32, 4, 4);
  fill(255, 255, 255, 30);
  ellipse(90 + (frameCount * 0.95 % 240), 80 + cos(frameCount * 0.02) * 32, 20 + cos(frameCount), 20 + cos(frameCount));

  fill(255);
  ellipse(100 + (frameCount * 0.95 % 200), 80 + cos(frameCount * 0.04) * 32, 4, 4);
  fill(255, 255, 255, 30);
  ellipse(100 + (frameCount * 0.95 % 200), 80 + cos(frameCount * 0.04) * 32, 20 + cos(frameCount), 20 + cos(frameCount));
}
/*
  When you press the mouse, the mouse squeeks, causing the cat to be surprised!
*/
void mousePressed() 
{
  //holds the expression of the cat for a bit
  frameRate(3);
  println("squeek!");
  
  //hides the original expression
  fill(90);
  ellipse(215+(mouseX*0.02), 220, 17, 7);  
  ellipse(185+(mouseX*0.02), 220, 17, 7);

  //replaces the expression with a surprised one
  fill(255);
  ellipse(215+(mouseX*0.02), 215, 15, 5);
  ellipse(185+(mouseX*0.02), 215, 15, 5);

  ellipse(180+(mouseX*0.03), 225, 6, 6);
  ellipse(210+(mouseX*0.03), 225, 6, 6);

  //adds an exclamation mark, to show some surprise
  fill(255, 0, 0);
  ellipse(155, 220, 10, 25);
  ellipse(155, 240, 5, 5);
}

//The mouse switches colours with the one in the picture. Cat is suspicous...

void keyPressed()
{
  //holds the expression of the cat and the mouse's colour change before changing it back
  frameRate(2);
  
  //mouse changes to a black mouse
  fill(0);
  ellipse(mouseX, 300, 25, 35);
  fill(255);
  ellipse(mouseX+10, 290, 6, 5);
  ellipse(mouseX-10, 290, 6, 5);
  ellipse(mouseX-6, 287, 2, 2);
  ellipse(mouseX+6, 287, 2, 2);
  curve(mouseX+20, 280, mouseX+10, 320, mouseX, 310, mouseX+30, 400);
  
  //pictured mouse switches to a white mouse
  noStroke();
  fill(220);
  ellipse(20, 58, 30, 25);
  fill(255);
  ellipse(20, 40, 20, 20);
  fill(150);
  ellipse(13, 30, 5, 5);
  ellipse(28, 30, 5, 5);
  ellipse(16+(mouseX*0.01), 40, 3, 3);
  ellipse(23+(mouseX*0.01), 40, 3, 3);
  ellipse(20,47,2,2);
  
  //hiding the old expression by filling it in
  fill(90);
  ellipse(215+(mouseX*0.02), 220, 17, 7);  
  ellipse(185+(mouseX*0.02), 220, 17, 7);
  ellipse(180+(mouseX*0.03), 225, 8, 8);
  ellipse(210+(mouseX*0.03), 225, 8, 8);

  //the change in the Cat's expression (more suspicous)
  fill(255);
  ellipse(215+(mouseX*0.02), 222, 15, 5);
  ellipse(185+(mouseX*0.02), 222, 15, 5);

  ellipse(180+(mouseX*0.03), 225, 3, 3);
  ellipse(210+(mouseX*0.03), 225, 3, 3);
  
  println("...");
}