ギンの備忘録

デジタルアートやプログラミングやテクノロジー関連のこと。

4章-円を描く間違った方法「ジェネラティブ・アートーProcessingによる実践ガイド」

「ジェネラティブ・アートーProcessingによる実践ガイド」の4章「円を描く間違った方法」を実践しました。 三角関数を用いて円を描くところから始まり、ノイズを加えた円描きます。 最後には線分を用いて中心、半径、回転角にノイズを加えて描く「Wave Clock」を実行します。

参考書の図4.2~図4.15までを手元で再現した結果になります。 表示される図と実行したソースコードを下に載せておきます。 乱数を使うコードは、ランダム性があるので完全一致はしませんが、目的としている表現はできました。

図4.2

f:id:gin_graphic:20200914200110p:plain

ソースコード
void setup(){
   size(500, 300);
   background(255);
   strokeWeight(5);
   smooth();

   float radius = 100;
   int centx = 250;
   int centy = 150;
   
   stroke(0, 30);
   noFill();
   ellipse(centx,centy,radius*2,radius*2);
   
   stroke(20, 50, 70);
   float x,y;
   float lastx = -999;
   float lasty = -999;
   for(float ang=0; ang<=360; ang+=5){
     float rad = radians(ang);
     x = centx + (radius * cos(rad));
     y = centy + (radius * sin(rad));
     point(x,y);
   }
}

図4.3

f:id:gin_graphic:20200914200114p:plain

ソースコード
void setup(){
   size(500, 300);
   background(255);
   strokeWeight(5);
   smooth();

   float radius = 100;
   int centx = 250;
   int centy = 150;
   
   stroke(0, 30);
   noFill();
   ellipse(centx,centy,radius*2,radius*2);
   
   stroke(20, 50, 70);
   float x,y;
   float lastx = -999;
   float lasty = -999;
   for(float ang=0; ang<=360; ang+=5){
     float rad = radians(ang);
     x = centx + (radius * cos(rad));
     y = centy + (radius * sin(rad));
     point(x,y);
   }
}

図4.4

f:id:gin_graphic:20200914200122p:plain

ソースコード
void setup(){
   size(500, 300);
   background(255);
   strokeWeight(5);
   smooth();

   float radius = 100;
   int centx = 250;
   int centy = 150;
   
   stroke(0, 30);
   noFill();
   ellipse(centx,centy,radius*2,radius*2);
   
   radius = 10;
   stroke(20, 50, 70);
   float x,y;
   float lastx = -999;
   float lasty = -999;
   float radiusNoise = random(10);
   for(float ang=0; ang<=1440; ang+=5){
     radiusNoise += 0.05;
     radius += 0.5;
     float thisRadius = radius + (noise(radiusNoise) * 200) - 100;
     float rad = radians(ang);
     x = centx + (thisRadius * cos(rad));
     y = centy + (thisRadius * sin(rad));
     if(lastx > -999){
       line(x,y,lastx,lasty);
     }
     lastx = x;
     lasty = y;
   }
}

図4.5

f:id:gin_graphic:20200914200126p:plain

ソースコード
void setup(){
   size(500, 300);
   background(255);
   strokeWeight(0.5);
   smooth();

   int centx = 250;
   int centy = 150;
   
   float x,y;
   
   for(int i=0;i<100;i++){
     float radius = 10;
     float lastx = -999;
     float lasty = -999;
     float radiusNoise = random(10);
     stroke(random(20), random(50), random(70), 80);
     
     int startangle = int(random(360));
     int endangle = 1440 + int(random(1440));
     int anglestep = 5 + int(random(3));
     
     for(float ang=startangle; ang<=endangle; ang+=anglestep){
       radiusNoise += 0.05;
       radius += 0.5;
       float thisRadius = radius + (noise(radiusNoise) * 200) - 100;
       float rad = radians(ang);
       x = centx + (thisRadius * cos(rad));
       y = centy + (thisRadius * sin(rad));
       if(lastx > -999){
         line(x,y,lastx,lasty);
       }
       lastx = x;
       lasty = y;
     }
   }
}

