Franck Pommereau

minor changes, added /examples

......@@ -11,4 +11,7 @@
*.snm
*.synctex.gz
*.toc
*.tikz
__pycache__
examples/codanim
examples/out.tikz
......
......@@ -91,8 +91,7 @@ class CAniTikZ (CAni) :
return cleandoc(r"""\begin{{tikzpicture}}[{opt.tikzpicture}]
{code}
\end{{tikzpicture}}
""").format(opt=opt,
code="\n ".join(self.tikz(**tikz).splitlines()))
""").format(opt=opt, code="\n ".join(self.tikz(**tikz).splitlines()))
class Pointer (CAniTikZ) :
def __init__ (self, data) :
......@@ -250,24 +249,17 @@ class Aggregate (CAniTikZ) :
else :
yield val._node(opt)
prev = val
yield (r"\node[{opt.group},fit=({first}) ({last})] ({nodeid}) {{}};"
r"").format(opt=opt,
nodeid=self.nodeid,
first=(self@0).nodeid,
last=(self@-1).nodeid)
first, last = (self@0).nodeid, (self@-1).nodeid
yield fr"\node[{opt.group},fit=({first}) ({last})] ({self.nodeid}) {{}};"
def _ticks (self, opt) :
ticks_side = opt.aggregate.get("ticks", None)
if not ticks_side :
side = opt.aggregate.get("ticks", None)
if not side :
return
ticks_anchor = opp(ticks_side)
anchor = opp(side)
for key, val in self._d.items() :
yield (r"\node[{opt.ticks},anchor={anchor}] at ({nodeid}.{side})"
r" {{{tick}}};"
r"").format(opt=opt,
anchor=ticks_anchor,
nodeid=val.nodeid,
side=ticks_side,
tick=self._tick(key, opt))
tick = self._tick(key, opt)
nodeid = val.nodeid
yield fr"\node[{opt.ticks},anchor={anchor}] at ({nodeid}.{side}) {{{tick}}};"
def _tick (self, key, opt) :
return fr"{key}\strut"
def _highlight (self, opt) :
......@@ -285,8 +277,8 @@ class Aggregate (CAniTikZ) :
def minstep (item) :
return tuple(sorted(item[1]))
for info, steps in sorted(mina.items(), key=minstep) :
yield (r"\only<{steps}>{{"
r"").format(steps=",".join(str(s) for s in steps))
when = ",".join(str(s) for s in sorted(steps))
yield fr"\only<{when}>{{"
for key in info :
nodeid = (self@key).nodeid
yield (fr"\draw[{access}] ({nodeid}.south west) rectangle"
......@@ -302,8 +294,7 @@ class Aggregate (CAniTikZ) :
for (start, stop), info in sorted(anim.items(), key=firstlargest) :
if all(v is None for _, v in info) :
continue
yield (r"\only<{start}-{stop}>{{"
r"").format(start=start, stop=stop)
yield fr"\only<{start}-{stop}>{{"
for key, val in info :
if val is not None :
nodeid = (self@key).nodeid
......
all: heap.pdf
%.pdf: %.py tpl.tex
ln -sf ../codanim .
python $< > out.tikz
latexmk -pdf tpl
cp tpl.pdf $@
latexmk -C tpl
clean:
rm -f $$(grep '^*' ../.gitignore)
No preview for this file type
from codanim.data import Heap, Struct, Value
h = Heap()
p = h.new(Struct({"data": 1, "next": None}))
p = h.new(Struct({"data": 2, "next": p}))
p = h.new(Struct({"data": 3, "next": p}))
h.new(Value(p, value={"yshift": "-1cm"}))
print(h.tex(tikzpicture={"scale": .7}))
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{fancyvrb}
\usepackage{adjustbox}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{fit}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\def\hl #1{{\setbox0=\hbox{#1}%
\adjustbox{set vsize={\ht0}{\dp0}}{\hbox to \wd0{\hss\colorbox{yellow}{#1}\hss}}}}
\def\hl #1{%
\tikz[overlay,baseline,inner sep=1pt]
\node[fill=yellow,anchor=text] {\color{yellow}#1};%
#1%
}
\def\onlyhl #1{\only<#1>\hl}
\def\onlyshow #1{\only<#1>}
\begin{document}
\begin{frame}
\input{out.tikz}
\end{frame}
\end{document}