1920x1200 resolution with 3000 iterations, took around 2 minutes to render.
- Code: Select all
require 'gd'
local dime = {1920,1200}
--local dime = {400,400}
local im = gd.createTrueColor(dime[1], dime[2])
local white = im:colorAllocate(255, 255, 255)
local black = im:colorAllocate(0, 0, 0)
local MinRe = -2
local MaxRe = 1
local MinIm = -1.2
local MaxIm = MinIm + (MaxRe-MinRe) * dime[2]/dime[1]
local Re_factor = (MaxRe-MinRe)/(dime[1]-1);
local Im_factor = (MaxIm-MinIm)/(dime[2]-1);
local MaxIterations = 3000
for y=0, dime[2] do
local c_im = MaxIm - y*Im_factor
for x=0, dime[1] do
local c_re = MinRe + x*Re_factor
local Z_re = c_re
local Z_im = c_im
local isInside = true
local d = 0
for n=0, MaxIterations do
local Z_re2 = Z_re*Z_re
local Z_im2 = Z_im*Z_im
if Z_re2 + Z_im2 > 4 then
isInside = false;
d = n
break
end
Z_im = 2*Z_re*Z_im + c_im
Z_re = Z_re2 - Z_im2 + c_re
end
if isInside then
im:setPixel(x,y, white)
else
local mul = (d < MaxIterations/2) and (d / MaxIterations) * 100 or 0
local mul2 = (d > MaxIterations/2) and d / MaxIterations or 0
local col = im:colorResolve(0,mul2*255,mul*255)
im:setPixel(x,y,col)
end
end
print((y/dime[2])*100 .. "%")
end
im:png("result.png")



