Skip to content

Instantly share code, notes, and snippets.

@liquidev
Last active October 16, 2022 13:25
Show Gist options
  • Save liquidev/2f3fc437a214e6a7ab5083c8c7c7b739 to your computer and use it in GitHub Desktop.
Save liquidev/2f3fc437a214e6a7ab5083c8c7c7b739 to your computer and use it in GitHub Desktop.
Mandelbrots

Mandelbrots

An assortment of obfuscated Mandelbrot implementations in Lua. Originally started by me, optimized further by Zevv.

-- Somewhat broken implementation, resembles a Mandelbrot set but probably isn't.
-- I'm no mathematician.
w=io.write y=-1.5 for j=0,20 do x=-2 for i=0,80 do a,b,n=x,y,0 while n<9 do a=a*
a-b*b+x b=2*a*b+y if a*a+b*b>256 then break end n=n+1 end w((".,:;=$%# "):sub(n,
n))x=x+.0375 end w"\n" y=y+.15 end
--[[
:;$,,,,,,.............................................................,,,,;;::=:,
.,,,==;:,,,,,,,,...............................................,,,,,:;;;::;::$;,,
....,,,,;=;::,,,,,,,,,,,,............................,,,,,,,,,:$;;;;;%;::;;=,,,..
......,,,,,:==;=:::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:: $#=;;;;% =::$$%#,,,,....
.......,,,,,,,: %;;%;:::::::::::::::::::::::::;; % % $:,,,,,.....
........,,,,,,,,::# %==%$=;;;::::::;;;;;=$ =% :,,,,,,,....
......,,,,,,,,,,,:::=%# $$ # %$$$==$$$% $ ;:,,,,,,,,,,
,,,,,,,,,,,,,,,,,:::;= #$========
::,,,,,,,,,,::::::;;= ;:::,,,,,,,,
,:::= ==;;;;;;;;= =;;;; ;:,,,,,,
#$$==;;;:::::::,,,
,:::= ==;;;;;;;;= =;;;; ;:,,,,,,
::,,,,,,,,,,::::::;;= ;:::,,,,,,,,
,,,,,,,,,,,,,,,,,:::;= #$========
......,,,,,,,,,,,:::=%# $$ # %$$$==$$$% $ ;:,,,,,,,,,,
........,,,,,,,,::# %==%$=;;;::::::;;;;;=$ =% :,,,,,,,....
.......,,,,,,,: %;;%;:::::::::::::::::::::::::;; % % $:,,,,,.....
......,,,,,:==;=:::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:: $#=;;;;% =::$$%#,,,,....
....,,,,;=;::,,,,,,,,,,,,............................,,,,,,,,,:$;;;;;%;::;;=,,,..
.,,,==;:,,,,,,,,...............................................,,,,,:;;;::;::$;,,
:;$,,,,,,.............................................................,,,,;;::=:,
]]
-- Correct implementation.
w=io.write for j=0,24 do x,y=-2,j/8-1.5 for i=0,80 do a,b,n=x,y,0 while n<9 and
a*a+b*b<6 do a,b,n=a*a-b*b+x,2*a*b+y,n+1 end w((".,:;=$%# "):sub(n,n))x=x+.0375
end w"\n"end
--[[
...............................................................................
........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,........................
.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.................
............,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::;=$=;;;::::::,,,,,,,,,,............
........,,,,,,,,,,,,,,,,,,,,,,,,::::::::::;;;;==% # =;;::::::,,,,,,,,,,........
.....,,,,,,,,,,,,,,,,,,,,,,,:::::::::::;;;;==$# ##==;;;;:::::,,,,,,,,,,.....
...,,,,,,,,,,,,,,,,,,,,::::::::::;;;;====$$$%# %$$====;;;:::,,,,,,,,,,...
.,,,,,,,,,,,,,,,,,::::::::;;;;;;;===$ #=;:::,,,,,,,,,,.
,,,,,,,,,,,,:::::::;;;;;;;;;;====$$# $=;;:::,,,,,,,,,,
,,,,,,::::::::;;;==% %%$%% %%$$%%# $;;:::,,,,,,,,,
,,::::::::;;;;;;=$$%# =;;::::,,,,,,,,
::::::;;;====$$% $=;;:::::,,,,,,,
%$=;;;:::::,,,,,,,
::::::;;;====$$% $=;;:::::,,,,,,,
,,::::::::;;;;;;=$$%# =;;::::,,,,,,,,
,,,,,,::::::::;;;==% %%$%% %%$$%%# $;;:::,,,,,,,,,
,,,,,,,,,,,,:::::::;;;;;;;;;;====$$# $=;;:::,,,,,,,,,,
.,,,,,,,,,,,,,,,,,::::::::;;;;;;;===$ #=;:::,,,,,,,,,,.
...,,,,,,,,,,,,,,,,,,,,::::::::::;;;;====$$$%# %$$====;;;:::,,,,,,,,,,...
.....,,,,,,,,,,,,,,,,,,,,,,,:::::::::::;;;;==$# ##==;;;;:::::,,,,,,,,,,.....
........,,,,,,,,,,,,,,,,,,,,,,,,::::::::::;;;;==% # =;;::::::,,,,,,,,,,........
............,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::;=$=;;;::::::,,,,,,,,,,............
.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.................
........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,........................
...............................................................................
]]
-- Condensed down to two lines by counting X and Y directly instead of deriving
-- them from line and column positions.
-- This has the nice side effect that the Mandelbrot isn't infuriatingly 81x25
-- cells big anymore.
w=io.write for y=-12,12 do for x=-2,1,3/80 do a,b,n=x,y/8,0 while n<9 and a*a+b*
b<6 do a,b,n=a*a-b*b+x,2*a*b+y/8,n+1 end w((".,:;=$%# "):sub(n,n))end w"\n"end
--[[
..............................................................................
........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.......................
.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................
............,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::;=$=;;;::::::,,,,,,,,,,...........
........,,,,,,,,,,,,,,,,,,,,,,,,::::::::::;;;;==% # =;;::::::,,,,,,,,,,.......
.....,,,,,,,,,,,,,,,,,,,,,,,:::::::::::;;;;==$# ##==;;;;:::::,,,,,,,,,,....
...,,,,,,,,,,,,,,,,,,,,::::::::::;;;;====$$$%# %$$====;;;:::,,,,,,,,,,..
.,,,,,,,,,,,,,,,,,::::::::;;;;;;;===$ #=;:::,,,,,,,,,,
,,,,,,,,,,,,:::::::;;;;;;;;;;====$$# $=;;:::,,,,,,,,,
,,,,,,::::::::;;;==% %%$%% %%$$%%# $;;:::,,,,,,,,
,,::::::::;;;;;;=$$%# =;;::::,,,,,,,
::::::;;;====$$% $=;;:::::,,,,,,
%$=;;;:::::,,,,,,
::::::;;;====$$% $=;;:::::,,,,,,
,,::::::::;;;;;;=$$%# =;;::::,,,,,,,
,,,,,,::::::::;;;==% %%$%% %%$$%%# $;;:::,,,,,,,,
,,,,,,,,,,,,:::::::;;;;;;;;;;====$$# $=;;:::,,,,,,,,,
.,,,,,,,,,,,,,,,,,::::::::;;;;;;;===$ #=;:::,,,,,,,,,,
...,,,,,,,,,,,,,,,,,,,,::::::::::;;;;====$$$%# %$$====;;;:::,,,,,,,,,,..
.....,,,,,,,,,,,,,,,,,,,,,,,:::::::::::;;;;==$# ##==;;;;:::::,,,,,,,,,,....
........,,,,,,,,,,,,,,,,,,,,,,,,::::::::::;;;;==% # =;;::::::,,,,,,,,,,.......
............,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::;=$=;;;::::::,,,,,,,,,,...........
.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................
........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.......................
..............................................................................
]]
-- Uses string concatenation instead of io.write, which saves a few bytes.
for y=-12,12 do l=""for x=-2,1,3/80 do a,b,n=0,0,0 while n<9 and a*a+b*b<4 do
a,b,n=a*a-b*b+x,2*a*b+y/8,n+1 end l=l..(".,:;=$%# "):sub(n,n)end print(l)end
-- Output is the same as 2022-10-15-a.lua.
-- Increased iteration count from 10 to 25. Does this by cheating slightly and
-- choosing a negative initial value for n. This means the string lookup table
-- need not be expanded to account for additional iterations.
-- This cheat however requires that the second bailout condition uses a really
-- big limit value, not sure why. But it works! and produces a Mandelbrot that's
-- a bit less blobby and with a bit more intricate detail.
for y=-12,12 do l=""for x=-2,1,3/80 do a,b,n=0,0,-15 while n<9 and a*a+b*b<1e12
do a,b,n=a*a-b*b+x,2*a*b+y/8,n+1 end l=l..(".,:;=$%# "):sub(n,n)end print(l)end
--[[
............................................,,,,,,,,............................
.................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................
.........................,,,,,,,,,,,,,,,,,,,,,,::::,,,,,,,,,,,,,,,..............
...................,,,,,,,,,,,,,,,,,,,,,::::::;=$=;;::::::,,,,,,,,,,,,..........
..............,,,,,,,,,,,,,,,,,,,,:::::::::;;;==% :#=;;:::::,,,,,,,,,,,.......
.........,,,,,,,,,,,,,,,,,,,,:::::::::;;;;;==$%;; ,##==;;;::::::,,,,,,,,,.....
.....,,,,,,,,,,,,,,,,,:::::::::::;;;;====$$$%#: %$$===;;;;::::,,,,,,,,...
..,,,,,,,,,,,,,,::::::::::::;;;;;;==$ , .#% #=;:::,,,,,,,,,.
,,,,,,,,,,,,::::::;;;;;;;;;;=====$$#:. $=;;::::,,,,,,,,
,,,,,,,,:::::::;;;=%:%%%%%=%%%%%%# $ $;;:::,,,,,,,,
,,,,:::::::;;;;===$%#: ,.. :,=;;::::,,,,,,,
::::;;;;;;====$# ..# ;$=;;::::,,,,,,,
; %$=;;;::::,,,,,,,
::::;;;;;;====$# ..# ;$=;;::::,,,,,,,
,,,,:::::::;;;;===$%#: ,.. :,=;;::::,,,,,,,
,,,,,,,,:::::::;;;=%:%%%%%=%%%%%%# $ $;;:::,,,,,,,,
,,,,,,,,,,,,::::::;;;;;;;;;;=====$$#:. $=;;::::,,,,,,,,
..,,,,,,,,,,,,,,::::::::::::;;;;;;==$ , .#% #=;:::,,,,,,,,,.
.....,,,,,,,,,,,,,,,,,:::::::::::;;;;====$$$%#: %$$===;;;;::::,,,,,,,,...
.........,,,,,,,,,,,,,,,,,,,,:::::::::;;;;;==$%;; ,##==;;;::::::,,,,,,,,,.....
..............,,,,,,,,,,,,,,,,,,,,:::::::::;;;==% :#=;;:::::,,,,,,,,,,,.......
...................,,,,,,,,,,,,,,,,,,,,,::::::;=$=;;::::::,,,,,,,,,,,,..........
.........................,,,,,,,,,,,,,,,,,,,,,,::::,,,,,,,,,,,,,,,..............
.................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................
............................................,,,,,,,,............................
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment