LoginSignup
0
1

マンデルブロ集合の内側を塗る

Posted at

再帰プログラム

5! = 5\times4\times3\times2\times1=120

階乗を求めるプログラム

void setup() {
  print(f(5));
}

int f(int n) {
  if (n<=0) {
    return 1;
  }
  return n*f(n-1);
}

この再帰構造を参考にマンデルブロ集合を描く

void setup() {
  size(512, 512);
  noLoop();

  double d = 2.5d/(double)width;
  int xx=0,yy=0;
  for (double y = -1.25; y < 1.25; y+=d) {
    for (double x = -2.0; x < 0.5; x+=d) {
      int c = mandel(0, 0, x, y, 255);
      stroke(c);
      point(xx,yy);
      xx++;
    }
    xx=0;
    yy++;
  }
}

int mandel(double zr, double zi, double cr, double ci, int ite) {
  double zr2 = zr*zr - zi*zi + cr;
  double zi2 = 2*zr*zi + ci;  
  if(0==ite || zr2*zr2 + zi2*zi2>4){
    return ite;
  }
  return mandel( zr2, zi2, cr, ci, ite-1);
}

mandel.png

式変形して

mandel_in_01.png

image.png

もう少しきれいに3Dで表示したい
z^3とかよくあるバリエーションについても

0
1
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
1