Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
#!/usr/bin/env python3
"""Writes src/layouts.h: the four layouts of 144 tiles, from KMahjongg's layout files (GPL-2.0-or-later).
layouts.py DIR (DIR: KMahjongg's layouts folder: default.layout, the Turtle, and dragon, crab, spider)
A tile takes 2 x 2 cells of a layout file, so its place is in half tiles: x 0 to 31, y 0 to 15, and its layer z.
Each tile is two bytes, x then y + 16 z, ordered by layer, then x, then y: the order they are drawn in."""
import os
import sys
LAYOUTS = [("Turtle", "default"), ("Dragon", "dragon"), ("Crab", "crab"), ("Spider", "spider")]
def parse(path):
w = h = d = None
grid = []
for line in open(path).read().split("\n"):
line = line.rstrip()
if not line or line.startswith(("#", "kmahjongg")):
continue
if line[0] in "whd" and line[1:].isdigit():
w, h, d = (int(line[1:]) if line[0] == k else v for k, v in zip("whd", (w, h, d)))
continue
grid.append(line)
tiles = []
for z in range(d):
for y, row in enumerate(grid[z * h:(z + 1) * h]):
tiles += [(x, y, z) for x, ch in enumerate(row) if ch == "1"]
return sorted(tiles, key=lambda t: (t[2], t[0], t[1]))
def main():
out = ["/* Generated by tools/layouts.py from KMahjongg's layouts (GPL-2.0-or-later): each tile's x in half tiles,",
" * then its y in half tiles + 16 x its layer, in the order they're drawn (layer, x, y). */",
f"#define LAYOUTS {len(LAYOUTS)}",
"static const char *const layout_name[LAYOUTS] = {" + ", ".join(f'T("{n}")' for n, _ in LAYOUTS) + "};",
f"static const uint8_t layout_tiles[LAYOUTS][288] = {{"]
for name, f in LAYOUTS:
t = parse(os.path.join(sys.argv[1], f + ".layout"))
assert len(t) == 144, (name, len(t))
assert all(x < 32 and y < 16 and z < 8 for x, y, z in t)
print(f"{name}: 144 tiles, {max(z for *_, z in t) + 1} layers, x {min(x for x, *_ in t)} to {max(x for x, *_ in t)}")
b = [v for x, y, z in t for v in (x, y + 16 * z)]
out.append(f" {{ /* {name} */")
for k in range(0, 288, 24):
out.append(" " + ", ".join(str(v) for v in b[k:k + 24]) + ",")
out.append(" },")
out.append("};")
open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src", "layouts.h"), "w").write("\n".join(out) + "\n")
if __name__ == "__main__":
main()