"""Draw a diagonal 32 x 32 pixel-art axe. Requires Pillow.

Run: python3 draw_axe.py
All coordinates are native pixels; no antialiasing is used.
"""

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 = "#202838"
WOOD_DARK = "#70402f"
WOOD = "#b5733c"
WOOD_LIGHT = "#e4aa62"
STEEL_DARK = "#4d657b"
STEEL = "#829cae"
STEEL_LIGHT = "#bed5df"
EDGE = "#edf6f7"

# The oak shaft runs from the lower-left grip to the upper-right socket.
draw.polygon(
    [(3, 27), (21, 9), (23, 8), (25, 10), (25, 12),
     (7, 30), (5, 30), (3, 28)], fill=INK
)
draw.polygon(
    [(4, 27), (22, 9), (24, 10), (24, 11),
     (6, 29), (5, 29), (4, 28)], fill=WOOD_DARK
)
draw.polygon(
    [(4, 27), (22, 9), (23, 10), (5, 28)], fill=WOOD
)
draw.line([(5, 26), (21, 10)], fill=WOOD_LIGHT, width=1)

# Three dark leather bands at the butt, each perpendicular to the shaft.
for x, y in [(6, 25), (8, 23), (10, 21)]:
    draw.line([(x, y), (x + 2, y + 2)], fill=WOOD_DARK, width=1)
    draw.point((x, y), fill=INK)

# A broad, curved cutting blade and a short squared poll.
draw.polygon(
    [(11, 2), (14, 3), (17, 6), (18, 7), (21, 7),
     (22, 6), (24, 6), (29, 11), (29, 13), (26, 16),
     (24, 16), (20, 12), (18, 13), (17, 16), (14, 19),
     (10, 17), (7, 14), (5, 10), (6, 7), (8, 4)], fill=INK
)
draw.polygon(
    [(11, 3), (13, 4), (16, 7), (18, 8), (21, 8),
     (22, 7), (24, 7), (28, 11), (28, 13), (25, 15),
     (20, 10), (17, 12), (16, 15), (14, 18),
     (11, 16), (8, 13), (6, 10), (7, 7), (9, 5)], fill=STEEL
)

# Facets on the forged steel, shaded toward the lower-right.
draw.polygon(
    [(14, 7), (18, 9), (20, 9), (19, 11), (16, 13),
     (15, 16), (14, 17), (11, 15), (10, 13)], fill=STEEL_DARK
)
draw.polygon(
    [(11, 4), (13, 5), (16, 8), (18, 9),
     (15, 10), (11, 9), (8, 10), (8, 8)], fill=STEEL_LIGHT
)

# Bright continuous bevel follows the stepped outer cutting edge.
draw.line([(11, 3), (8, 6), (7, 8), (6, 10), (8, 13),
           (11, 16), (14, 18)], fill=EDGE, width=1)
draw.line([(9, 7), (8, 10), (10, 13), (13, 16)],
          fill=STEEL_LIGHT, width=1)

# Diagonal socket, dark lower rim, and one warm metal pin.
draw.polygon([(21, 8), (23, 7), (27, 11), (25, 13)], fill=STEEL_DARK)
draw.line([(23, 8), (26, 11)], fill=STEEL_LIGHT, width=1)
draw.line([(21, 9), (25, 13)], fill=INK, width=1)
draw.point((23, 10), fill=WOOD_LIGHT)
draw.line([(26, 14), (28, 12)], fill=STEEL_LIGHT, width=1)

image.save(OUT / "axe.png")
image.resize((512, 512), Image.Resampling.NEAREST).save(OUT / "axe_preview.png")
print(f"Saved {OUT / 'axe.png'} (32 x 32 RGBA)")
