0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Truchetタイル

Last updated at Posted at 2024-10-07

本記事は、以下の記事から続いています。

Truchet トルシェット タイル

正方形を斜めに分け、白黒に塗り分けたタイルを用意する。これを敷き詰める際に向きをランダムにしたり、規則的にすることで、また別の模様が見えてくる。

truchet.png

int(random(4))*90;

乱数0~3.999を発生させ、intで整数に切り捨てる(0,1,2,3)。
その後90を掛けて、0,90,180,270を生成する。

radians(th);

度をラジアンに単位変換する命令。

PImage img;

size(640, 640);
img = loadImage("truchet.png");

for (int y=0; y<640; y+=64) {
  for (int x=0; x<640; x+=64) {
    float th = int(random(4))*90;
    push();
      translate(x+32, y+32);
      rotate(radians(th));
      translate(-img.width/2, -img.height/2);
      image(img, 0, 0);
    pop();
  }
}

image.png

六角形充填

 正方形と同様に、六角形を敷き詰める事を考える。
 画像は、イラレから書き出す際に、背景を透過色pngで保存する。
 画像サイズは、64x64として、画像の中心が六角形の中心になるようにする。
truchetHex.png

int(random(6))*60

これは0,60,120,180,240,300を生成する式である。

((x/(int)w)%2*(h*0.5))

これは、xをwで割ったときに、奇数か偶数かで、上下にずらす値を計算する式である。
xを整数で割りたいので、intでwを変換し、
%2で、余りが、0か1を求める。
その結果に、ずらしたい縦の移動量(h*0.5)を掛けている。
h/2だと結果が、整数になるかもしれないので、避けている。

「55.4256」この値は、イラレで表示された値です。

PImage img;

float w=64-16;
float h=55.4256;

size(640, 640);
img = loadImage("truchetHex.png");

for (int y=0; y<640; y+=h) {
  for (int x=0; x<640; x+=w) {
    float th = int(random(6))*60;
    push();
      translate(x, y+((x/(int)w)%2*(h*0.5)));
      rotate(radians(th));
      translate(-img.width/2, -img.height/2);
      image(img, 0, 0);
    pop();
  }
}

image.png

改良

truchetパターンは多く考案されているので、正方形や六角形の画像を差し替えて、違うバリエーションを試してほしい。

スクショを撮るか、save("xxx.png");で保存提出。

おまけ

我が家の、なんかしらん袋
IMG_6283.jpeg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?