"""Palette-aware desktop toolbar glyphs."""

from PIL import Image, ImageDraw


def icon(name, color, size=24):
    """Palette-aware toolbar glyphs."""
    img = Image.new("RGBA", (72,72))
    draw = ImageDraw.Draw(img)
    def line(*points):
        draw.line([(3*x,3*y) for x,y in points], fill=color, width=5, joint="curve")
    def arc(box, start, end):
        draw.arc(tuple(3*x for x in box), start, end, fill=color, width=5)
    if name == "open":
        line((3,19),(3,6),(9,6),(11,8),(21,8),(21,19),(3,19))
        line((3,10),(19,10))
    elif name == "save":
        line((12,3),(12,15))
        line((8,11),(12,15),(16,11))
        line((4,16),(4,21),(20,21),(20,16))
    elif name == "run":
        line((5,12),(20,12)); line((14,6),(20,12),(14,18))
    elif name == "reset":
        arc((5,5,20,20), -105, 174)
        line((4,7),(4,12),(9,12))
    elif name == "edges":
        line((4,7),(12,3),(20,7),(20,17),(12,21),(4,17),(4,7),(12,11),(20,7))
        line((12,11),(12,21))
    elif name == "colors":
        for x,y in ((7,7),(16,7),(7,16),(16,16)):
            arc((x-2.5,y-2.5,x+2.5,y+2.5), 0, 360)
    elif name == "sun":
        arc((8,8,16,16), 0, 360)
        for x,y,ex,ey in [(12,2,12,5),(12,19,12,22),(2,12,5,12),(19,12,22,12),
                          (4,4,6,6),(18,18,20,20),(4,20,6,18),(18,6,20,4)]:
            line((x,y),(ex,ey))
    else:
        arc((4,4,21,21), 32, 246)
        arc((10,2,23,15), 104, 186)
    return img.resize((size,size), Image.Resampling.LANCZOS)
