見出し画像

Generative Art #153

Code

int[] colors = new int [7];

void setup() {
 size(900, 900);
 pixelDensity(2);
 //noLoop();
}

void draw() {
 newColor();
 
 background(getCol());
 lines();
 
 saveFrame("output/####.png");
 if (frameCount == 60) {
   exit();
 }
}

void lines() {
 for (int i=0; i<180; i++) {
   float w = random(width);
   
   stroke(getCol());
   if (random(1) < 0.5) {
     myLine(w, 0, w, width);
   } else {
     myLine(0, w, width, w);
   }
   
   if (random(1) < 0.3) {
     noStroke();
     fill(getCol());
     circle(random(width), random(width), random(random(random(300))));
   }
 }
}

void myLine(float x1, float y1, float x2, float y2) {
 float c = (abs(x1-x2)+abs(y1-y2))*0.5;
 float ns = random(0.05);
 float px = -1234;
 float py = 0;
 color col = getCol();

 for (int i = 0; i < c; i ++) {
   float x = lerp(x1, x2, i/c);
   float y = lerp(y1, y2, i/c);

   if (px != -1234) {
     strokeWeight(noise(i*ns)*10);
     stroke(col);
     line(px, py, x, y);
   }

   px = x;
   py = y;
 }
 noiseSeed((int)random(100000));
}

void newColor() {
 for (int i = 0; i < colors.length; i ++) {
   colors[i] = color(random(255), random(255), random(255));
 }
}

int getCol() {
 return colors[(int)random(colors.length)];
}

点線を描いてくる関数を作ったので点線を使って何か作ろうとしてたんですけど、気づいたらこうなっていました。

ノイズで線の太さを変えています。


点線はこんな感じに作りました。

void dottedLine(float x1, float y1, float x2, float y2) {
 float c = (abs(x1-x2)+abs(y1-y2))*0.5;

 for (int i = 0; i < c; i ++) {
  float x = lerp(x1, x2, i/c);
   float y = lerp(y1, y2, i/c);
   point(x, y);
 }
}

そのうち君は必要になるだろう。それまで待っていてくれ。


Happy coding!

応援してくださる方!いつでもサポート受け付けてます!