Processing/Processing Study
                
              mouse rollover
                상큼어린이
                 2009. 3. 22. 19:40
              
                          
            
요즘엔 똑같은 비주얼을 얼마나 다르게 코딩을 해볼 수 있을까하고 의문이 들었다.
간단하지만 롤오버코드를 여러가지로 풀어보았다. 어떤게 좋은 코딩인지는 모르겠으나 전부다 똑같이 동작한다.^^
스터디때 했었던 조건문인 IF를 사용한 간단한 예다.
// 변수 사용
int x;
int y;
void setup(){
  size(200, 200);
  noStroke();
}
void draw(){
  background(255);
  fill(0);
  rect(x, y, 100, 100);
  if( 0 < mouseX && 100 > mouseX && 0 < mouseY && 100 > mouseY){
   x = 0;
   y = 0; 
  }else if( 100 < mouseX && 200 > mouseX && 0 < mouseY && 100 > mouseY){
    x = 100;
    y = 0;
  }else if( 0 < mouseX && 100 > mouseX && 100 < mouseY && 200 > mouseY){
    x = 0;
    y= 100;
  }else{
    x = 100;
    y = 100;
  }
}
// 변수 미사용
void setup(){
  size(200, 200);
  noStroke();
}
void draw(){
  background(255);
  if( 100 > mouseX && 100 > mouseY){
    fill(0);
    rect(0, 0, 100, 100);
  }
  else if( 100 < mouseX && 100 > mouseY){
    fill(0);
    rect(100, 0, 100, 100);
  }
  else if( 100 > mouseX && 100 < mouseY){
    fill(0);
    rect(0, 100, 100, 100);
  }
  else if(100 < mouseX && 100 < mouseY){
    fill(0);
    rect(100, 100, 100, 100);
  }
}