Files
wheel/scripts/compose_kfl_150_switch60.py

35 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from PIL import Image, ImageChops, ImageDraw, ImageFont
from pathlib import Path
out = Path(r'C:\projects\wheel\models\kfl_150_switch60_concept')
font = r'C:\Windows\Fonts\msyh.ttc'
title = ImageFont.truetype(font, 38)
normal = ImageFont.truetype(font, 24)
small = ImageFont.truetype(font, 21)
im = Image.new('RGB', (1920, 1200), 'white')
d = ImageDraw.Draw(im)
d.text((40, 18), '150 mm 轴 · 开关及接线预留 60 mm', fill='#1a304d', font=title)
d.text((40, 80), '轴 Ø12 × 150 mm;两端相同法兰;两块 8 mm 铝板,KFL001 反装', fill='#52657b', font=normal)
d.rounded_rectangle((40, 123, 1880, 177), radius=8, fill='#fff0eb')
d.text((55, 134), '概念示意:实际开关、轴承、接线和中心螺母未实测;不能认定实物可装', fill='#9b2b22', font=normal)
view = Image.open(out / 'side.png').convert('RGB').rotate(90, expand=True)
mask = ImageChops.difference(view, Image.new('RGB', view.size, 'white')).convert('L').point(lambda p: 255 if p > 12 else 0)
bounds = mask.getbbox()
if bounds:
view = view.crop(bounds)
view.thumbnail((1760, 550))
d.text((40, 196), '侧视:电机在左,方向盘侧在右', font=normal, fill='#243a55')
im.paste(view, (80 + (1760-view.width)//2, 230 + (550-view.height)//2))
d.line((40, 800, 1880, 800), fill='#d8e0e9', width=2)
rows = [
('绿色:开关及接线 60 mm 包络占位;灰色 KFL 和中心 Ø47 孔为假设。', '#405b4a'),
('电机侧和后轴承不动;前轴承与前法兰前移 25 mm,轴和轴套中心前移 12.5 mm。', '#243a55'),
('轴承中心距约 101.5 mm;开关包络到两侧内圈各约 13.5 mm;法兰与轴承座约 0.5 mm。', '#243a55'),
('轴两端进入法兰各约 13.5 mm,距底盘内表面各 6.5 mm;两端键长与强度未知。', '#243a55'),
('下方两根 2020 型材示意延长 25 mm;长度和连接方式未经实物验证。', '#243a55'),
('开关真实外形、白色拨片、接线弯曲、中心 M3 螺母及 KFL 凸起均未验证。', '#9b2b22'),
]
for i, (message, color) in enumerate(rows):
d.text((42, 819 + i * 43), message, font=small, fill=color)
im.save(out / '150mm轴_60mm开关_装配示意.png')