diff --git a/mandelbrot b/mandelbrot new file mode 100755 index 0000000..6e3bb8e Binary files /dev/null and b/mandelbrot differ diff --git a/mandelbrot.nim b/mandelbrot.nim index d8866f2..1820675 100644 --- a/mandelbrot.nim +++ b/mandelbrot.nim @@ -1,8 +1,26 @@ -import complex, colors +import math, complex, colors - -proc getComplexValueForPixel(x:int, y:int, height:int, width:int, zoom:float): Complex = - (re: (x-width/2.0)/zoom, im: (y-height/2.0)/zoom) +proc getComplexValueForPixel(x:int, y:int, height:int, width:int, zoom:float64): Complex[float64] = + complex.complex64((x.float64-width.float64/2.0'f64)/zoom, (y.float64-height.float64/2.0'f64)/zoom) proc colorMap(i:int, nMax:int): Color = rgb(0, 0, 0) + +proc generatePixel(x:int, y:int, height:int, width:int, zoom:float64, + rMax: int, maxIter:int) : Color = + let c = getComplexValueForPixel(x, y, height, width, zoom) + + var + n = 0 + z = complex64(0'f64, 0'f64) + + for i in 0..maxIter: + if z.abs >= rMax.float64: + n = i + break + z = c + z * z + + result = colorMap(n, maxIter) + +proc generateImage(width:int, height:int, zoom:float64, rMax:int, maxIter:int) = + discard nil