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?

トリボナッチ・木構造

Last updated at Posted at 2025-05-18

トリボナッチ・木構造

トリボナッチ数列に基づき、木構造を描く。
L-Systemと同様の結果。
image.png

フィボナッチ数列

F_0 = 1
F_n = F_{n-1} + F_{n-2}
0 1 2 3 4 5 6 7 8 9 10 11
1 1 2 3 5 8 13 21 34 55 89 144

トリボナッチ数列

T_0 = 1
T_n = T_{n-1} + T_{n-2} + T_{n-3}
0 1 2 3 4 5 6 7 8 9 10 11
0 0 1 1 2 4 7 13 24 44 81 149
1 1 1 3 5 9 17 31 57 105 193 355

0開始と、1開始がある。

プログラム

float angle = PI / 5;
int maxDepth = 10;

void setup() {
  size(400, 300);
  background(255);
  stroke(0);
  translate(width/2, height);
  drawTribonacciBranch(100, maxDepth);
}

void drawTribonacciBranch(float len, int depth) {
  if (depth < 1) return;

  line(0, 0, 0, -len);
  translate(0, -len);

  if (depth - 1 >= 1) {
    pushMatrix();
    rotate(-angle);
    drawTribonacciBranch(len * 0.7, depth - 1);
    popMatrix();
  }

  if (depth - 2 >= 1) {
    pushMatrix();
    rotate(0);
    drawTribonacciBranch(len * 0.7, depth - 2);
    popMatrix();
  }

  if (depth - 3 >= 1) {
    pushMatrix();
    rotate(angle);
    drawTribonacciBranch(len * 0.7, depth - 3);
    popMatrix();
  }
}
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?