図4.7

f:id:gin_graphic:20200914200130p:plain

ソースコード
void setup(){
   size(500, 300);
   background(255);
   strokeWeight(1);
   smooth();

   float radius = 100;
   int centx = 250;
   int centy = 150;
   
   stroke(0, 30);
   noFill();
   ellipse(centx,centy,radius*2,radius*2);
   
   stroke(20, 50, 70);
   float x,y;
   float noiseval = random(10);
   float radVariance, thisRadius, rad;
   beginShape();
   fill(20, 50, 70, 50);
   for(float ang=0; ang<=360; ang+=1){
     noiseval += 0.1;
     radVariance = 30 * customNoise(noiseval);
     
     thisRadius = radius + radVariance;
     rad = radians(ang);
     x = centx + (thisRadius * cos(rad));
     y = centy + (thisRadius * sin(rad));
     
     curveVertex(x, y);
   }
   endShape();
}

図4.8

f:id:gin_graphic:20200914200134p:plain

ソースコード
void setup(){
   size(500, 300);
   background(255);
   strokeWeight(1);
   smooth();

   float radius = 100;
   int centx = 250;
   int centy = 150;
   
   stroke(0, 30);
   noFill();
   ellipse(centx,centy,radius*2,radius*2);
   
   stroke(20, 50, 70);
   float x,y;
   float noiseval = random(10);
   float radVariance, thisRadius, rad;
   beginShape();
   fill(20, 50, 70, 50);
   for(float ang=0; ang<=360; ang+=1){
     noiseval += 0.1;
     radVariance = 30 * customNoise(noiseval);
     
     thisRadius = radius + radVariance;
     rad = radians(ang);
     x = centx + (thisRadius * cos(rad));
     y = centy + (thisRadius * sin(rad));
     
     curveVertex(x, y);
   }
   endShape();
}

図4.11

f:id:gin_graphic:20200914200138p:plain

ソースコード
float _xnoise, _ynoise;
float _angle = -PI/2;
float _radius;

void setup(){
   size(500, 300);
   background(255);
   frameRate(30);
   smooth();
   noFill();
}

void draw(){
   _radius = 100;
   _angle += 1;
   if(_angle > 360){_angle -= 360;}
   if(_angle < 0){_angle += 360;}
   
   float centerx = width/2;
   float centery = height/2;
   
   float rad = radians(_angle);
   float x1 = centerx + (_radius * cos(rad));
   float y1 = centery + (_radius * sin(rad));
   
   float opprad = rad + PI ;
   float x2 = centerx + (_radius * cos(opprad));
   float y2 = centery + (_radius * sin(opprad));
   
   stroke(0, 60);
   strokeWeight(1);
   line(x1, y1, x2, y2);
}

図4.12

f:id:gin_graphic:20200914200142p:plain

ソースコード
float _xnoise, _ynoise;
float _angle = -PI/2;
float _radius;
float _strokeCol = 254;
int _strokeChange = -1;

void setup(){
   size(500, 300);
   background(255);
   frameRate(30);
   smooth();
   noFill();
}

void draw(){
   _radius = 100;
   _angle += 1;
   if(_angle > 360){_angle -= 360;}
   if(_angle < 0){_angle += 360;}
   
   float centerx = width/2;
   float centery = height/2;
   
   float rad = radians(_angle);
   float x1 = centerx + (_radius * cos(rad));
   float y1 = centery + (_radius * sin(rad));
   
   float opprad = rad + PI ;
   float x2 = centerx + (_radius * cos(opprad));
   float y2 = centery + (_radius * sin(opprad));
   
   _strokeCol += _strokeChange;
   if(_strokeCol > 254){_strokeChange = -1;}
   if(_strokeCol < 0){_strokeChange = 1;}
   stroke(_strokeCol, 60);
   strokeWeight(1);
   line(x1, y1, x2, y2);
}

図4.13

f:id:gin_graphic:20200914200145p:plain

ソースコード
float _radiusnoise;
float _xnoise, _ynoise;
float _angle = -PI/2;
float _radius;
float _strokeCol = 254;
int _strokeChange = -1;

