WIP
This commit is contained in:
parent
572116ba4a
commit
2948a9ea5d
7 changed files with 83 additions and 7 deletions
|
|
@ -1,20 +1,27 @@
|
|||
import math, complex, colors
|
||||
import sequtils, math, complex, colors, hsb
|
||||
|
||||
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)
|
||||
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)
|
||||
let
|
||||
h = if (float(i) / 100'f64) <= 1.0:
|
||||
(float(i) / 100'f64) * 360'f64
|
||||
else: 360'f64
|
||||
s = 1'f64
|
||||
v = if i < nMax: 1'f64 else: 0'f64
|
||||
|
||||
result = hsbToRgb(h, s, v)
|
||||
|
||||
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
|
||||
n = maxIter
|
||||
z = complex64(0'f64, 0'f64)
|
||||
|
||||
for i in 0..maxIter:
|
||||
for i in 0..maxIter-1:
|
||||
if z.abs >= rMax.float64:
|
||||
n = i
|
||||
break
|
||||
|
|
@ -22,5 +29,10 @@ proc generatePixel(x:int, y:int, height:int, width:int, zoom:float64,
|
|||
|
||||
result = colorMap(n, maxIter)
|
||||
|
||||
proc generateImage(width:int, height:int, zoom:float64, rMax:int, maxIter:int) =
|
||||
discard nil
|
||||
proc generateImage*(width:int, height:int, zoom:float64, rMax:int, maxIter:int): seq[seq[Color]] =
|
||||
|
||||
result = newSeqWith(height, newSeq[Color](width))
|
||||
|
||||
for y in 0..height-1:
|
||||
for x in 0..width-1:
|
||||
result[y][x] = generatePixel(x, y, height, width, zoom, rMax, maxIter)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue