How to resolve the algorithm Mandelbrot set step by step in the Haxe programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Mandelbrot set step by step in the Haxe programming language
Table of Contents
Problem Statement
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Mandelbrot set step by step in the Haxe programming language
Source code in the haxe programming language
haxe -swf mandelbrot.swf -main Mandelbrot
class Mandelbrot extends flash.display.Sprite
{
inline static var MAX_ITER = 255;
public static function main() {
var w = flash.Lib.current.stage.stageWidth;
var h = flash.Lib.current.stage.stageHeight;
var mandelbrot = new Mandelbrot(w, h);
flash.Lib.current.stage.addChild(mandelbrot);
mandelbrot.drawMandelbrot();
}
var image:flash.display.BitmapData;
public function new(width, height) {
super();
var bitmap:flash.display.Bitmap;
image = new flash.display.BitmapData(width, height, false);
bitmap = new flash.display.Bitmap(image);
this.addChild(bitmap);
}
public function drawMandelbrot() {
image.lock();
var step_x = 3.0 / (image.width-1);
var step_y = 2.0 / (image.height-1);
for (i in 0...image.height) {
var ci = i * step_y - 1.0;
for (j in 0...image.width) {
var k = 0;
var zr = 0.0;
var zi = 0.0;
var cr = j * step_x - 2.0;
while (k <= MAX_ITER && (zr*zr + zi*zi) <= 4) {
var temp = zr*zr - zi*zi + cr;
zi = 2*zr*zi + ci;
zr = temp;
k ++;
}
paint(j, i, k);
}
}
image.unlock();
}
inline function paint(x, y, iter) {
var color = iter > MAX_ITER? 0 : iter * 0x100;
image.setPixel(x, y, color);
}
}
You may also check:How to resolve the algorithm Hello world/Text step by step in the COBOL programming language
You may also check:How to resolve the algorithm Variable size/Get step by step in the IDL programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the XPL0 programming language