Franck Pommereau

minor changes, added /examples

...@@ -11,4 +11,7 @@ ...@@ -11,4 +11,7 @@
11 *.snm 11 *.snm
12 *.synctex.gz 12 *.synctex.gz
13 *.toc 13 *.toc
14 +*.tikz
14 __pycache__ 15 __pycache__
16 +examples/codanim
17 +examples/out.tikz
......
...@@ -91,8 +91,7 @@ class CAniTikZ (CAni) : ...@@ -91,8 +91,7 @@ class CAniTikZ (CAni) :
91 return cleandoc(r"""\begin{{tikzpicture}}[{opt.tikzpicture}] 91 return cleandoc(r"""\begin{{tikzpicture}}[{opt.tikzpicture}]
92 {code} 92 {code}
93 \end{{tikzpicture}} 93 \end{{tikzpicture}}
94 - """).format(opt=opt, 94 + """).format(opt=opt, code="\n ".join(self.tikz(**tikz).splitlines()))
95 - code="\n ".join(self.tikz(**tikz).splitlines()))
96 95
97 class Pointer (CAniTikZ) : 96 class Pointer (CAniTikZ) :
98 def __init__ (self, data) : 97 def __init__ (self, data) :
...@@ -250,24 +249,17 @@ class Aggregate (CAniTikZ) : ...@@ -250,24 +249,17 @@ class Aggregate (CAniTikZ) :
250 else : 249 else :
251 yield val._node(opt) 250 yield val._node(opt)
252 prev = val 251 prev = val
253 - yield (r"\node[{opt.group},fit=({first}) ({last})] ({nodeid}) {{}};" 252 + first, last = (self@0).nodeid, (self@-1).nodeid
254 - r"").format(opt=opt, 253 + yield fr"\node[{opt.group},fit=({first}) ({last})] ({self.nodeid}) {{}};"
255 - nodeid=self.nodeid,
256 - first=(self@0).nodeid,
257 - last=(self@-1).nodeid)
258 def _ticks (self, opt) : 254 def _ticks (self, opt) :
259 - ticks_side = opt.aggregate.get("ticks", None) 255 + side = opt.aggregate.get("ticks", None)
260 - if not ticks_side : 256 + if not side :
261 return 257 return
262 - ticks_anchor = opp(ticks_side) 258 + anchor = opp(side)
263 for key, val in self._d.items() : 259 for key, val in self._d.items() :
264 - yield (r"\node[{opt.ticks},anchor={anchor}] at ({nodeid}.{side})" 260 + tick = self._tick(key, opt)
265 - r" {{{tick}}};" 261 + nodeid = val.nodeid
266 - r"").format(opt=opt, 262 + yield fr"\node[{opt.ticks},anchor={anchor}] at ({nodeid}.{side}) {{{tick}}};"
267 - anchor=ticks_anchor,
268 - nodeid=val.nodeid,
269 - side=ticks_side,
270 - tick=self._tick(key, opt))
271 def _tick (self, key, opt) : 263 def _tick (self, key, opt) :
272 return fr"{key}\strut" 264 return fr"{key}\strut"
273 def _highlight (self, opt) : 265 def _highlight (self, opt) :
...@@ -285,8 +277,8 @@ class Aggregate (CAniTikZ) : ...@@ -285,8 +277,8 @@ class Aggregate (CAniTikZ) :
285 def minstep (item) : 277 def minstep (item) :
286 return tuple(sorted(item[1])) 278 return tuple(sorted(item[1]))
287 for info, steps in sorted(mina.items(), key=minstep) : 279 for info, steps in sorted(mina.items(), key=minstep) :
288 - yield (r"\only<{steps}>{{" 280 + when = ",".join(str(s) for s in sorted(steps))
289 - r"").format(steps=",".join(str(s) for s in steps)) 281 + yield fr"\only<{when}>{{"
290 for key in info : 282 for key in info :
291 nodeid = (self@key).nodeid 283 nodeid = (self@key).nodeid
292 yield (fr"\draw[{access}] ({nodeid}.south west) rectangle" 284 yield (fr"\draw[{access}] ({nodeid}.south west) rectangle"
...@@ -302,8 +294,7 @@ class Aggregate (CAniTikZ) : ...@@ -302,8 +294,7 @@ class Aggregate (CAniTikZ) :
302 for (start, stop), info in sorted(anim.items(), key=firstlargest) : 294 for (start, stop), info in sorted(anim.items(), key=firstlargest) :
303 if all(v is None for _, v in info) : 295 if all(v is None for _, v in info) :
304 continue 296 continue
305 - yield (r"\only<{start}-{stop}>{{" 297 + yield fr"\only<{start}-{stop}>{{"
306 - r"").format(start=start, stop=stop)
307 for key, val in info : 298 for key, val in info :
308 if val is not None : 299 if val is not None :
309 nodeid = (self@key).nodeid 300 nodeid = (self@key).nodeid
......
1 +all: heap.pdf
2 +
3 +%.pdf: %.py tpl.tex
4 + ln -sf ../codanim .
5 + python $< > out.tikz
6 + latexmk -pdf tpl
7 + cp tpl.pdf $@
8 + latexmk -C tpl
9 +
10 +clean:
11 + rm -f $$(grep '^*' ../.gitignore)
No preview for this file type
1 +from codanim.data import Heap, Struct, Value
2 +
3 +h = Heap()
4 +p = h.new(Struct({"data": 1, "next": None}))
5 +p = h.new(Struct({"data": 2, "next": p}))
6 +p = h.new(Struct({"data": 3, "next": p}))
7 +h.new(Value(p, value={"yshift": "-1cm"}))
8 +
9 +print(h.tex(tikzpicture={"scale": .7}))
1 +\documentclass{beamer}
2 +
3 +\setbeamertemplate{navigation symbols}{}
4 +
5 +\usepackage{fancyvrb}
6 +\usepackage{adjustbox}
7 +
8 +\usepackage{tikz}
9 +\usetikzlibrary{arrows}
10 +\usetikzlibrary{fit}
11 +\usetikzlibrary{arrows.meta}
12 +\usetikzlibrary{positioning}
13 +
14 +\def\hl #1{{\setbox0=\hbox{#1}%
15 + \adjustbox{set vsize={\ht0}{\dp0}}{\hbox to \wd0{\hss\colorbox{yellow}{#1}\hss}}}}
16 +
17 +\def\hl #1{%
18 + \tikz[overlay,baseline,inner sep=1pt]
19 + \node[fill=yellow,anchor=text] {\color{yellow}#1};%
20 + #1%
21 +}
22 +
23 +\def\onlyhl #1{\only<#1>\hl}
24 +\def\onlyshow #1{\only<#1>}
25 +
26 +\begin{document}
27 +
28 +\begin{frame}
29 + \input{out.tikz}
30 +\end{frame}
31 +
32 +\end{document}