Skip to content

Commit

Permalink
Very bad TikZ code...
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudomanifold committed May 6, 2024
1 parent 94427ff commit bd2533c
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion mantra/realize.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,59 @@ def realize_triangulation(data):
break

if not invalid:
print("Required", i, "tries:", X)
print("Required", i, "tries:", X / k)
plot(data["id"], top_level_simplices, X)
break


def plot(id, top_level_simplices, coordinates):
coordinates = coordinates.astype(float)
coordinates /= k

with open(f"/tmp/{id}.tex", "w") as f:
print(
r"""
\documentclass[crop, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat = 1.17,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3[
patch,
patch type = triangle,
patch table = {%""", file=f, end="")

for triangle in top_level_simplices:
a, b, c = triangle
print("\n", int(a - 1), int(b - 1), int(c - 1), r"\\", file=f,
end="")

print(r"""
},
draw = black,
fill = gray!50,
shader = flat,
]
table[row sep=\\] {
""", file=f, end="")

for coordinate in coordinates:
x, y, z = coordinate
print(f"{x:.4f} {y:.4f} {z:.4f}", r"\\", file=f, end="")

print(r"""
};
\end{axis}
\end{tikzpicture}
\end{document}
""", file=f)


if __name__ == "__main__":
with open(sys.argv[1]) as f:
triangulations = json.load(f)
Expand Down

0 comments on commit bd2533c

Please sign in to comment.