Week 05 / Interactive Video





BRUSHING MY TEETH


PImage face;
PImage face2;
PImage bubble1;
PImage bubble2;
PImage toothbrush;
PImage toothbrush2;
int toothbrushX = 300;
int toothbrushY = 1150;
int toothbrush2X = 300;
int toothbrush2Y = 400;
int bubbleX = 100;
int bubbleY = 1200;
int bubble2X = 70;
int bubble2Y = 300;

void setup () {
  size (700, 500);
  face = loadImage("face.png");
  face2 = loadImage("face2.png");
  bubble1 = loadImage("bubble1.png");
  bubble2 = loadImage("bubble2.png");
  toothbrush = loadImage("toothbrush.png");
  toothbrush2 = loadImage("toothbrush2.png");
}

void draw () {
  image(face, 0, 0);

  if (mousePressed==true) {
    image(face2, 0, 0);}
   
  if (keyPressed) {
    if (keyCode==LEFT) {
      pushMatrix();
      scale(0.2);
      image(bubble1, bubbleX, bubbleY);
      popMatrix();
      pushMatrix();
      scale(0.3);
      image(toothbrush, toothbrushX, toothbrushY);
      popMatrix();
      toothbrushX-= 5;
      bubbleX-=7;}
    if (keyCode==RIGHT) {
      pushMatrix();
      scale(0.2);
      image(bubble1, bubbleX, bubbleY);
      popMatrix();
      pushMatrix();
      scale(0.3);
      image(toothbrush, toothbrushX, toothbrushY);
      popMatrix();
      toothbrushX+= 5;
      bubbleX+=7;}
      if (toothbrushX > 1600) {toothbrushX = 1600;}
      if (toothbrushX < 300) {toothbrushX = 300;}
      if (bubbleX > 1900) {bubbleX = 1900;}
      if (bubbleX < 100) {bubbleX = 100;}
    if(keyCode==DOWN) {
      pushMatrix();
      scale(0.2);
      image(bubble2, bubble2X, bubble2Y);
      popMatrix();
      pushMatrix();
      scale(0.3);
      image(toothbrush2, toothbrush2X, toothbrush2Y);
      popMatrix();
      toothbrush2X+= 12;
      bubble2X+= 18;}
    if(keyCode==UP) {
      pushMatrix();
      scale(0.2);
      image(bubble2, bubble2X, bubble2Y);
      popMatrix();
      pushMatrix();
      scale(0.3);
      image(toothbrush2, toothbrush2X, toothbrush2Y);
      popMatrix();}
      toothbrush2X-= 8;
      bubble2X-= 12;}
      if (toothbrush2X > 1600) {toothbrush2X = 1600;}
      if (toothbrush2X < 300) {toothbrush2X = 300;}
      if (bubble2X < 70) {bubble2X = 70;}
      if (bubble2X > 2100) {bubble2X = 2100;}

덧글

댓글 입력 영역