generativeart_037
// 作品概要:
// 黒板の落書き
// (C)2023 sakuzo_arts
// Global変数
String APPNAME = "generativeart_037";
// セットアップ
void setup() {
size(800, 800);
noLoop();
}
// 描画
void draw() {
// 背景色設定
background(32, 64, 64);
noFill();
noStroke();
// 描画処理
drawpPttern(10);
// フッター表示
drawFooter();
}
// 円をを描画する関数
void drawpPttern(int LINE_NUMBER){
for(int i = 0; i < LINE_NUMBER + 1; i = i + 1){
for(int j = 0; j < LINE_NUMBER + 1; j = j + 1){
float PIECE_WIDTH = width/LINE_NUMBER;
float PIECE_HEIGHT = height/LINE_NUMBER;
float CORNER_A_X = PIECE_WIDTH * i;
float CORNER_A_Y = PIECE_HEIGHT * j;
float CORNER_B_X = PIECE_WIDTH * i;
float CORNER_B_Y = PIECE_HEIGHT * (j + 1);
float CORNER_C_X = PIECE_WIDTH * (i + 1);
float CORNER_C_Y = PIECE_HEIGHT * (j + 1);
float CORNER_D_X = PIECE_WIDTH * (i + 1);
float CORNER_D_Y = PIECE_HEIGHT * j;
color LINE_COLOR[] = { color(255, 255, 255, 192),
color(255, 255, 146, 192),
color(247, 171, 173, 192),
color(126, 203, 220, 192)};
int SHAPE_TYPE = (int)random(5);
switch(SHAPE_TYPE){
case 0:
// 四角形描画
stroke(LINE_COLOR[(int)random(4)]);
int RECT_TYPE = (int)random(5);
strokeWeight(random(5, 10));
strokeCap(SQUARE);
switch(RECT_TYPE){
case 0:
// ヨコ縞
for(int k = 0; k < 5; k = k + 1){
for(int m = 0; m < PIECE_WIDTH; m = m + 15){
line(CORNER_A_X, CORNER_A_Y + m + random(-5, 5), CORNER_D_X, CORNER_D_Y + random(-5, 5) + m);
}
}
break;
case 1:
// タテ縞
for(int k = 0; k < 5; k = k + 1){
for(int m = 0; m < PIECE_WIDTH; m = m + 15){
line(CORNER_A_X + m + random(-5, 5), CORNER_A_Y, CORNER_B_X + random(-5, 5) + m, CORNER_B_Y);
}
}
break;
default:
// 四角形
rect(CORNER_A_X + random(-5, 5), CORNER_A_Y + random(-5, 5), PIECE_WIDTH, PIECE_HEIGHT);
}
break;
case 1:
// 円描画
stroke(LINE_COLOR[(int)random(4)]);
for(int k = 0; k < 5; k = k + 1){
strokeWeight(random(5));
circle(CORNER_A_X + PIECE_WIDTH / 2 + random(-5, 5), CORNER_A_Y + PIECE_HEIGHT / 2 + random(-5, 5), PIECE_WIDTH);
}
break;
case 2:
// 直角三角形を描画
stroke(LINE_COLOR[(int)random(4)]);
for(int k = 0; k < 5; k = k + 1){
strokeWeight(random(5));
beginShape();
vertex(CORNER_A_X + random(-5, 5), CORNER_A_Y + random(-5, 5));
vertex(CORNER_B_X + random(-5, 5), CORNER_B_Y + random(-5, 5));
vertex(CORNER_C_X + random(-5, 5), CORNER_C_Y + random(-5, 5));
endShape(CLOSE);
}
break;
case 3:
// 二等辺三角形を描画
stroke(LINE_COLOR[(int)random(4)]);
for(int k = 0; k < 5; k = k + 1){
strokeWeight(random(5));
beginShape();
vertex(CORNER_A_X + PIECE_WIDTH / 2 + random(-5, 5), CORNER_A_Y + random(-5, 5));
vertex(CORNER_B_X + random(-5, 5), CORNER_B_Y + random(-5, 5));
vertex(CORNER_C_X + random(-5, 5), CORNER_C_Y + random(-5, 5));
endShape(CLOSE);
}
break;
case 4:
// ひし形を描画
stroke(LINE_COLOR[(int)random(4)]);
for(int k = 0; k < 5; k = k + 1){
strokeWeight(random(5));
beginShape();
vertex(CORNER_A_X + PIECE_WIDTH / 2 + random(-5, 5), CORNER_A_Y + random(-5, 5));
vertex(CORNER_A_X + random(-5, 5), CORNER_A_Y + PIECE_HEIGHT / 2 + random(-5, 5));
vertex(CORNER_A_X + PIECE_WIDTH / 2 + random(-5, 5), CORNER_A_Y + PIECE_HEIGHT + random(-5, 5));
vertex(CORNER_A_X + PIECE_WIDTH + random(-5, 5), CORNER_B_Y - PIECE_HEIGHT / 2 + random(-5, 5));
endShape(CLOSE);
}
break;
default:
}
}
}
}
// フッターを表示する関数
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");
}
}
この記事が気に入ったらサポートをしてみませんか?