generative art. list3-11

今朝のprocessing.

lineにrandomnessを加える.
my random関数を使う.
list3-11

f:id:ksumiya0318:20160928102806p:plain

void setup () {
  size(500,100);
  background(255);
  strokeWeight(5);
  smooth();
  
  int xmin = 20;
  int xmax = width - xmin;
  float ymin = 10;
  float ymax = height - xmin;
  float ycenter = height/2;
  stroke(0, 30);
  line(xmin, ycenter, xmax, ycenter);
  
  stroke(0);
  
  int xstep = 5;
  float dummy = -999;
  float lastx = dummy;
  float lasty = dummy;
  float y;
  float angle = 0;
  float rad;
  for (int x = xmin; x <= xmax; x += xstep) {
    rad = radians(angle);
    y = ymin + myRandom()*(ymax - ymin);
    if (lastx > dummy) {
      line(x, y, lastx, lasty);
    }
    lastx = x;
    lasty = y;
    angle++;
  }
  saveFrame("img.png");
}

float myRandom () {
 float val = 1 - pow(random(1), 5);
 return val;
}

次は円です.