"""Draw a diagonal 16x16 axe. Run with: python3 draw_axe.py

Requires Pillow (pip install pillow). All marks are whole pixels;
the enlarged preview uses nearest-neighbor scaling.
"""

from pathlib import Path

from PIL import Image


PALETTE = {
    ".": (0, 0, 0, 0),
    "#": "#202735",  # outline
    "H": "#f1fbff",  # cutting-edge highlight
    "L": "#c5dce3",  # bright steel
    "S": "#8daab8",  # steel
    "M": "#526b80",  # shaded steel
    "P": "#71899b",  # back of the axe head
    "T": "#805033",  # handle in shadow / grip
    "W": "#dfaa62",  # lit wood
    "O": "#ad703e",  # wood shadow
}

PIXELS = (
    "................",
    ".......##.......",
    "......#HH#......",
    ".....#HLLL#.....",
    ".....#HLLSM##...",
    ".....#HLSSMTM#..",
    "......#SSSMTMP#.",
    ".......##TMMP#..",
    "........#WM##...",
    ".......#WO#.....",
    "......#WO#......",
    ".....#WO#.......",
    "....#TO#........",
    "...#WO#.........",
    "....##..........",
    "................",
)


def main():
    assert len(PIXELS) == 16 and all(len(row) == 16 for row in PIXELS)
    sprite = Image.new("RGBA", (16, 16))
    for y, row in enumerate(PIXELS):
        for x, symbol in enumerate(row):
            color = PALETTE[symbol]
            if isinstance(color, str):
                color = tuple(bytes.fromhex(color[1:])) + (255,)
            sprite.putpixel((x, y), color)

    output = Path(__file__).resolve().parent
    sprite.save(output / "axe_16x16.png")
    sprite.resize((512, 512), Image.Resampling.NEAREST).save(
        output / "axe_preview.png"
    )
    print("Exported axe_16x16.png and axe_preview.png")


if __name__ == "__main__":
    main()
