An assortment of obfuscated Mandelbrot implementations in Lua. Originally started by me, optimized further by Zevv.
Last active
October 16, 2022 13:25
-
-
Save liquidev/2f3fc437a214e6a7ab5083c8c7c7b739 to your computer and use it in GitHub Desktop.
Mandelbrots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 | |
--[[ | |
:;$,,,,,,.............................................................,,,,;;::=:, | |
.,,,==;:,,,,,,,,...............................................,,,,,:;;;::;::$;,, | |
....,,,,;=;::,,,,,,,,,,,,............................,,,,,,,,,:$;;;;;%;::;;=,,,.. | |
......,,,,,:==;=:::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:: $#=;;;;% =::$$%#,,,,.... | |
.......,,,,,,,: %;;%;:::::::::::::::::::::::::;; % % $:,,,,,..... | |
........,,,,,,,,::# %==%$=;;;::::::;;;;;=$ =% :,,,,,,,.... | |
......,,,,,,,,,,,:::=%# $$ # %$$$==$$$% $ ;:,,,,,,,,,, | |
,,,,,,,,,,,,,,,,,:::;= #$======== | |
::,,,,,,,,,,::::::;;= ;:::,,,,,,,, | |
,:::= ==;;;;;;;;= =;;;; ;:,,,,,, | |
#$$==;;;:::::::,,, | |
,:::= ==;;;;;;;;= =;;;; ;:,,,,,, | |
::,,,,,,,,,,::::::;;= ;:::,,,,,,,, | |
,,,,,,,,,,,,,,,,,:::;= #$======== | |
......,,,,,,,,,,,:::=%# $$ # %$$$==$$$% $ ;:,,,,,,,,,, | |
........,,,,,,,,::# %==%$=;;;::::::;;;;;=$ =% :,,,,,,,.... | |
.......,,,,,,,: %;;%;:::::::::::::::::::::::::;; % % $:,,,,,..... | |
......,,,,,:==;=:::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:: $#=;;;;% =::$$%#,,,,.... | |
....,,,,;=;::,,,,,,,,,,,,............................,,,,,,,,,:$;;;;;%;::;;=,,,.. | |
.,,,==;:,,,,,,,,...............................................,,,,,:;;;::;::$;,, | |
:;$,,,,,,.............................................................,,,,;;::=:, | |
]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 | |
--[[ | |
............................................................................... | |
........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,........................ | |
.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................. | |
............,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::;=$=;;;::::::,,,,,,,,,,............ | |
........,,,,,,,,,,,,,,,,,,,,,,,,::::::::::;;;;==% # =;;::::::,,,,,,,,,,........ | |
.....,,,,,,,,,,,,,,,,,,,,,,,:::::::::::;;;;==$# ##==;;;;:::::,,,,,,,,,,..... | |
...,,,,,,,,,,,,,,,,,,,,::::::::::;;;;====$$$%# %$$====;;;:::,,,,,,,,,,... | |
.,,,,,,,,,,,,,,,,,::::::::;;;;;;;===$ #=;:::,,,,,,,,,,. | |
,,,,,,,,,,,,:::::::;;;;;;;;;;====$$# $=;;:::,,,,,,,,,, | |
,,,,,,::::::::;;;==% %%$%% %%$$%%# $;;:::,,,,,,,,, | |
,,::::::::;;;;;;=$$%# =;;::::,,,,,,,, | |
::::::;;;====$$% $=;;:::::,,,,,,, | |
%$=;;;:::::,,,,,,, | |
::::::;;;====$$% $=;;:::::,,,,,,, | |
,,::::::::;;;;;;=$$%# =;;::::,,,,,,,, | |
,,,,,,::::::::;;;==% %%$%% %%$$%%# $;;:::,,,,,,,,, | |
,,,,,,,,,,,,:::::::;;;;;;;;;;====$$# $=;;:::,,,,,,,,,, | |
.,,,,,,,,,,,,,,,,,::::::::;;;;;;;===$ #=;:::,,,,,,,,,,. | |
...,,,,,,,,,,,,,,,,,,,,::::::::::;;;;====$$$%# %$$====;;;:::,,,,,,,,,,... | |
.....,,,,,,,,,,,,,,,,,,,,,,,:::::::::::;;;;==$# ##==;;;;:::::,,,,,,,,,,..... | |
........,,,,,,,,,,,,,,,,,,,,,,,,::::::::::;;;;==% # =;;::::::,,,,,,,,,,........ | |
............,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::;=$=;;;::::::,,,,,,,,,,............ | |
.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................. | |
........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,........................ | |
............................................................................... | |
]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 | |
--[[ | |
.............................................................................. | |
........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................... | |
.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................ | |
............,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::;=$=;;;::::::,,,,,,,,,,........... | |
........,,,,,,,,,,,,,,,,,,,,,,,,::::::::::;;;;==% # =;;::::::,,,,,,,,,,....... | |
.....,,,,,,,,,,,,,,,,,,,,,,,:::::::::::;;;;==$# ##==;;;;:::::,,,,,,,,,,.... | |
...,,,,,,,,,,,,,,,,,,,,::::::::::;;;;====$$$%# %$$====;;;:::,,,,,,,,,,.. | |
.,,,,,,,,,,,,,,,,,::::::::;;;;;;;===$ #=;:::,,,,,,,,,, | |
,,,,,,,,,,,,:::::::;;;;;;;;;;====$$# $=;;:::,,,,,,,,, | |
,,,,,,::::::::;;;==% %%$%% %%$$%%# $;;:::,,,,,,,, | |
,,::::::::;;;;;;=$$%# =;;::::,,,,,,, | |
::::::;;;====$$% $=;;:::::,,,,,, | |
%$=;;;:::::,,,,,, | |
::::::;;;====$$% $=;;:::::,,,,,, | |
,,::::::::;;;;;;=$$%# =;;::::,,,,,,, | |
,,,,,,::::::::;;;==% %%$%% %%$$%%# $;;:::,,,,,,,, | |
,,,,,,,,,,,,:::::::;;;;;;;;;;====$$# $=;;:::,,,,,,,,, | |
.,,,,,,,,,,,,,,,,,::::::::;;;;;;;===$ #=;:::,,,,,,,,,, | |
...,,,,,,,,,,,,,,,,,,,,::::::::::;;;;====$$$%# %$$====;;;:::,,,,,,,,,,.. | |
.....,,,,,,,,,,,,,,,,,,,,,,,:::::::::::;;;;==$# ##==;;;;:::::,,,,,,,,,,.... | |
........,,,,,,,,,,,,,,,,,,,,,,,,::::::::::;;;;==% # =;;::::::,,,,,,,,,,....... | |
............,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::;=$=;;;::::::,,,,,,,,,,........... | |
.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................ | |
........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................... | |
.............................................................................. | |
]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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