Untitled

By Diminutive Ostrich, 6 Years ago (2012-12-24 20:18:14), written in Lua, viewed 892 times.
URL https://paste.godclan.hu/view/7wUa3Vt5 Embed
Download Paste or View RawExpand paste to full width of browser
  1. local write, char, unpack = io.write, string.char, unpack
  2. local N = tonumber(arg and arg[1]) or 100
  3. local M, ba, bb, buf = 2/N, 2^(N%8+1)-1, 2^(8-N%8), {}
  4. write("P4\n", N, " ", N, "\n")
  5. for y=0,N-1 do
  6.   local Ci, b, p = y*M-1, 1, 0
  7.   for x=0,N-1 do
  8.     local Cr = x*M-1.5
  9.     local Zr, Zi, Zrq, Ziq = Cr, Ci, Cr*Cr, Ci*Ci
  10.     b = b + b
  11.     for i=1,49 do
  12.       Zi = Zr*Zi*2 + Ci
  13.       Zr = Zrq-Ziq + Cr
  14.       Ziq = Zi*Zi
  15.       Zrq = Zr*Zr
  16.       if Zrq+Ziq > 4.0 then b = b + 1; break; end
  17.     end
  18.     if b >= 256 then p = p + 1; buf[p] = 511 - b; b = 1; end
  19.   end
  20.   if b ~= 1 then p = p + 1; buf[p] = (ba-b)*bb; end
  21.   write(char(unpack(buf, 1, p)))
  22. end
  23.  

Reply to "Untitled"

Here you can reply to the paste above