見出し画像

generativeart_038

// 作品概要:
// Zendoodle
// (C)2024 sakuzo_arts

// Global変数
String APPNAME = "generativeart_038";

// セットアップ
void setup() {
  size(800, 800);
  noLoop();
}


// 描画
void draw() {
  // 背景色設定
  background(0, 0, 0);
  noFill();
  noStroke();
  
  // 描画処理
  drawpPttern(8);
  
  // フッター表示
  drawFooter();
}

// パターンを描画する関数
void drawpPttern(int PIECE_NUMBER){

  for(int i = 0; i < PIECE_NUMBER + 1; i = i + 1){
    for(int j = 0; j < PIECE_NUMBER + 1; j = j + 1){
      float PIECE_WIDTH = width/PIECE_NUMBER;
      float PIECE_HEIGHT = height/PIECE_NUMBER;
      float PIECE_CORNER_R = 20;
      float CORNER_X = PIECE_WIDTH  * i;
      float CORNER_Y = PIECE_HEIGHT * j;
      
      // 四角ピース
      strokeWeight(0.5);
      stroke(64, 64, 64);
      fill(255, 255, 255);
      rect(CORNER_X, CORNER_Y, PIECE_WIDTH, PIECE_HEIGHT, PIECE_CORNER_R);
      
      // 渦巻き
      fill(64, 64, 64);
      noStroke();
      float R = 3;
      float k = 0;
      float PIECE_CENTER_X = CORNER_X + PIECE_WIDTH / 2;
      float PIECE_CENTER_Y = CORNER_Y + PIECE_HEIGHT / 2;
      while(true){
        if(R * 2 < PIECE_WIDTH){
          float CIRCUMFRENCE_X = PIECE_CENTER_X + R * cos(radians(k));
          float CIRCUMFRENCE_Y = PIECE_CENTER_Y + R * sin(radians(k));
          circle(CIRCUMFRENCE_X, CIRCUMFRENCE_Y, 2);
        } else {
          break;
        }
        R = R + 0.1;
        k = k + 2;
      }
      
      // 交点の円
      noStroke();
      fill(255, 255, 255);
      circle(CORNER_X, CORNER_Y, 10);
    }
  }
  

}

// フッターを表示する関数
void drawFooter(){
  // 長方形の描画方法をデフォルトに戻す
  rectMode(CORNER);

  // 長方形を背景として描画する
  noStroke();
  fill(255, 255, 255, 192);
  rect(0, height - 45, width, 45);

  // 作品名
  textAlign(LEFT, BOTTOM);
  textSize(20);
  fill(64);
  text(APPNAME, 30, height - 10);
  
  // 著作権表示
  textAlign(RIGHT, BOTTOM);
  textSize(20);
  fill(64);
  text("(C)2024 sakuzo_arts", width - 30, height - 10);
}

// キー操作でイベントを実行する関数
void keyPressed(){
  // スペースキーを押下で再描画
  if(key == ' '){
    redraw();
  }
  
  // Shift+sキーを押下で画像保存
  if(key == 'S'){
    int Y = year();
    int M = month();
    int D = day();
    int h = hour();
    int m = minute();
    int s = second();
    String FILENAME = APPNAME + "-" + Y + nf(M, 2) + nf(D, 2) + nf(h, 2) + nf(m, 2) + nf(s, 2);
    saveFrame(FILENAME + ".png");
  }
}

この記事が気に入ったらサポートをしてみませんか?