Skip to content

Instantly share code, notes, and snippets.

@seungwonpark
Created October 11, 2019 13:36
Show Gist options
  • Save seungwonpark/899a50265659b883a318490a317c6b89 to your computer and use it in GitHub Desktop.
Save seungwonpark/899a50265659b883a318490a317c6b89 to your computer and use it in GitHub Desktop.
% !TeX program = lualatex
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usepackage{luacode}
\usepackage{graphicx}
\definecolor{joired}{RGB}{218,11,49}
\definecolor{joigreen}{RGB}{18,136,104}
\definecolor{joiyellow}{RGB}{250,210,49}
\definecolor{joiblue}{RGB}{15,105,180}
\definecolor{joiblack}{RGB}{0,0,1}
\begin{document}
\begin{tikzpicture}
\clip (-8,8) rectangle (0,-0);
\luaexec{
s = {"joiblack", "joiblue", "joiyellow", "joigreen", "joired"}
tp=tex.print
two = {8}
gap = {0.2}
textscale = 1
for i=2,50 do
two[i] = two[i-1]*0.5
gap[i] = gap[i-1]*0.5
end
function fractal(n, c, x, y)
tp("\\fill[" .. s[math.fmod(c+8,5)+1] .. "] (" .. x-two[n] .. ", " .. y+two[n+1] .. ") rectangle (" .. x-two[n+1] .. ", " .. y+two[n] .. ");")
tp("\\fill[" .. s[math.fmod(c+5,5)+1] .. "] (" .. x-two[n+1] .. ", " .. y+two[n+1]+two[n+2] .. ") rectangle (" .. x-two[n+2] .. ", " .. y+two[n] .. ");")
tp("\\fill[" .. s[math.fmod(c+7,5)+1] .. "] (" .. x-two[n+2] .. ", " .. y+two[n+1]+two[n+2] .. ") rectangle (" .. x .. ", " .. y+two[n] .. ");")
tp("\\fill[" .. s[math.fmod(c+7,5)+1] .. "] (" .. x-two[n+1] .. ", " .. y+two[n+1] .. ") rectangle (" .. x-two[n+2] .. ", " .. y+two[n+1]+two[n+2] .. ");")
tp("\\fill[" .. s[math.fmod(c+5,5)+1] .. "] (" .. x-two[n] .. ", " .. y+two[n+2] .. ") rectangle (" .. x-two[n+1]-two[n+2] .. ", " .. y+two[n+1] .. ");")
tp("\\fill[" .. s[math.fmod(c+7,5)+1] .. "] (" .. x-two[n+2]-two[n+1] .. ", " .. y+two[n+2] .. ") rectangle (" .. x-two[n+1] .. ", " .. y+two[n+1] .. ");")
tp("\\fill[" .. s[math.fmod(c+7,5)+1] .. "] (" .. x-two[n] .. ", " .. y .. ") rectangle (" .. x-two[n+1]-two[n+2] .. ", " .. y+two[n+2] .. ");")
if n<=8 then
tp("\\node at (" .. x-two[n+1]-two[n+2] .. "," .. y+two[n+1]+two[n+2] .. ") {\\includegraphics[width=" .. textscale*two[n+1] .. "cm]{park.png}};")
tp("\\node at (" .. x-two[n+2]-two[n+3] .. "," .. y+two[n]-two[n+3] .. ") {\\includegraphics[width=" .. textscale*two[n+2] .. "cm]{seung.png}};")
tp("\\node at (" .. x-two[n]+two[n+3] .. "," .. y+two[n+2]+two[n+3] .. ") {\\includegraphics[width=" .. textscale*two[n+2] .. "cm]{seung.png}};")
tp("\\node at (" .. x-two[n+3] .. "," .. y+two[n]-two[n+3] .. ") {\\includegraphics[width=" .. textscale*two[n+2] .. "cm]{won.png}};")
tp("\\node at (" .. x-two[n+2]-two[n+3] .. "," .. y+two[n+1]+two[n+3] .. ") {\\includegraphics[width=" .. textscale*two[n+2] .. "cm]{won.png}};")
tp("\\node at (" .. x-two[n+1]-two[n+3] .. "," .. y+two[n+2]+two[n+3] .. ") {\\includegraphics[width=" .. textscale*two[n+2] .. "cm]{won.png}};")
tp("\\node at (" .. x-two[n]+two[n+3] .. "," .. y+two[n+3] .. ") {\\includegraphics[width=" .. textscale*two[n+2] .. "cm]{won.png}};")
end
if n >= 10 then
return
end
fractal(n+1, c+1, x, y)
fractal(n+2, c+3, x-two[n+1], y)
fractal(n+2, c+3, x, y+two[n+1])
end
fractal(1, 1, 0, 0)
}
% \draw[->] (-8,8) -- (0,0);
\end{tikzpicture}
\end{document}
@seungwonpark
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment