Files
cuotibiye/report/make_diagram4.py
T

277 lines
12 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.
# -*- coding: utf-8 -*-
"""初中版 PRD 的两张示意图。
prd_flow_j.png 九步主流程(3×3 蛇形)
prd_wire_j.png 三屏线框:学生端今日 6 道 / 讲给 AI 听 / 可上交 A4
画布逻辑宽 680,超采样 4 倍 → 2720px,插入 16cm 后正文约 6.8pt。
"""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
HERE = Path(__file__).parent
W = 680
S = 4
INK = (34, 34, 34)
MUTED = (120, 120, 120)
ACCENT = (179, 39, 45)
LINE = (208, 208, 208)
CARD = (250, 250, 250)
PARENT = (179, 39, 45)
CHILD = (46, 110, 74)
SYS = (90, 90, 90)
TEACHER = (37, 79, 138)
FONT_REG = "C:/Windows/Fonts/msyh.ttc"
FONT_BOLD = "C:/Windows/Fonts/msyhbd.ttc"
def font(size, bold=False):
return ImageFont.truetype(FONT_BOLD if bold else FONT_REG, int(size * S))
def txt(d, xy, s, size=10, bold=False, fill=INK):
d.text((xy[0] * S, xy[1] * S), s, font=font(size, bold), fill=fill)
def center(d, box, s, size=10, bold=False, fill=INK):
f = font(size, bold)
l, t, r, b = [v * S for v in box]
tw = d.textlength(s, font=f)
d.text(((l + r - tw) / 2, (t + b - size * S * 1.35) / 2), s, font=f, fill=fill)
def rect(d, box, fill=None, outline=None, w=1, r=6):
b = tuple(v * S for v in box)
d.rounded_rectangle(b, radius=r * S, fill=fill, outline=outline, width=int(w * S))
def line(d, p1, p2, fill=ACCENT, w=1.4):
d.line((p1[0] * S, p1[1] * S, p2[0] * S, p2[1] * S), fill=fill, width=int(w * S))
def arrow(d, p1, p2, fill=ACCENT, w=1.4):
line(d, p1, p2, fill, w)
dx, dy = p2[0] - p1[0], p2[1] - p1[1]
L = max((dx * dx + dy * dy) ** 0.5, 1e-6)
ux, uy = dx / L, dy / L
size = 6
px, py = -uy, ux
d.polygon(
[
(p2[0] * S, p2[1] * S),
((p2[0] - ux * size + px * size * 0.5) * S, (p2[1] - uy * size + py * size * 0.5) * S),
((p2[0] - ux * size - px * size * 0.5) * S, (p2[1] - uy * size - py * size * 0.5) * S),
],
fill=fill,
)
def fit(s, max_w, size, bold=False):
f = font(size, bold)
d = ImageDraw.Draw(Image.new("RGB", (10, 10)))
while size > 6 and d.textlength(s, font=f) > max_w * S:
size -= 0.5
f = font(size, bold)
return size
# ------------------------------------------------------------------ 流程图
def make_flow():
ROLE_COLOR = {"学生": CHILD, "系统": SYS, "老师": TEACHER, "家长": PARENT}
steps = [
("学生", "拍照收题", "一次拍整页,最多 4 张"),
("系统", "切题 + 批改", "逐题判对错,标出错的"),
("学生", "标错因", "会但错了 / 真不会 / 粗心"),
("系统", "只错三次才入库", "第一次错 → 观察,不进队列"),
("系统", "今日 6 道", "21:00 推送,按知识点排"),
("学生", "重做 · 连对两次", "同题两次全对才算记住"),
("学生", "讲给 AI 听", "AI 扮演没听懂的同学追问"),
("系统", "毕业 → 已消灭", "连对两次 + 讲清"),
("系统", "周日 · A4 错题本", "可打印、可上交、可签字"),
]
MARGIN, GAP = 18, 18
CW = (W - 2 * MARGIN - 2 * GAP) / 3
CH, RGAP = 112, 52
TOP = 46
H = TOP + 3 * CH + 2 * RGAP + 56
img = Image.new("RGB", (W * S, int(H * S)), "white")
d = ImageDraw.Draw(img)
txt(d, (MARGIN, 14), "一道错题在初中生手里的九步", 13, True, INK)
txt(d, (MARGIN, 32), "从拍下来到交上去,全程 15 分钟,一周一次 A4", 8.5, False, MUTED)
boxes = []
for i, (role, title, sub) in enumerate(steps):
row, col = divmod(i, 3)
if row % 2 == 1:
col = 2 - col
x = MARGIN + col * (CW + GAP)
y = TOP + row * (CH + RGAP)
color = ROLE_COLOR[role]
rect(d, (x, y, x + CW, y + CH), fill=CARD, outline=LINE, w=0.8, r=8)
d.rectangle((x * S, y * S, (x + 3) * S, (y + CH) * S), fill=color)
txt(d, (x + 10, y + 8), f"第 {i + 1} 步", 7.5, False, MUTED)
ts = fit(title, CW - 20, 11, True)
txt(d, (x + 10, y + 24), title, ts, True, INK)
txt(d, (x + 10, y + 46), sub, fit(sub, CW - 20, 8.5), False, MUTED)
rect(d, (x + 10, y + CH - 22, x + 10 + 30, y + CH - 8), fill=None, outline=color, w=0.7, r=3)
center(d, (x + 10, y + CH - 22, x + 40, y + CH - 8), role, 7, False, color)
boxes.append((x, y, x + CW, y + CH))
for i in range(len(boxes) - 1):
a, b = boxes[i], boxes[i + 1]
row_a = i // 3
row_b = (i + 1) // 3
if row_a == row_b:
if row_a % 2 == 0:
arrow(d, (a[2] + 1, (a[1] + a[3]) / 2), (b[0] - 1, (b[1] + b[3]) / 2))
else:
arrow(d, (a[0] - 1, (a[1] + a[3]) / 2), (b[2] + 1, (b[1] + b[3]) / 2))
else:
cx = (b[0] + b[2]) / 2
arrow(d, (cx, a[3] + 1), (cx, b[1] - 1))
y0 = TOP + 3 * CH + 2 * RGAP + 6
rect(d, (MARGIN, y0, W - MARGIN, y0 + 44), fill=(251, 244, 243), outline=None, r=6)
txt(d, (MARGIN + 10, y0 + 7), "三条硬约束", 8.5, True, ACCENT)
txt(d, (MARGIN + 74, y0 + 7), "① 一次只推 6 道(多了不做) ② 第 6 道答完就结束,不追加 ③ 终点是纸——能打印、能交给老师", 8.2, False, INK)
txt(d, (MARGIN + 10, y0 + 25), "角色", 8.5, True, ACCENT)
txt(d, (MARGIN + 74, y0 + 25), "孩子自己拍、自己标错因、自己讲给 AI 听;家长只看周报上的三个数字;老师只收到那张 A4", 8.2, False, INK)
img = img.resize((W * 2, int(H * 2)), Image.LANCZOS) if False else img.resize((W * S, int(H * S)), Image.LANCZOS)
out = HERE / "prd_flow_j.png"
img.save(out)
print("已生成", out.name, img.size)
# ------------------------------------------------------------------ 线框图
def make_wire():
MARGIN, GAP = 18, 16
PW = (W - 2 * MARGIN - 2 * GAP) / 3
PH = 330
TOP = 62
H = TOP + PH + 86
img = Image.new("RGB", (W * S, int(H * S)), "white")
d = ImageDraw.Draw(img)
txt(d, (MARGIN, 14), "三个核心页面", 13, True, INK)
txt(d, (MARGIN, 32), "学生端今日 6 道 / 讲给 AI 听 / 周日可上交的 A4", 8.5, False, MUTED)
xs = [MARGIN, MARGIN + PW + GAP, MARGIN + 2 * (PW + GAP)]
# ---------- A 学生端今日
x = xs[0]
rect(d, (x, TOP, x + PW, TOP + PH), fill="white", outline=LINE, w=1, r=10)
d.rectangle((x * S, TOP * S, (x + PW) * S, (TOP + 26) * S), fill=(245, 245, 245))
txt(d, (x + 10, TOP + 6), "错题毕业", 9, True, INK)
txt(d, (x + PW - 44, TOP + 7), "周三 21:04", 7, False, MUTED)
txt(d, (x + 12, TOP + 38), "今天 6 道", 11, True, INK)
txt(d, (x + 88, TOP + 42), "约 15 分钟", 7.5, False, MUTED)
rows = [
("数学 · 二次函数", "错 2 次 · 待复习"),
("数学 · 全等三角形", "错 3 次 · 待复习"),
("数学 · 分式方程", "错 1 次 · 待复习"),
("物理 · 压强", "错 2 次 · 待复习"),
("物理 · 电路", "错 3 次 · 待复习"),
("英语 · 定语从句", "错 2 次 · 待复习"),
]
for i, (t1, t2) in enumerate(rows):
y = TOP + 62 + i * 34
rect(d, (x + 10, y, x + PW - 10, y + 30), fill=CARD, outline=LINE, w=0.6, r=5)
txt(d, (x + 16, y + 4), t1, 8, True, INK)
txt(d, (x + 16, y + 17), t2, 7, False, MUTED)
rect(d, (x + 10, TOP + PH - 40, x + PW - 10, TOP + PH - 12), fill=ACCENT, outline=None, r=6)
center(d, (x + 10, TOP + PH - 40, x + PW - 10, TOP + PH - 12), "开始(6/6)", 9.5, True, (255, 255, 255))
# ---------- B 讲给 AI 听
x = xs[1]
rect(d, (x, TOP, x + PW, TOP + PH), fill="white", outline=LINE, w=1, r=10)
d.rectangle((x * S, TOP * S, (x + PW) * S, (TOP + 26) * S), fill=(245, 245, 245))
txt(d, (x + 10, TOP + 6), "讲给 AI 听", 9, True, INK)
txt(d, (x + PW - 40, TOP + 7), "第 5/6", 7, False, MUTED)
txt(d, (x + 12, TOP + 38), "数学 · 分式方程", 8, False, MUTED)
# AI 气泡
rect(d, (x + 10, TOP + 54, x + PW - 34, TOP + 96), fill=(243, 243, 243), outline=None, r=8)
txt(d, (x + 18, TOP + 60), "我没看懂:", 8, True, INK)
txt(d, (x + 18, TOP + 74), "为什么两边要先乘 x(x-1)?", 8, False, INK)
# 学生气泡(语音)
rect(d, (x + 34, TOP + 106, x + PW - 10, TOP + 152), fill=(232, 242, 236), outline=None, r=8)
txt(d, (x + 42, TOP + 112), "因为去分母…", 8, True, INK)
for i in range(11):
h = 4 + (i % 4) * 2.2
xx = x + 42 + i * 6
d.rectangle((xx * S, (TOP + 132 - h / 2) * S, (xx + 3) * S, (TOP + 132 + h / 2) * S), fill=CHILD)
txt(d, (x + PW - 34, TOP + 136), "0:23", 6.5, False, MUTED)
# AI 追问
rect(d, (x + 10, TOP + 162, x + PW - 34, TOP + 200), fill=(243, 243, 243), outline=None, r=8)
txt(d, (x + 18, TOP + 168), "那下次遇到分式方程,", 7.8, False, INK)
txt(d, (x + 18, TOP + 182), "第一步先做什么?", 7.8, False, INK)
txt(d, (x + 12, TOP + 212), "只追问 2 轮,可随时跳过 ›", 7, False, MUTED)
rect(d, (x + 10, TOP + PH - 40, x + PW - 10, TOP + PH - 12), fill=OUTLINE_FILL, outline=None, r=6)
center(d, (x + 10, TOP + PH - 40, x + PW - 10, TOP + PH - 12), "说完了", 9.5, True, (255, 255, 255))
# ---------- C A4 错题本
x = xs[2]
rect(d, (x, TOP, x + PW, TOP + PH), fill="white", outline=LINE, w=1, r=10)
d.rectangle((x * S, TOP * S, (x + PW) * S, (TOP + 26) * S), fill=(245, 245, 245))
txt(d, (x + 10, TOP + 6), "预览 · A4", 9, True, INK)
txt(d, (x + PW - 52, TOP + 7), "第 12 周", 7, False, MUTED)
txt(d, (x + 12, TOP + 36), "错题本 · 第 12 周", 9.5, True, INK)
txt(d, (x + 12, TOP + 52), "姓名 ______ 班级 ______", 7.5, False, MUTED)
line(d, (x + 12, TOP + 66), (x + PW - 12, TOP + 66), LINE, 0.8)
txt(d, (x + 12, TOP + 72), "本周 6 道:二次函数 ×2 全等 ×1", 7.2, False, INK)
txt(d, (x + 12, TOP + 84), "分式方程 ×1 压强 ×1 电路 ×1", 7.2, False, INK)
line(d, (x + 12, TOP + 98), (x + PW - 12, TOP + 98), LINE, 0.8)
blocks = [
("1. 已知 x²-4x+3=0,求…", "我的做法:因式分解 (x-1)(x-3)", "重做:✓ 11.09 ✓ 11.12"),
("2. 如图,AB=AC,∠A=40°…", "我的做法:漏了等腰三角形底角", "重做:✓ 11.13"),
]
yy = TOP + 104
for q, mine, again in blocks:
txt(d, (x + 12, yy), q, 7.4, True, INK)
txt(d, (x + 12, yy + 12), mine, 7.2, False, MUTED)
txt(d, (x + 12, yy + 24), again, 7.2, False, CHILD)
yy += 42
rect(d, (x + 12, TOP + PH - 74, x + PW - 12, TOP + PH - 46), fill=(248, 248, 248), outline=LINE, w=0.6, r=4)
txt(d, (x + 18, TOP + PH - 69), "老师批阅:______________", 7.2, False, MUTED)
txt(d, (x + 18, TOP + PH - 57), "家长签字:______________", 7.2, False, MUTED)
rect(d, (x + 10, TOP + PH - 40, x + PW - 10, TOP + PH - 12), fill=ACCENT, outline=None, r=6)
center(d, (x + 10, TOP + PH - 40, x + PW - 10, TOP + PH - 12), "下载 / 打印", 9.5, True, (255, 255, 255))
# 底部标注
notes = [
"① 孩子自己操作,不需要家长在场",
"② 讲解靠嘴说,不对镜头、不上传视频",
"③ 家长看到的是这张纸,不是每道题的记录",
]
for i, n in enumerate(notes):
txt(d, (xs[i], TOP + PH + 12), n, 7.8, False, MUTED)
y0 = TOP + PH + 40
rect(d, (MARGIN, y0, W - MARGIN, y0 + 34), fill=(251, 244, 243), outline=None, r=6)
txt(d, (MARGIN + 10, y0 + 9), "任何一页都不出现:排行榜 · 好友 PK · 连续打卡天数 ·「你再不练就晚了」", 8.4, False, ACCENT)
img = img.resize((W * S, int(H * S)), Image.LANCZOS)
out = HERE / "prd_wire_j.png"
img.save(out)
print("已生成", out.name, img.size)
OUTLINE_FILL = (46, 110, 74)
if __name__ == "__main__":
make_flow()
make_wire()