【Processing】門・開・閉

 

漢字をマウスクリックで動かす。

「門」と「開」と「閉」の意味に動きをつけた。

if(  ){ }else if( ){  }が便利だった。

 

float l = 230;
float r = 280;

void setup(){
  size(500,500);
}


void draw(){

  background(255);
  strokeWeight(45);
  stroke(200);
  line(l,100,l,230);
  line(l-150,100,l-150,400);
  line(l,100,l-150,100);  
  line(l,165,l-150,165);  
  line(l,230,l-150,230);    
  
  line(r,100,r,230);
  line(r+150,100,r+150,400);  
  line(r,100,r+150,100);  
  line(r,165,r+150,165);  
  line(r,230,r+150,230); 
  line(r+150-30,400-30,r+150,400); 

if(mousePressed == true){
  l-=1.5;
  r+=1.5;
  open();
}else if( l < 230 || r > 280  ){
  l++;
  r--;
  close();
}
}

void open(){
  stroke(#FC800A);
  line(180,280,320,280);
  line(180,330,320,330);
  line(200,280,200,400);
  line(300,280,300,400);
}

void close(){
  stroke(#9AFF05);

  line(180,300,320,300);
  line(280,280,280,400);
  line(280,300,180,380);
}