コエンザイムのブログ

ジェネレーティブアートが好きです

Auto Generated Curvesをつくりました

Auto Generated Curvesをつくりました。ジェネレーティブアートです。ランダムなペジェ曲線420本を重ねました。

opensea.io

以下はソースコードです。開発環境はProcessingです。

// Curves
import  java.time.LocalDateTime;
import  java.time.ZoneId;
import  java.time.format.DateTimeFormatter;

final boolean cSAVE_FLG = false;
final int cSAVE_NUM = 20;
final int cSTART_NUM = 80;
final int cDIGIT_NUM = 2;

//// For Logo image size
//final int cMyWidth = 350;
//final int cMyHeight = 350;
//final String cFILE_NAME = "Curves_Logo_";

//// For Featured image size
//final int cMyWidth = 600;
//final int cMyHeight = 400;
//final String cFILE_NAME = "Curves_Featured_";

//// For Banner image size
//final int cMyWidth = 1400;
//final int cMyHeight = 400;
//final String cFILE_NAME = "Curves_Banner_";

// For HD
final int cMyWidth = 1280;
final int cMyHeight = 720;
final String cFILE_NAME = "Curves_";

//// For Full HD
//final int cMyWidth = 1920;
//final int cMyHeight = 1080;
//final String cFILE_NAME = "Curves_";

//// For Test
//final int cMyWidth = 800;
//final int cMyHeight = 450;
//final String cFILE_NAME = "Curves_";

final boolean cLOOP_FLG = true;
final float cFRAME_RATE = 0.3;

void settings() {
  size(cMyWidth, cMyHeight);
}

void setup()
{
  strokeWeight(3);
  noFill();
  colorMode(HSB, 360, 100, 100, 100);
  if (cSAVE_FLG)
  {
    noLoop();
  }
  else if (cLOOP_FLG)
  {
    frameRate(cFRAME_RATE);
  }
  else
  {
    noLoop();
  }
}

void draw()
{
  int loopMax = 1;
  
  if (cSAVE_FLG)
  {
    loopMax = cSAVE_NUM;
  }

  for (int i = 0; i < loopMax; i++)
  {
    myDraw();
    if (cSAVE_FLG)
    {
      LocalDateTime utcDateTime = LocalDateTime.now(ZoneId.of("UTC"));
      DateTimeFormatter dateFrmt = DateTimeFormatter.ofPattern("uuuuMMdd");
      DateTimeFormatter timeFrmt = DateTimeFormatter.ofPattern("HHmmss,SSSSSS");
      String dateStr = dateFrmt.format(utcDateTime);
      String timeStr = timeFrmt.format(utcDateTime);
      //println(cFILE_NAME + nf(cSTART_NUM + i, cDIGIT_NUM)
      //  + "_" + dateStr + "T" + timeStr + "Z" + ".png");
      save(cFILE_NAME + nf(cSTART_NUM + i, cDIGIT_NUM) 
        + "_" + dateStr + "T" + timeStr + "Z" + ".png");
    }
  }
}

void myDraw()
{
  background(random(255));
  float hue = random(360);
  float hue1 = hue;
  float hue2 = int(hue + 327) % 360;
  float hue3 = int(hue + 180) % 360;

  for (int i = 0; i < 420; i++)
  {
    int rand = int(random(10));
    if (rand <= 1)
    {
      hue = hue3;
    }
    else if (rand == 2)
    {
      hue = hue2;
    }
    else
    {
      hue = hue1;
    }
    stroke(hue, random(101), random(33, 97), random(10, 101));
    bezier(random(width), random(height), random(width), random(height), random(width), random(height), random(width), random(height));
  }
}