Files
Siro/scratch/draw_wrench.py
2026-06-15 01:37:41 +03:00

52 lines
2.0 KiB
Python

import math
from PIL import Image, ImageDraw
def draw_wrench(draw, color):
# Centers
cx_open, cy_open = 810, 160
cx_closed, cy_closed = 720, 250
# Draw shaft
# Direction vector from closed to open: (90, -90)
# Unit vector: dx = 0.7071, dy = -0.7071
# Perpendicular vector: px = 0.7071, py = 0.7071
dx, dy = 0.7071, -0.7071
px, py = 0.7071, 0.7071
half_w = 12
p1 = (cx_closed - half_w * px, cy_closed - half_w * py)
p2 = (cx_closed + half_w * px, cy_closed + half_w * py)
p3 = (cx_open + half_w * px, cy_open + half_w * py)
p4 = (cx_open - half_w * px, cy_open - half_w * py)
draw.polygon([p1, p2, p3, p4], fill=color)
# Draw open end outer circle
draw.ellipse([cx_open - 38, cy_open - 38, cx_open + 38, cy_open + 38], fill=color)
# Draw closed end outer circle
draw.ellipse([cx_closed - 30, cy_closed - 30, cx_closed + 30, cy_closed + 30], fill=color)
# Cut out the slot in open end (white polygon)
# Slot of width 22, length 50, starting at cx_open, cy_open and going in direction (dx, dy)
slot_half_w = 11
s1 = (cx_open - slot_half_w * px, cy_open - slot_half_w * py)
s2 = (cx_open + slot_half_w * px, cy_open + slot_half_w * py)
s3 = (cx_open + 50 * dx + slot_half_w * px, cy_open + 50 * dy + slot_half_w * py)
s4 = (cx_open + 50 * dx - slot_half_w * px, cy_open + 50 * dy - slot_half_w * py)
draw.polygon([s1, s2, s3, s4], fill=(255, 255, 255, 255))
# Draw a small circle at the base of the slot to make it round and clean
draw.ellipse([cx_open - 11, cy_open - 11, cx_open + 11, cy_open + 11], fill=(255, 255, 255, 255))
# Cut out closed end inner hole (white circle)
draw.ellipse([cx_closed - 15, cy_closed - 15, cx_closed + 15, cy_closed + 15], fill=(255, 255, 255, 255))
im = Image.open('scratch/logo_s_only.png')
draw = ImageDraw.Draw(im)
color = (29, 32, 47, 255)
draw_wrench(draw, color)
im.save('scratch/service_logo_test.png')
print("Saved service logo to scratch/service_logo_test.png")