読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

ずれた格子

インタラクション ランダム
/**
* Unshaped Lattice
*
* @author aa_debdeb
* @date 2016/02/21
*/


float noiseX, noiseY;

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

void draw(){

}

void mousePressed(){
  
  color bgColor = color(random(255), random(255), random(255));
  color stColor = color(random(255), random(255), random(255));
  int pointNum = 10;
  float pointWidth = 40;  
  noiseX = random(100);
  noiseY = random(100);
  PVector[][] points = new PVector[pointNum + 1][pointNum + 1];

  
  for(int h = 0; h <= pointNum; h++){
    for(int w = 0; w <= pointNum; w++){
      float x = 50 + w * pointWidth;
      float y = 50 + h * pointWidth;
      if(noise(noiseX + x * 0.05, noiseY + y * 0.05) < 0.45){ // for javascript mode
      //if(noise(noiseX + x * 0.05, noiseY + y * 0.05) < 0.3){ // for java mode
        x += map(random(1), 0, 1, -(pointWidth * 0.8) / 2, (pointWidth * 0.8) / 2);
        y += map(random(1), 0, 1, -(pointWidth * 0.8) / 2, (pointWidth * 0.8) / 2);
      }
      points[h][w] = new PVector(x, y);
    }
  }
  
  background(bgColor);
  stroke(stColor);
  strokeWeight(3);
  for(int h = 0; h <= pointNum; h++){
    for(int w = 0; w <= pointNum; w++){
      if(w != pointNum){
        line(points[h][w].x, points[h][w].y, points[h][w + 1].x, points[h][w + 1].y);
      }
      if(w != 0 && h != pointNum){
        line(points[h][w].x, points[h][w].y, points[h + 1][w - 1].x, points[h + 1][w - 1].y);      
      }
      if(h != pointNum){
        line(points[h][w].x, points[h][w].y, points[h + 1][w].x, points[h + 1][w].y);     
      } 
      if(w != pointNum && h != pointNum){
        line(points[h][w].x, points[h][w].y, points[h + 1][w + 1].x, points[h + 1][w + 1].y);   
      }   
    }
  }
  
}