BioErrorLog Tech Blog

試行錯誤の記録

Generative Art #4 - Processing作品

おはよう。@bioerrorlogです。

ProcessingによるGenerative Art作品
4作目を記録します。

自作品まとめはこちら: www.bioerrorlog.work

Output

f:id:BioErrorLog:20191212081809p:plain f:id:BioErrorLog:20191212081801p:plain

フル解像度/その他出力パターンはこちら:
Generative_4 - BioErrorLog - pixiv


Material

使用言語: Processing 3.5.3

Processingというプログラミング言語に聞き覚えがない、という方は是非こちらをご参考ください:
www.bioerrorlog.work


Source Code

GitHubはこちら

import processing.opengl.*;

int _radius = 400;

void setup(){
  size(1920, 1080, OPENGL); // OPENGLで3D描画
  background(255);
  stroke(0, 10);
  strokeWeight(0.01);
}


void draw(){
  /*
  3次元の球体をぐるぐる回転
  sinやconを利用した線の描画を薄く重ねる
  */

  translate(width/2, height/2, 0); // 出力範囲の中心を描画位置にする
  rotateX(frameCount * 0.04);
  rotateY(frameCount * 0.04);
  
  float s = 0;
  float t = 0;
  float lastX = 0;
  float lastY = 0;
  float lastZ = 0;

  while ( t < 180){ // OUTPUT1枚目はwhile条件 t<90
    s += 18;
    t += 1;
    float radianS = radians(s);
    float radianT = radians(t);
    
    float thisX = _radius * cos(radianS) * sin(radianT); // ここら辺を変えると多様なパターンが見られる
    float thisY = _radius * sin(radianS) * sin(radianT);
    float thisZ = _radius * cos(radianT);
    
    if (lastX != 0){
      line(thisX, thisY, thisZ, lastX, lastY, lastZ);
    }
    lastX = thisX;
    lastY = thisY;
    lastZ = thisZ;
  }
}


void keyPressed(){
  /*
  ENTERキー押下: 画像を保存する
  BACKSPACEキー押下: setup()を呼んでモデルをリセットする
  */

  if (keyCode == ENTER){
    saveFrame("generative_4_####.png");
  }
  if (keyCode == BACKSPACE){
    setup();
  }
}

Discussion

はじめての3D描画をOpenGLを用いて行いました。
sinやcosを利用して線を薄く重ねることで、綺麗なパターンが現れてきます。

OUTPUTの1枚目は各フレーム90度の球体の回転、2枚目は180度の回転を加えています。

私は1枚目のほうが、立体感が感じられて好きです。


See also

www.bioerrorlog.work

www.bioerrorlog.work

www.bioerrorlog.work

Reference