#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
N5 笔势化 —— 把简片从「矩形」改成「竖画」
N5 的根病(第一轮被否的同一根病):完美直角矩形配毛笔字,是两套语言。
之前我试过给它加绳、加结、加桥、加斜切——全是加法,被否得对。
这次做减法之外的另一件事:改轮廓的**性格**,元素数量一个不加。
竖画的笔势要素:
起笔 顿 —— 顶部略宽、带一点斜角(笔落地压出的肩)
行笔 中段微凸 —— 竹片本身有弧度,笔腹也有弹性
收笔 悬针(渐收至尖)或 垂露(收笔回顿成珠)
四版:
S1 悬针竖 收笔出尖,最利落
S2 垂露竖 收笔回顿成珠,最厚重
S3 竹节竖 中段双凸、两端微收,最像竹片而非笔画
S4 一笔册 简片改通高竖画 + 一道横画作编绳(唯一做加法的一版,单列出供否决)
基准:定稿 N5(4 片 · 缝 6 · 绳区 7 纯空隙,矩形)。
"""
import importlib.util
import math
import os
HERE = os.path.dirname(os.path.abspath(__file__))
def load(name, path):
sp = importlib.util.spec_from_file_location(name, path)
m = importlib.util.module_from_spec(sp)
sp.loader.exec_module(m)
return m
ms = load("ms", os.path.join(HERE, "mark-swap.py"))
n5 = load("n5", os.path.join(HERE, "n5-refine.py"))
RED, INK, WHITE = n5.RED, n5.INK, n5.WHITE
ENV_X, ENV_W = n5.ENV_X, n5.ENV_W
BT, BB, BH, BCY = n5.BLOCK_TOP, n5.BLOCK_BOT, n5.BLOCK_H, n5.BLOCK_CY
N, GAP, ROPE = 4, 6, 7
BW = (ENV_W - (N - 1) * GAP) / N
# 宽度轮廓:t(0=顶,1=底) → 相对宽度
P_XUANZHEN = [(0.00, 0.86), (0.05, 1.00), (0.30, 0.97), (0.58, 0.82),
(0.82, 0.48), (0.96, 0.14), (1.00, 0.04)]
P_CHUILU = [(0.00, 0.86), (0.05, 1.00), (0.34, 0.95), (0.66, 0.88),
(0.88, 1.02), (0.97, 0.86), (1.00, 0.52)]
P_ZHJIE = [(0.00, 0.90), (0.10, 0.99), (0.42, 1.06), (0.70, 0.99),
(0.92, 0.92), (1.00, 0.84)]
P_HENG = [(0.00, 0.55), (0.10, 1.00), (0.45, 0.96), (0.80, 0.80),
(0.96, 0.30), (1.00, 0.12)]
def interp(prof, t):
for (a, va), (b, vb) in zip(prof, prof[1:]):
if a <= t <= b:
k = 0 if b == a else (t - a) / (b - a)
return va + (vb - va) * k
return prof[-1][1]
def stroke_v(x, y, w, h, prof, drift=0.0, steps=44):
"""竖画:x,y 为该笔画外接框左上角,w 为最大宽,h 为高。
drift 让笔画中线轻微摆动(笔不是尺)。"""
right, left = [], []
for i in range(steps + 1):
t = i / steps
ww = w * interp(prof, t) / 2.0
cy = y + h * t
cx = x + w / 2 + drift * w * math.sin(math.pi * t)
right.append((cx + ww, cy))
left.append((cx - ww, cy))
pts = right + list(reversed(left))
return "M " + " L ".join("%g %g" % p for p in pts) + " Z"
def stroke_h(x, y, w, h, prof, steps=44):
"""横画:从左到右,用于编绳。"""
top, bot = [], []
for i in range(steps + 1):
t = i / steps
hh = h * interp(prof, t) / 2.0
cx = x + w * t
cy = y + h / 2
top.append((cx, cy - hh))
bot.append((cx, cy + hh))
pts = top + list(reversed(bot))
return "M " + " L ".join("%g %g" % p for p in pts) + " Z"
def path(d, color=RED):
return '' % (d, color)
TOP_H = (BCY - ROPE / 2) - BT
BOT_Y = BCY + ROPE / 2
BOT_H = BB - BOT_Y
def slips_brush(prof, drift=0.0, color=RED):
out = []
for i in range(N):
x = ENV_X + i * (BW + GAP)
for y, h in ((BT, TOP_H), (BOT_Y, BOT_H)):
out.append(path(stroke_v(x, y, BW, h, prof, drift), color))
return "".join(out)
def s4():
"""通高竖画 + 一道横画编绳。"""
out = []
for i in range(N):
x = ENV_X + i * (BW + GAP)
out.append(path(stroke_v(x, BT, BW, BH, prof=P_ZHJIE, drift=0.05)))
out.append(path(stroke_h(ENV_X - 6, BCY - 4.5, ENV_W + 12, 9, P_HENG)))
return "".join(out)
VARIANTS = [
dict(id="S1", nm="悬针竖", body=lambda: slips_brush(P_XUANZHEN, 0.04),
note="收笔出尖。利落、有速度感,最像「写」出来的。"),
dict(id="S2", nm="垂露竖", body=lambda: slips_brush(P_CHUILU, 0.0),
note="收笔回顿成珠。厚重、稳,但八段都带珠会显繁。"),
dict(id="S3", nm="竹节竖", body=lambda: slips_brush(P_ZHJIE, 0.03),
note="中段微凸、两端微收——先像竹片,再像笔画,最克制的一版。"),
dict(id="S4", nm="一笔册", body=s4,
note="简片改通高竖画,编绳改一道横画。唯一做加法的一版,"
"但加的是笔画而非几何条。"),
]
def lockup(mark, h, color=INK):
return ('' % (h, color, mark, n5.wordmark_fixed(color)))
def mark_only(mark, px):
return ('' % (px, mark))
CSS = ms.CSS + """
.be{display:grid;grid-template-columns:1fr 252px;border-bottom:1px solid var(--hair)}
.be>div:first-child{border-right:1px solid var(--hair);padding:18px 22px}
.be .big{background:#fff;border:1px solid var(--hair);padding:14px 16px;display:flex;
align-items:center;justify-content:center;min-height:112px}
.row2{display:flex;gap:18px;align-items:flex-end;flex-wrap:wrap;margin-top:12px}
.u{text-align:center}.u>span{display:block;font-size:10px;color:var(--muted);margin-top:5px}
.darkcell{background:var(--ink);padding:9px 13px;display:inline-flex}
h3{font-family:'PingFang SC',serif;font-size:15px;font-weight:700;margin:0 0 4px}
h3 .id{color:var(--red);font-size:11px;letter-spacing:.12em;margin-right:7px}
.zoom{display:grid;grid-template-columns:repeat(5,1fr);border:1px solid var(--hair)}
.zoom>div{padding:14px 8px;text-align:center;border-left:1px solid var(--hair)}
.zoom>div:first-child{border-left:0}
.zoom .lab{font-size:11px;color:var(--muted);margin-top:8px;font-family:'PingFang SC',serif}
"""
JS = """
"""
def build():
P = []
w = P.append
w('
'
''
'N5 笔势化 · 简片改竖画 · 2026-10-13')
w('')
w('
N5 in brush strokes · 2026-10-13 · 评审稿(repo 零改动)
')
w('N5 笔势化:把简片从矩形改成竖画
')
w('元素一个不加,只改轮廓的性格——起笔有顿、行笔微凸、收笔出尖或回珠。'
'这是治"几何块配毛笔字=两套语言"那个根病的正面做法,而不是我之前那种加绳加结的绕路。'
'片数、缝宽、绳区、包络、字标全部沿用定稿 N5。
')
# 单片放大对比:笔势本身长什么样
w('
先看单片:四种笔势的轮廓
')
w('每格是一枚简片放大到 96px 高。差别只在收笔与中段。
')
w('')
for lab, prof, dr in (("定稿 · 矩形", None, 0), ("悬针", P_XUANZHEN, 0.04),
("垂露", P_CHUILU, 0.0), ("竹节", P_ZHJIE, 0.03),
("编绳横画", P_HENG, 0)):
if lab.startswith("定稿"):
art = ('
' % RED)
elif lab == "编绳横画":
art = ('
'
% path(stroke_h(2, 4, 96, 13, P_HENG)))
else:
art = ('
'
% path(stroke_v(3, 2, 24, 96, prof, dr)))
w('
' % (art, lab))
w('
')
# 基准
w('
整体对比
')
w('%s
' % lockup(n5.V1, 96))
w('
')
for px in (40, 32):
w('
%s%dpx
' % (lockup(n5.V1, px), px))
w('
%s深底 40px
'
% lockup(n5.V1, 40, WHITE))
for px in (32, 16):
w('
%s%dpx
' % (mark_only(n5.V1, px), px))
w('
')
for v in VARIANTS:
body = v["body"]()
w('')
w('
%s
' % lockup(body, 96))
w('
')
for px in (40, 32):
w('
%s%dpx
' % (lockup(body, px), px))
w('
%s深底 40px
'
% lockup(body, 40, WHITE))
for px in (32, 16):
w('
%s%dpx
' % (mark_only(body, px), px))
w('
%s深底 32px
'
% mark_only(body.replace('fill="%s"' % RED, 'fill="%s"' % WHITE), 32))
w('
')
w('
')
w('')
w('' % n5.V1)
for v in VARIANTS:
w(''
% (v["id"], v["body"]()))
w('
')
w('')
w('
一个必须提醒的量化后果
')
w('笔势化会让简片变细——悬针的下半段宽度只有最大宽的四成左右,'
'而缝宽仍是 6 单位。小尺寸下"片变窄 + 缝不变"意味着片更容易先消失。'
'定稿 N5 在 16px 实测已经是 1 段(四片并成一块),笔势化可能更早失守。'
'所以上表的 16px 一栏是这轮真正的门槛,不是装饰。
')
w('结论待实测回填后给出。
')
w('')
w(JS)
w('
')
w('
')
return "".join(P)
def export():
d = os.path.join(HERE, "assets-n5-brush")
os.makedirs(d, exist_ok=True)
for v in VARIANTS:
body = v["body"]()
for kind, color in (("logo", INK), ("logo-white", WHITE)):
open(os.path.join(d, "%s-%s.svg" % (v["id"], kind)), "w", encoding="utf-8").write(
'\n\n' % (body, n5.wordmark_fixed(color)))
open(os.path.join(d, "%s-mark.svg" % v["id"]), "w", encoding="utf-8").write(
'\n\n' % body)
print("assets-n5-brush/ →", len(os.listdir(d)), "个文件")
def main():
path = os.path.join(HERE, "n5-brush.html")
with open(path, "w", encoding="utf-8") as f:
f.write(build())
print("n5-brush.html %s B" % f"{os.path.getsize(path):,}")
export()
if __name__ == "__main__":
main()