void setup(){
   size(500, 300);
   background(255);
   frameRate(30);
   smooth();
   noFill();
   
   _radiusnoise = random(10);
}

void draw(){
   _radiusnoise += 0.005;
   _radius = (noise(_radiusnoise) * 550) + 1;
   _angle += 1;
   if(_angle > 360){_angle -= 360;}
   if(_angle < 0){_angle += 360;}
   
   float centerx = width/2;
   float centery = height/2;
   
   float rad = radians(_angle);
   float x1 = centerx + (_radius * cos(rad));
   float y1 = centery + (_radius * sin(rad));
   
   float opprad = rad + PI ;
   float x2 = centerx + (_radius * cos(opprad));
   float y2 = centery + (_radius * sin(opprad));
   
   _strokeCol += _strokeChange;
   if(_strokeCol > 254){_strokeChange = -1;}
   if(_strokeCol < 0){_strokeChange = 1;}
   stroke(_strokeCol, 60);
   strokeWeight(1);
   line(x1, y1, x2, y2);
}

図4.14

f:id:gin_graphic:20200914200149p:plain

ソースコード
float _angnoise, _radiusnoise;
float _xnoise, _ynoise;
float _angle = -PI/2;
float _radius;
float _strokeCol = 254;
int _strokeChange = -1;

void setup(){
   size(500, 300);
   background(255);
   frameRate(30);
   smooth();
   noFill();

   _angnoise = random(10);
   _radiusnoise = random(10);
}

void draw(){
   _radiusnoise += 0.005;
   _radius = (noise(_radiusnoise) * 550) + 1;
   _angnoise += 0.005;
   _angle += (noise(_angnoise) * 6) - 3;
   if(_angle > 360){_angle -= 360;}
   if(_angle < 0){_angle += 360;}
   
   float centerx = width/2;
   float centery = height/2;
   
   float rad = radians(_angle);
   float x1 = centerx + (_radius * cos(rad));
   float y1 = centery + (_radius * sin(rad));
   
   float opprad = rad + PI ;
   float x2 = centerx + (_radius * cos(opprad));
   float y2 = centery + (_radius * sin(opprad));
   
   _strokeCol += _strokeChange;
   if(_strokeCol > 254){_strokeChange = -1;}
   if(_strokeCol < 0){_strokeChange = 1;}
   stroke(_strokeCol, 60);
   strokeWeight(1);
   line(x1, y1, x2, y2);
}

図4.15

f:id:gin_graphic:20200914200153p:plain

ソースコード
float _angnoise, _radiusnoise;
float _xnoise, _ynoise;
float _angle = -PI/2;
float _radius;
float _strokeCol = 254;
int _strokeChange = -1;


void setup(){
   size(500, 300);
   background(255);
   frameRate(30);
   smooth();
   noFill();

   _angnoise = random(10);
   _radiusnoise = random(10);
   _xnoise = random(10);
   _ynoise = random(10);
}

void draw(){
   _radiusnoise += 0.005;
   _radius = (noise(_radiusnoise) * 550) + 1;
   _angnoise += 0.005;
   _angle += (noise(_angnoise) * 6) - 3;
   if(_angle > 360){_angle -= 360;}
   if(_angle < 0){_angle += 360;}
   
   _xnoise += 0.01;
   _ynoise += 0.01;
   float centerx = width/2 + (noise(_xnoise) * 100) - 50;
   float centery = height/2 + (noise(_ynoise) * 100) - 50;
   
   float rad = radians(_angle);
   float x1 = centerx + (_radius * cos(rad));
   float y1 = centery + (_radius * sin(rad));
   
   float opprad = rad + PI ;
   float x2 = centerx + (_radius * cos(opprad));
   float y2 = centery + (_radius * sin(opprad));
   
   _strokeCol += _strokeChange;
   if(_strokeCol > 254){_strokeChange = -1;}
   if(_strokeCol < 0){_strokeChange = 1;}
   stroke(_strokeCol, 60);
   strokeWeight(1);
   line(x1, y1, x2, y2);
}