M
Code
Tutorials
Grammar
Star
general
draw mandelbrot set using linear color function
let mut a:u8[200][300 * 4] let scale = 0.01 for x in 0..300: for y in 0..200: let cx = -2.0 + scale*x let cy = -1.0 + scale*y let mut zx = 0.0, zy = 0.0 let mut zx2 = 0.0, zy2 = 0.0 let mut n = 0 while n<510 and (zx2 + zy2) < 4.0: zy = 2.0 * zx * zy + cy zx = zx2 - zy2 + cx zx2 = zx * zx zy2 = zy * zy n++ a[y][4*x] = n < 256 ? 0 : 510 - n a[y][4*x+1] = n < 256 ? n : 510 - n a[y][4*x+2] = n < 256 ? 0 : 510 - n a[y][4*x+3] = 255 setImageData(a, 300, 200)
run
draw mandelbrot set using log color function
let mut a:u8[200][300 * 4] let scale = 0.01, max_iter = 510 let mut v = 0.0, r = 0.0, g = 0.0, b = 0.0 for x in 0..300: for y in 0..200: let cx = -2.0 + scale*x let cy = -1.0 + scale*y let mut zx = 0.0, zy = 0.0 let mut zx2 = 0.0, zy2 = 0.0 let mut n = 0 while n
run
julia set c = -0.79 + 0.15i
let width = 300, height = 200 let mut a:u8[200][300 * 4] let scalex = 4.0/300.0, scaley=2.0/200.0, max_iter = 510 let mut v = 0.0, r = 0.0, g = 0.0, b = 0.0 let cx = -0.79 let cy = 0.15 for x in 0..300: for y in 0..200: let mut zx = -2.0 + scalex * x, zy = -1.0 + scaley * y let mut zx2 = zx * zx, zy2 = zy * zy let mut n = 0 while n
run
julia set c = 0.3 - 0.01i
let width = 300, height = 200 let mut a:u8[200][300 * 4] let scalex = 4.0/300.0, scaley=3.0/200.0, max_iter = 510 let mut v = 0.0, r = 0.0, g = 0.0, b = 0.0 let cx = 0.3 let cy = -0.01 for x in 0..300: for y in 0..200: let mut zx = -2.0 + scalex * x, zy = -1.5 + scaley * y let mut zx2 = zx * zx, zy2 = zy * zy let mut n = 0 while n
run