Skip to content

Instantly share code, notes, and snippets.

View HexDecimal's full-sized avatar

Kyle Benesch HexDecimal

View GitHub Profile
@HexDecimal
HexDecimal / tcod_sdl_example.py
Last active January 31, 2022 04:46
Example of the experimental SDL port in python-tcod.
import tcod
import tcod.render
# Font file is at https://github.com/libtcod/python-tcod/blob/4385a4d65f20a6e1eefc8ab0a243c0d869adec45/fonts/libtcod/dejavu16x16_gs_tc.png
FONT = "dejavu16x16_gs_tc.png"
tileset = tcod.tileset.load_tilesheet(FONT, 32, 8, tcod.tileset.CHARMAP_TCOD)
console = tcod.Console(20, 8)
console.print(0, 0, "Hello World")
sdl_window = tcod.sdl.video.new_window(
console.width * tileset.tile_width,
@HexDecimal
HexDecimal / tcod_map_benchmarks.py
Last active November 2, 2020 19:22
Benchmarks for setting map attributes in python-tcod.
"""Python-tcod map attribute benchmarks for pytest-benchmark.
This test should be run with the Python optimize flag set.
Not doing so will slow down tcod.map_set_properties since it will emit
warnings on every call.
"""
import tcod
import numpy as np
tile_list = [
@HexDecimal
HexDecimal / rot45.py
Created February 18, 2020 02:21
Rotate a NumPy array by 45 degrees.
# To the extent possible under law, Kyle Stewart has waived all copyright and
# related or neighboring rights to this work.
# This work is published from: United States.
import functools
from typing import Any, Tuple
import numpy as np # type: ignore
@functools.lru_cache
@HexDecimal
HexDecimal / starfield.py
Last active October 19, 2019 08:30
Starfield visualization (python-tcod)
#!/usr/bin/env python3
# To the extent possible under law, the Kyle Stewart has waived all
# copyright and related or neighboring rights for starfield.py. This work is
# published from: United States.
# https://creativecommons.org/publicdomain/zero/1.0/
import random
import math
import tcod
import tcod.event