31 lines
796 B
Text
31 lines
796 B
Text
require "bitmap"
|
|
|
|
local w = 800
|
|
local h = 600
|
|
local bmp = bitmap.of(w, h, color.black, "Mandelbrot_set")
|
|
|
|
local max_iters = 570
|
|
local zoom = 150
|
|
|
|
local function mandelbrot()
|
|
for x = 0, w - 1 do
|
|
for y = 0, h - 1 do
|
|
local zx = 0
|
|
local zy = 0
|
|
local c_x = (x - 400) / zoom
|
|
local c_y = (y - 300) / zoom
|
|
local i = max_iters
|
|
while zx * zx + zy * zy < 4 and i > 0 do
|
|
local tmp = zx * zx - zy * zy + c_x
|
|
zy = 2 * zx * zy + c_y
|
|
zx = tmp
|
|
i -= 1
|
|
end
|
|
local r = math.round(i * 255 / max_iters)
|
|
bmp:set(math.round(x), math.round(y), bitmap.rgbColor(r, r, r))
|
|
end
|
|
end
|
|
end
|
|
|
|
mandelbrot()
|
|
bmp:view(false, "", "", true)
|