Skip to content

Instantly share code, notes, and snippets.

@TonyMooori
Last active December 24, 2017 13:21
Show Gist options
  • Save TonyMooori/9e92b20512a79396d3654a0a40084744 to your computer and use it in GitHub Desktop.
Save TonyMooori/9e92b20512a79396d3654a0a40084744 to your computer and use it in GitHub Desktop.
宝石の国のopに感化されて作ったもの.彩色はアンタークチサイトの出場シーンをイメージ(氷の青と雪の白)
public static final int N = 12;
void setup() {
size(700, 335);
//size(1400, 670);
// 正N角形の座標
FloatList xs = new FloatList();
FloatList ys = new FloatList();
int r = 1404;
for (int i = 0; i < N; i++ ) {
float theta = i*2*PI/N;
xs.append(r*cos(theta));
ys.append(r*sin(theta));
}
// 色とかの決定
background(0,125,255,6);
fill(255, 255, 255,60);
stroke(255, 255, 255,60);
translate(3*width/4, 3*height/4);
rotate(PI/12);
// 描画
drawFractal(xs, ys, 0);
//saveFrame("E:\\a.png");
}
void drawFractal(FloatList xs, FloatList ys, int depth) {
if (depth==30)return;
FloatList xs2 = new FloatList();
FloatList ys2 = new FloatList();
int k = 4; // 係数
// 3点の平均を次の座標列にする
for (int i = 0; i < N; i++ ) {
xs2.append((xs.get(i)+xs.get((i+k/2)%N)+xs.get((i+k)%N))/3);
ys2.append((ys.get(i)+ys.get((i+k/2)%N)+ys.get((i+k)%N))/3);
}
// 新たな座標列とそのもととなった座標列で三角形を描画
for (int i = 0; i < N; i++ ) {
triangle(
xs.get(i%N), ys.get(i%N),
xs.get((i+k)%N), ys.get((i+k)%N),
xs2.get(i%N), ys2.get(i%N));
}
// 再帰呼び出し
drawFractal(xs2, ys2, depth+1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment