見出し画像

generativeart_028


// 作品概要:
// ランダムに図形を並べる
// (C)2023 sakuzo_arts

// Global変数
String APPNAME = "generativeart_028";
int SHAPE_NUM;  // 描画する図形の数

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

// 描画
void draw() {
  background(255);

  // 図形を描画
  SHAPE_NUM = 30;
  for (int i = 0; i < SHAPE_NUM; i = i + 1) {
    drawRectangle();
    drawTriangle();
    drawCircle();
  }
  
  // フッター表示
  drawFooter();
}

// 短形を描画する関数
void drawRectangle(){
  // デフォルトの座標軸 (0, 0) をスタックに入れる
  pushMatrix();
  
  float X = random(width);
  float Y = random(height);
  float W = random(100, 300);
  float H = random(100, 300);
  
  translate(X, Y);
  rotate(radians(random(180)));

  noStroke();
  fill(getColor());
  stroke(getColor());
  strokeCap(PROJECT);
  strokeJoin(BEVEL);
  strokeWeight(3);
  rect(0, 0, W, H);
  
  // 座標をリセットする
  popMatrix();
  
}

void drawTriangle(){
  float X1 = random(width);
  float Y1 = random(height);
  float X2 = X1 + random(-300, 300);
  float Y2 = Y1 + random(-300, 300);
  float X3 = X2 + random(-300, 300);
  float Y3 = Y2 + random(-300, 300);
  noStroke();
  fill(getColor());
  stroke(getColor());
  strokeCap(PROJECT);
  strokeJoin(BEVEL);
  strokeWeight(3);
  triangle(X1, Y1, X2, Y2, X3, Y3); 
}

// 円を描画する関数
void drawCircle(){
  float X = random(width);
  float Y = random(height);
  float R = random(50, 200);

  noStroke();
  fill(getColor());
  stroke(getColor());
  strokeWeight(3);
  circle(X, Y, R);
}


// 色を設定する関数
color getColor(){
  
  float COLOR_R = 255;
  float COLOR_G = random(129, 255);
  float COLOR_B = random(0, 128);
  float COLOR_A = 192;
  color COLOR_RGBA = color(COLOR_R, COLOR_G, COLOR_B, COLOR_A);

  return COLOR_RGBA;
}

// フッターを表示する関数
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)2023 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");
  }
}

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