"""SaiCore Stylus Palette icons."""
import os
from PIL import Image, ImageDraw, ImageFont
BASE = os.path.join(os.path.dirname(__file__), "..", "resources", "images", "stylusPalette")
DARK = (250, 250, 249) # cream-white for dark bg
INDIGO = (220, 38, 38) # red-600 primary
INDIGO_LT = (248, 113, 113) # red-400 light
WHITE = (255, 255, 255)
RED = (239, 68, 68)
T = (0, 0, 0, 0)
SZ = 42
def font(sz):
for n in ['C:/Windows/Fonts/segoeuib.ttf', 'C:/Windows/Fonts/arialbd.ttf']:
try: return ImageFont.truetype(n, sz)
except: pass
return ImageFont.load_default()
def new():
img = Image.new('RGBA', (SZ, SZ), T)
return img, ImageDraw.Draw(img)
def save(name, img):
img.save(os.path.join(BASE, name), 'PNG')
print(f" {name}")
def svg(name, body):
with open(os.path.join(BASE, name), 'w', encoding='utf-8') as f:
f.write(f'\n\n')
print(f" {name}")
def hx(c): return f'#{c[0]:02x}{c[1]:02x}{c[2]:02x}'
def pen(color, arrow=False):
img, dr = new()
dr.line([(10,32),(32,10)], fill=color, width=4)
dr.ellipse([29,7,35,13], fill=color)
dr.polygon([(7,35),(13,35),(10,32)], fill=color)
if arrow: dr.polygon([(34,34),(40,31),(40,37)], fill=INDIGO)
return img
def marker(color, arrow=False):
img, dr = new()
dr.line([(10,32),(32,10)], fill=color, width=6)
dr.rounded_rectangle([29,6,37,12], radius=2, fill=color)
dr.polygon([(6,36),(14,36),(10,40)], fill=color)
if arrow: dr.polygon([(34,34),(40,31),(40,37)], fill=INDIGO)
return img
def eraser(color, arrow=False):
img, dr = new()
dr.rounded_rectangle([10,14,32,28], radius=3, fill=color)
dr.rounded_rectangle([10,24,32,28], radius=2, fill=INDIGO)
if arrow: dr.polygon([(34,34),(40,31),(40,37)], fill=INDIGO)
return img
def run():
print("=== Stylus Palette ===")
for name, img in [
("pen.png", pen(DARK)), ("penOn.png", pen(INDIGO)),
("penArrow.png", pen(DARK, True)), ("penOnArrow.png", pen(INDIGO, True)),
("marker.png", marker(DARK)), ("markerOn.png", marker(INDIGO)),
("markerArrow.png", marker(DARK, True)), ("markerOnArrow.png", marker(INDIGO, True)),
("eraser.png", eraser(DARK)), ("eraserOn.png", eraser(INDIGO)),
("eraserArrow.png", eraser(DARK, True)), ("eraserOnArrow.png", eraser(INDIGO, True)),
]: save(name, img)
for base, w in [("pen", 4), ("marker", 6), ("eraser", 0)]:
for suffix, color in [("", DARK), ("On", INDIGO)]:
if base == "eraser":
body = f''
else:
body = f''
svg(f"{base}{suffix}.svg", body)
# Line
for suffix, color in [("", DARK), ("On", INDIGO)]:
img, dr = new()
dr.line([(8,32),(34,10)], fill=color, width=3)
dr.ellipse([5,29,11,35], fill=color)
dr.ellipse([31,7,37,13], fill=color)
save(f"line{suffix}.png", img)
# Text
for suffix, color in [("", DARK), ("On", INDIGO)]:
img, dr = new()
dr.text((14,8), "T", fill=color, font=font(24))
save(f"text{suffix}.png", img)
# Hand
for suffix, color, play in [("",DARK,False),("On",INDIGO,False),("Play",DARK,True),("PlayOn",INDIGO,True)]:
img, dr = new()
dr.rounded_rectangle([14,18,28,32], radius=4, fill=color)
for ox in [-6,-2,2,6]:
dr.rounded_rectangle([20+ox-1,10,20+ox+1,20], radius=1, fill=color)
dr.rounded_rectangle([10,22,14,28], radius=2, fill=color)
if play: dr.polygon([(30,18),(30,28),(37,23)], fill=WHITE)
save(f"hand{suffix}.png", img)
# Arrow
for suffix, color in [("", DARK), ("On", INDIGO)]:
img, dr = new()
dr.line([(8,34),(30,12)], fill=color, width=3)
dr.polygon([(30,12),(24,12),(30,18)], fill=color)
save(f"arrow{suffix}.png", img)
# Capture
for suffix, color in [("", DARK), ("On", INDIGO)]:
img, dr = new()
for i in range(8,34,6):
dr.line([i,8,min(i+3,34),8], fill=color, width=2)
dr.line([i,34,min(i+3,34),34], fill=color, width=2)
dr.line([8,i,8,min(i+3,34)], fill=color, width=2)
dr.line([34,i,34,min(i+3,34)], fill=color, width=2)
save(f"captureArea{suffix}.png", img)
# Laser
for suffix, color in [("", DARK), ("On", INDIGO)]:
img, dr = new()
dr.rounded_rectangle([8,19,26,23], radius=2, fill=color)
dr.ellipse([24,16,34,26], fill=RED)
save(f"laser{suffix}.png", img)
# Zoom
for suffix, direction in [("In","in"),("InOn","in"),("Out","out"),("OutOn","out")]:
color = INDIGO if "On" in suffix else DARK
suffix_color = color
img, dr = new()
dr.ellipse([8,8,28,28], outline=color, width=3)
dr.line([26,26,36,36], fill=color, width=3)
if direction == "in":
dr.line([14,18,22,18], fill=color, width=3)
dr.line([18,14,18,22], fill=color, width=3)
else:
dr.line([14,18,22,18], fill=color, width=3)
save(f"zoom{suffix}.png", img)
# Restore zoom
img, dr = new()
dr.ellipse([8,8,28,28], outline=DARK, width=3)
dr.line([26,26,36,36], fill=DARK, width=3)
dr.text((12,12), "1:1", fill=DARK, font=font(8))
save("restoreZoom.png", img)
# Snap
for suffix, color in [("", DARK), ("On", INDIGO)]:
svg(f"snap{suffix}.svg", f'')
if __name__ == "__main__":
run()