グリッドの向きをランダムにしてみる
亀の歩み#6
亀の歩みと称して、ジェネラティブアートの練習を投稿しているのですが、今回はグリッドごとに向きをランダムにしてみるをテーマに作品を作ってみました。
グリッドとは縦列に分割したブロックのことで、この方向をランダムに変化させるには、いくつかの方法が考えられたのですが、今回はシンプルに二重for文のXとYをランダムに入れ替えることによって達成しました。
他の方法を辞めた理由としては、
例えば、rotate関数を使って、毎度グリッドを回転させようとするとその都度座標軸をグリッド中心に持っていく必要があるので、今回はよりシンプルな方法で実装してみました。
元の絵はこちら。
奮発してホテルのアフタヌーンティーに行った時の写真です。
これがこうなる!
おー。綺麗!
詐欺並みに高いアフタヌーンティーも、これで少しは元が取れたと言えるでしょう。
ちなみに各グリッド内では #亀の歩み1と同じく 、色相ごとにソートして描画しています。
ソースコード
import generativedesign.*;
PImage img;
color[] colors;
void setup() {
size(720, 720);
colorMode(HSB, 360, 100, 100);
img = loadImage("cake.JPG");
int big_rectSize = 120;
int big_tileCount = 720/big_rectSize;
int small_tileCount = 120/1;
int small_rectSize = 1;
// big boxes
for (int big_gridY=0; big_gridY<big_tileCount; big_gridY++) {
for (int big_gridX=0; big_gridX<big_tileCount; big_gridX++) {
// small boxes
int i = 0;
colors = new color[small_tileCount*small_tileCount];
for (int small_gridY=0; small_gridY<small_tileCount; small_gridY++) {
for (int small_gridX=0; small_gridX<small_tileCount; small_gridX++) {
int px = (int) (big_rectSize*big_gridX + small_gridX*small_rectSize);
int py = (int) (big_rectSize*big_gridY + small_gridY*small_rectSize);
colors[i] = img.get(px, py);
i++;
}
}
// small box end
String sortMode = GenerativeDesign.HUE;
colors = GenerativeDesign.sortColors(this, colors, sortMode);
int j = 0;
int toggle = (int) random(0, 2);
if (toggle == 0) {
for (int gridY=0; gridY<small_tileCount; gridY++) {
for (int gridX=0; gridX<small_tileCount; gridX++) {
fill(colors[j]);
noStroke();
rect(big_rectSize*big_gridX + gridX*small_rectSize, big_rectSize*big_gridY + gridY*small_rectSize, small_rectSize, small_rectSize);
j++;
}
}
} else if (toggle == 1) {
for (int gridX=0; gridX<small_tileCount; gridX++) {
for (int gridY=0; gridY<small_tileCount; gridY++) {
fill(colors[j]);
noStroke();
rect(big_rectSize*big_gridX + gridX*small_rectSize, big_rectSize*big_gridY + gridY*small_rectSize, small_rectSize, small_rectSize);
j++;
}
}
}
}
}
}
この記事が気に入ったらサポートをしてみませんか?