"""Draw a 32x32 pixel-art recurve bow. Run: python3 draw_bow.py"""

from pathlib import Path
from PIL import Image, ImageDraw


def draw_bow():
    image = Image.new("RGBA", (32, 32), (0, 0, 0, 0))
    draw = ImageDraw.Draw(image)
    outline = "#38262D"
    wood = "#AC5935"
    light = "#F2B967"

    # The string sits behind the recurved wooden limbs.
    draw.line([(23, 3), (21, 7), (21, 24), (23, 28)], fill=outline)
    draw.line([(22, 4), (20, 8), (20, 23), (22, 27)], fill="#E5D5AD")

    # Deliberately stepped contours: no antialiasing or intermediate resizing.
    limbs = [
        (23, 2), (22, 4), (19, 5), (18, 7), (15, 9),
        (12, 10), (10, 13), (10, 18), (12, 21),
        (15, 22), (18, 24), (19, 26), (22, 27), (23, 29),
    ]
    draw.line(limbs, fill=outline, width=5, joint="curve")
    draw.line(limbs, fill=wood, width=3, joint="curve")
    draw.line(
        [(22, 2), (21, 4), (18, 5), (17, 7), (14, 9),
         (11, 10), (9, 13)],
        fill=light, width=1,
    )
    draw.line(
        [(9, 18), (11, 21), (14, 22), (17, 24),
         (18, 26), (21, 27), (22, 29)],
        fill="#D98A45", width=1,
    )

    # Brass collars and a small leather-wrapped grip.
    draw.rectangle((8, 12, 12, 13), fill=outline)
    draw.rectangle((8, 18, 12, 19), fill=outline)
    draw.line((9, 12, 11, 12), fill="#F9D27D")
    draw.line((9, 18, 11, 18), fill="#DDA14F")
    draw.rectangle((8, 14, 12, 17), fill=outline)
    draw.rectangle((9, 14, 11, 17), fill="#634339")
    for y in (14, 16):
        draw.line((9, y, 11, y + 1), fill="#B08459")

    # Pale horn tips secure the bowstring.
    draw.point((23, 2), fill="#FFE1A0")
    draw.point((23, 29), fill="#FFE1A0")
    return image


if __name__ == "__main__":
    target = Path(__file__).with_name("archery_bow.png")
    bow = draw_bow()
    bow.save(target)
    assert bow.size == (32, 32) and bow.mode == "RGBA"
    print(f"Saved {target} (32x32 RGBA PNG)")
