... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2008-01-05

Mandelbrot in Mathematica

Just for laughs, a implemented a tiny Mandelbrot application in Mathematica.

mandelbrot =
  Compile[{{cx, _Real}, {cy, _Real}, {limit, _Integer}},
    Module[{count = 0, zx=cx, zy=cy, zx2=0, zy2=0, tx=0, ty=0},
      While[count <= limit && (zx2 = zx^2)+(zy2 = zy^2) < 4,
        ++count;
        tx = zx2 - zy2 + cx;
        ty = 2 zx zy + cy;
        zx = tx;
        zy = ty
      ];
    count
  ]
];

Manipulate[
  ReliefPlot[
    Table[
      mandelbrot[x, y, limit],
      {y, y0, y0 + x1 - x0, (x1 - x0) / resolution},
      {x, x0, x1, (x1 - x0) / resolution}
    ],
    ColorFunction -> colors
  ],
  {limit, 50},
  {resolution, 400},
  {x0, -2},
  {x1, 1},
  {y0, -1.5},
  {colors, Sort@ColorData["Gradients"]}
]

Blog Archive