Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Fractal Drawing
- -- by @beezing
- imgHeight = 220
- imgWidth = 300
- inCol = 0 -- mandelbrot set color
- colFac = 12 -- color gradient factor
- maxIt = 48 -- number of iterations
- function Fractal(x0,y0, minRe,maxRe,minIm, jRe,jIm, R,G,B)
- maxIm = minIm+(maxRe-minRe)*(imgHeight/imgWidth)
- reFac = (maxRe-minRe)/imgWidth
- imFac = (maxIm-minIm)/imgHeight
- for y = 0, imgHeight-1 do
- cIm = maxIm - y*imFac
- for x = 0, imgWidth-1 do
- cRe = minRe + x*reFac
- zRe = cRe; zIm = cIm;
- n = 0; isIn = true; outCol = colFac;
- repeat
- n = n + 1
- zRe2 = zRe*zRe; zIm2 = zIm*zIm;
- zIm = 2*zRe*zIm + (jIm or cIm)
- zRe = zRe2-zIm2 + (jRe or cRe)
- isIn = not (zRe2+zIm2 > 4)
- if n < maxIt/2-1 then
- outCol = outCol + colFac
- else
- outCol = outCol - colFac
- end
- until (not isIn) or (n > maxIt-1)
- if isIn then
- setcolor(inCol,inCol,inCol)
- else
- if R then r = R-outCol else r = outCol end
- if G then g = G-outCol else g = outCol end
- if B then b = B-outCol else b = outCol end
- setcolor(r,g,b)
- end
- drawPoint(x+x0, y+y0)
- end
- end
- end
- clear()
- --print('Calculating fractal image. Please wait...')
- --disableScreenRefresh()
- Fractal(10, 60,-1.1,-.6,-0.55,nil,nil,nil,nil,128)
- Fractal(10,290,-1.7,1.7,-1.25,-.8,.15,128,nil,nil)
- Fractal(10,520,-1.7,1.7,-1.25,-.7,.38,nil,128,nil)
- --enableScreenRefresh()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement