Files
wheel/scripts/compose_kfl_same_flange.py

34 lines
2.3 KiB
Python
Raw Permalink 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
root = Path(r'C:\projects\wheel\models')
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, 1370), 'white')
d = ImageDraw.Draw(im)
d.text((40, 18), '两端相同法兰:100 mm 与 120 mm 轴布局比较', fill='#1a304d', font=title)
d.text((40, 80), '两端法兰:Ø57 × 4 mm 底盘、Ø30 × 20 mm 凸台;6 孔 PCD48', fill='#52657b', font=normal)
d.rounded_rectangle((40, 123, 1880, 177), radius=8, fill='#fff0eb')
d.text((55, 134), '均为概念示意:KFL 和开关的真实结构未建模,不能证明实物装配通过', fill='#9b2b22', font=normal)
def panel(path, box):
view = Image.open(path).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((box[2]-box[0],box[3]-box[1]))
im.paste(view, (box[0] + (box[2]-box[0]-view.width)//2, box[1]))
d.text((40, 196), 'A:100 mm 轴;在此布局下,电机侧插入 12 mm,方向盘侧只插入 2 mm', font=normal, fill='#243a55')
panel(root / 'kfl_same_flange_100' / 'side.png', (35, 235, 1885, 605))
d.text((40, 620), 'B:120 mm 轴;同一布局下方向盘侧插入 20 mm,仅为对比假设', font=normal, fill='#243a55')
panel(root / 'kfl_same_flange_120' / 'side.png', (35, 660, 1885, 1030))
d.line((40, 1055, 1880, 1055), fill='#d8e0e9', width=2)
d.text((42, 1075), '绿色半透明体:50 mm 开关包络占位,内部 Ø47 孔仅为示意;白色回正件未建模。', font=small, fill='#405b4a')
d.text((42, 1116), 'KFL 凸起、铝板孔、端面键槽和电机中心螺母均未实测;两侧轴承和法兰间隙示意 0.5 mm。', font=small, fill='#46586b')
d.text((42, 1157), '120 mm 是当前布局的比较长度,不是已验证的必需长度或强度结论。', font=small, fill='#9b2b22')
d.text((42, 1198), '原铝转接盘 STEP 孔径约 Ø4.23 mm,法兰 M5 通孔无法直接使用 M5 螺丝贯穿原盘。', font=small, fill='#46586b')
im.save(root / 'kfl_same_flange_100' / '两端相同法兰_装配示意.png')