Skip to content

Instantly share code, notes, and snippets.

@dohyunkim
Last active September 5, 2025 05:51
Show Gist options
  • Select an option

  • Save dohyunkim/7054f5b3316a49bfbc5864ca114a9deb to your computer and use it in GitHub Desktop.

Select an option

Save dohyunkim/7054f5b3316a49bfbc5864ca114a9deb to your computer and use it in GitHub Desktop.
wave the text with luamplib
\documentclass[margin=5pt]{standalone}
\usepackage{luamplib}
\begin{document}
\setbox0\vbox{\sffamily\Large
\hsize=10cm \parindent=0pt\parskip=5pt
\begin{center}\LARGE Episode IV\end{center}
\centerline{A NEW HOPE}
It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.
During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet.
Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy\dots.
}
\directlua{
local hsize
local function starwars(x,y)
local depth = 250
local z = depth / (depth + y)
x = x - (hsize / 2)
x, y = x * z, y * z
x = x + (hsize / 2)
return ("(\csstring\%f,\csstring\%f)"):format(x,y)
end
local function wave (x,y)
y = y + 12 * math.sin(2*math.pi/hsize * x)
return ("(\csstring\%f,\csstring\%f)"):format(x,y)
end
function wavethepath(instance, p, wd)
hsize = wd
local wave = starwars
local t = luamplib.instances[instance]:get_path (p)
table.insert(t, t[1])
local tt = {"filldraw"}
for i=1, \csstring\#t-1 do
table.insert(tt, wave(t[i][1],t[i][2]))
table.insert(tt, ".. controls")
table.insert(tt, wave(t[i][5],t[i][6]))
table.insert(tt, "and")
table.insert(tt, wave(t[i+1][3],t[i+1][4]))
table.insert(tt, "..")
end
table.insert(tt, "cycle")
return table.concat(tt, " ")
end
}
\begin{mplibcode}[myinstance]
beginfig(1)
picture pic; pic = mpliboutlinetext.p ("\box0");
wd := xpart lrcorner pic;
j:=0;
for item within pic :
path p; p = pathpart item;
runscript("return wavethepath('myinstance', 'p', "&decimal wd&")")
if incr(j) < length pic :
withpostscript "collect"
fi
;
endfor
endfig;
\end{mplibcode}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment