"""Draw a diagonal axe with integer pixels; export a transparent 32x32 PNG.

Requires Pillow. Run: python3 draw_axe.py
"""

from pathlib import Path

from PIL import Image, ImageDraw


OUT = Path(__file__).resolve().parent
image = Image.new("RGBA", (32, 32), (0, 0, 0, 0))
draw = ImageDraw.Draw(image)

INK = "#202533"
STEEL_DARK = "#465568"
STEEL = "#778b9b"
STEEL_LIGHT = "#afc5ce"
EDGE = "#e5f4ed"
WOOD_DARK = "#653c32"
WOOD = "#a5683e"
WOOD_LIGHT = "#d59a58"
LEATHER = "#46353a"


def poly(points, color):
    draw.polygon(points, fill=color)


# The haft runs southwest to northeast, behind the head.
poly([(4, 26), (20, 10), (23, 10), (25, 12), (25, 14),
      (10, 29), (7, 29), (4, 27)], INK)
poly([(5, 26), (21, 10), (24, 13), (9, 28), (7, 28)], WOOD_DARK)
poly([(5, 26), (21, 10), (23, 12), (8, 27), (7, 28)], WOOD)
draw.line([(6, 25), (20, 11)], fill=WOOD_LIGHT, width=1)
draw.line([(10, 25), (20, 15)], fill=WOOD_DARK, width=1)

# Three dark leather wraps near the grip.
for x, y in [(7, 24), (10, 21), (13, 18)]:
    draw.line([(x, y), (x + 3, y + 2)], fill=LEATHER, width=1)
    draw.point((x, y), fill="#92705a")
draw.line([(5, 26), (7, 28)], fill=WOOD_LIGHT, width=1)

# Short, squared poll on the far side of the eye.
poly([(22, 9), (24, 9), (29, 14), (29, 16), (26, 19),
      (24, 18), (20, 14)], INK)
poly([(23, 10), (28, 15), (26, 17), (21, 12)], STEEL_DARK)
draw.line([(24, 11), (28, 15)], fill=STEEL_LIGHT, width=1)
draw.line([(25, 17), (27, 15)], fill=STEEL, width=1)

# Broad curved blade: crisp stepped contours, no antialiasing.
poly([(13, 2), (16, 2), (16, 5), (18, 7), (22, 9),
      (24, 11), (24, 13), (21, 16), (19, 15), (17, 18),
      (14, 19), (11, 19), (8, 17), (6, 15), (4, 11),
      (4, 9), (7, 6), (10, 4)], INK)
poly([(13, 3), (15, 3), (15, 6), (18, 9), (21, 10),
      (23, 12), (21, 14), (19, 13), (16, 17), (13, 18),
      (11, 18), (8, 16), (6, 13), (5, 10), (8, 7),
      (11, 5)], STEEL)

# Shadow below the neck gives the blade some thickness.
poly([(10, 15), (13, 16), (16, 15), (18, 12), (21, 12),
      (23, 12), (21, 14), (19, 13), (16, 17), (13, 18),
      (11, 18), (8, 16), (6, 13)], STEEL_DARK)

# Light bevel follows the curved outer cutting edge.
poly([(13, 3), (15, 3), (12, 6), (9, 8), (7, 11),
      (8, 14), (11, 17), (13, 18), (11, 18), (8, 16),
      (6, 13), (5, 10), (8, 7), (11, 5)], STEEL_LIGHT)
draw.line([(13, 3), (10, 5), (8, 7), (5, 10)], fill=EDGE)
draw.line([(5, 11), (7, 15), (10, 17)], fill=EDGE)

# A small highlight on the blade face and a band around the eye.
draw.line([(11, 8), (14, 5)], fill=STEEL_LIGHT)
draw.line([(12, 9), (14, 7)], fill=STEEL_LIGHT)
draw.line([(19, 9), (22, 12)], fill=STEEL_LIGHT)
draw.line([(20, 9), (23, 12)], fill=STEEL_DARK)
draw.point((21, 12), fill=INK)

image.save(OUT / "diagonal_axe_32x32.png")
image.resize((512, 512), Image.Resampling.NEAREST).save(
    OUT / "diagonal_axe_preview.png"
)
print(f"Saved {OUT / 'diagonal_axe_32x32.png'} (32x32 RGBA)")
