top of page

WORK_2

INTERACTIVE VIDEO WITH MOUSE

28   /   03  /   2018

Interactive Video with Mouse

​

​

I want to share my homework, i used some code for make a background's color changed ny click the mouse, and make the circle also the rect move by moved the mouse.

​

Code:

/*Zhafirah Farras Hanifah

2018318090*/

​

float colorR, colorG, colorB;
float spin=0;
void setup() {
  size(500, 500);
  colorR= colorG= colorB=6;
}

/*move the rect*/

void draw() {
  background(colorR, colorG, colorB);
  pushMatrix();
  translate(50, 50);
  fill(0, mouseX, mouseY);
  rect(mouseY, mouseX, 150, 150);
  popMatrix();
  
  fill(0, mouseX, mouseY);
  
  /*ellipse*/
  pushMatrix();
  scale(2, 2);
  ellipse(mouseY, mouseX, 50, 50);
  popMatrix();
  
 /*spin rect*/ 
  pushMatrix();
  spin+=0.0020;
  translate(10, 10);
  rotate(degrees(spin));
  rect(300, 300, 25, 25);
  rect(100, 100, 25, 25);
  popMatrix();
  
}

/*Change Background*/
void mouseClicked() {
  colorR+=random(60, 10); 
  colorG+=random(60, 10); 
  colorB+=random(60, 10);
  if (colorR>250) {
    colorR= random(0, 30);
  }
  if (colorB>250) {
    colorB= random(0, 30);
  }
  if (colorG>250) {
    colorG= random(0, 30);
  }
}

​

Thank You.

bottom of page