Ethscriptions's picture
登泰山记:渲染引擎、九个篇章场景、程序化配乐音效、MP4 导出、发布文案与封面(初版)
6fff8e3 verified
Raw History Blame Contribute Delete
7.05 kB
// 深读:义理 · 考据 · 辞章 —— 雅洁
import { RC, C, text, bg, vignette, during, wordTime, drawSeal, revealText } from '../draw'
import { Scene, LINE } from '../timeline'
import { glow } from '../assets'
import { easeOut, inv, smooth, rgba, mulberry32, clamp } from '../util'
function icon(rc: RC, kind: number, x: number, y: number, s: number, a: number) {
const { g, u } = rc
if (a <= 0) return
g.save()
g.globalAlpha *= a
g.strokeStyle = C.goldHi
g.fillStyle = C.goldHi
g.lineWidth = 2 * u
if (kind === 1) {
// 考据:山川图
g.beginPath()
for (let i = 0; i <= 20; i++) g.lineTo(x - s + (i / 20) * 2 * s, y - s * 0.5 + Math.sin(i * 0.8) * s * 0.06)
g.stroke()
g.beginPath()
for (let i = 0; i <= 20; i++) g.lineTo(x - s + (i / 20) * 2 * s, y + s * 0.5 + Math.sin(i * 0.7 + 1) * s * 0.06)
g.stroke()
g.strokeStyle = C.cinnabar
g.beginPath()
g.moveTo(x - s * 0.9, y)
g.lineTo(x + s * 0.9, y)
g.stroke()
g.fillStyle = C.goldHi
g.beginPath()
g.moveTo(x - s * 0.3, y + s * 0.15)
g.lineTo(x, y - s * 0.3)
g.lineTo(x + s * 0.3, y + s * 0.15)
g.fill()
} else if (kind === 2) {
// 辞章:日出
glow(g, x, y, s * 1.4, '#ff6a3a', 0.5)
g.fillStyle = '#d8281c'
g.beginPath()
g.arc(x, y, s * 0.4, 0, Math.PI * 2)
g.fill()
g.strokeStyle = C.goldHi
g.beginPath()
g.moveTo(x - s, y + s * 0.4)
g.lineTo(x + s, y + s * 0.4)
g.stroke()
} else {
// 义理:雪中静坐之人
g.beginPath()
g.arc(x, y - s * 0.35, s * 0.13, 0, Math.PI * 2)
g.fill()
g.beginPath()
g.moveTo(x - s * 0.35, y + s * 0.35)
g.quadraticCurveTo(x, y - s * 0.4, x + s * 0.35, y + s * 0.35)
g.fill()
const r = mulberry32(3)
for (let i = 0; i < 18; i++) {
g.globalAlpha = a * 0.6
g.beginPath()
g.arc(x + (r() - 0.5) * s * 2, y + (r() - 0.5) * s * 1.4, 1.6 * u, 0, Math.PI * 2)
g.fill()
}
}
g.restore()
}
function draw(rc: RC, sc: Scene, lt: number) {
const { g, W, H, u, P, t } = rc
bg(rc, 'dark')
glow(g, W / 2, H * 0.45, Math.max(W, H) * 0.6, '#3a2a1a', 0.35)
// f1
const a1 = during(rc, 'f1', LINE.f2.start + 0.3, 0.5, 0.6)
revealText(g, '为什么要这样写?', W / 2, H * 0.45, (P ? 76 : 90) * u, clamp((t - LINE.f1.start) / 1.2), { fam: 'serifB', color: '#f6f1e6', align: 'center', alpha: a1, ls: 0.15 })
// f2-f5 三柱
const aP = during(rc, 'f2', LINE.f6.start - 0.2, 0.6, 0.6)
if (aP > 0) {
const kH = smooth(inv(LINE.f2.start, LINE.f2.start + 0.8, t))
text(g, '桐城派 · 集大成者', W / 2, H * (P ? 0.14 : 0.16), 32 * u, { color: C.gold, align: 'center', alpha: aP * kH, ls: 0.4 })
drawSeal(rc, '惜抱', W / 2 + (P ? 230 : 250) * u, H * (P ? 0.14 : 0.16), 60 * u, aP * kH)
const items: { s: string; d: string; lit: string; icon: number; cap: string }[] = [
{ s: '义理', d: '思想 · 人格', lit: 'f5', icon: 3, cap: '辞官 · 除夕 · 静坐待日' },
{ s: '考据', d: '求实 · 查证', lit: 'f3', icon: 1, cap: '第一段 · 山川方位' },
{ s: '辞章', d: '文采 · 锤炼', lit: 'f4', icon: 2, cap: '第三段 · 日出' },
]
items.forEach((it, i) => {
const k = easeOut(inv(wordTime('f2', it.s), wordTime('f2', it.s) + 0.6, t))
const lit = smooth(inv(LINE[it.lit].start - 0.1, LINE[it.lit].start + 0.5, t))
const x = P ? W / 2 : W * (0.22 + i * 0.28)
const y = P ? H * (0.3 + i * 0.2) : H * 0.42
const col = lit > 0.5 ? C.goldHi : '#efe9dc'
if (lit > 0) glow(g, x, y, 220 * u, '#c9a86a', 0.18 * lit * aP)
text(g, it.s, P ? x - 150 * u : x, y, (P ? 96 : 120) * u, { fam: 'serifB', color: col, align: 'center', alpha: aP * k, ls: 0.15 })
text(g, it.d, P ? x - 150 * u : x, y + (P ? 76 : 100) * u, 24 * u, { color: rgba('#efe9dc', 0.7), align: 'center', alpha: aP * k, ls: 0.3 })
icon(rc, it.icon, P ? x + 200 * u : x, P ? y - 10 * u : y + 200 * u, (P ? 60 : 64) * u, aP * lit)
text(g, it.cap, P ? x + 200 * u : x, P ? y + 80 * u : y + 300 * u, 24 * u, { color: C.goldHi, align: 'center', alpha: aP * lit, ls: 0.12 })
})
}
// f6 雅洁
const a6 = during(rc, 'f6', LINE.f7.start + 0.2, 0.5, 0.6)
if (a6 > 0) {
const f6 = LINE.f6
const words = ['激动', '壮丽', '震撼', '感慨万千', '心潮澎湃', '美不胜收']
const r = mulberry32(17)
words.forEach((w, i) => {
const ang = (i / words.length) * Math.PI * 2 + 0.4
const rad = (P ? 300 : 360) * u + r() * 60 * u
const x = W / 2 + Math.cos(ang) * rad * (P ? 0.9 : 1.4)
const y = H * 0.45 + Math.sin(ang) * rad * 0.7
const k = smooth(inv(f6.start + 0.2 + i * 0.12, f6.start + 0.6 + i * 0.12, t))
const strike = smooth(inv(wordTime('f6', '删去'), wordTime('f6', '删去') + 0.8, t))
const fade = 1 - smooth(inv(wordTime('f6', '只留下'), wordTime('f6', '只留下') + 1, t))
const fs = 34 * u
text(g, w, x, y, fs, { color: '#9b958a', align: 'center', alpha: a6 * k * (0.3 + 0.7 * fade), ls: 0.1 })
if (strike > 0) {
const ww = w.length * fs * 1.1
g.strokeStyle = rgba(C.cinnabar, a6 * k * fade)
g.lineWidth = 2 * u
g.beginPath()
g.moveTo(x - ww / 2, y)
g.lineTo(x - ww / 2 + ww * strike, y)
g.stroke()
}
})
const k = easeOut(inv(wordTime('f6', '雅洁'), wordTime('f6', '雅洁') + 0.8, t))
text(g, '雅洁', W / 2, H * 0.45, (P ? 220 : 260) * u, { fam: 'xing', color: '#f6f1e6', align: 'center', alpha: a6 * k })
text(g, '只留下准确', W / 2, H * 0.45 + (P ? 170 : 190) * u, 34 * u, { color: C.goldHi, align: 'center', alpha: a6 * smooth(inv(wordTime('f6', '只留下'), wordTime('f6', '只留下') + 0.6, t)), ls: 0.4 })
}
// f7 日上,正赤如丹
const a7 = during(rc, 'f7', sc.end, 0.4, 0.6)
if (a7 > 0) {
const f7 = LINE.f7
const k0 = smooth(inv(f7.start, f7.start + 0.5, t))
const s1 = '我很激动'
text(g, `「${s1}」`, W / 2, H * 0.27, 40 * u, { color: '#9b958a', align: 'center', alpha: a7 * k0 * (1 - smooth(inv(wordTime('f7', '他只写'), wordTime('f7', '他只写') + 0.8, t)) * 0.7), ls: 0.2 })
const ks = smooth(inv(f7.start + 0.8, f7.start + 1.3, t))
if (ks > 0) {
g.strokeStyle = rgba(C.cinnabar, a7 * ks)
g.lineWidth = 2.5 * u
g.beginPath()
g.moveTo(W / 2 - 110 * u, H * 0.27)
g.lineTo(W / 2 - 110 * u + 220 * u * ks, H * 0.27)
g.stroke()
}
const tw = wordTime('f7', '日上')
const k = smooth(inv(tw, tw + 1.2, t))
glow(g, W / 2, H * 0.5, 360 * u, '#ff4a2a', 0.35 * a7 * k)
g.fillStyle = rgba('#c8231a', a7 * k * 0.9)
g.beginPath()
g.arc(W / 2, H * 0.5, (P ? 150 : 170) * u, 0, Math.PI * 2)
g.fill()
revealText(g, '日上,正赤如丹', W / 2, H * 0.5, (P ? 76 : 96) * u, clamp((t - tw) / 1.8), { fam: 'kai', color: '#fff6e8', align: 'center', alpha: a7, ls: 0.1 })
}
vignette(rc, 0.6)
void lt
}
export default { tone: 'dark' as const, draw }