两端共用的波形算法
size = 394 × 344
centerY = 172
segments = 24
halfWidth = 83 / 200
baseEnergy = 0.90
每帧:
phase += deltaTime × 2.88
targetEnergy = clamp(audioRMS, 0, 1)
smoothingAlpha = 1 - pow(0.92, deltaTime × 60)
smoothedEnergy += (targetEnergy - smoothedEnergy)
× smoothingAlpha
for i = 0...24:
x = i / 24
centered = (x - 0.5) / halfWidth
window = 1 - smoothstep(
0.72, 1.08, abs(centered)
)
shape = max(0.12,
0.52 + 0.22*sin(x*9.5 + phase*0.72)
+ 0.18*sin(x*23 - phase*1.06 + 0.7)
+ 0.09*sin(x*49 + phase*1.52 + 2.1)
+ 0.10*sin(x*5.2 - phase*0.44)
)
maxAmplitude = 18 + 48*2.2*smoothedEnergy
amplitude = (1.8*window + maxAmplitude*shape)
* window
top[i] = (x*394, 172-amplitude)
bottom[i] = (x*394, 172+amplitude)
用 Catmull-Rom → cubic Bézier 连接 top;
反向连接 bottom;闭合后作为 Alpha Mask。
所有尺寸先按 375pt/dp 设计基准计算,再由容器整体等比缩放。不要分别缩放线宽、间距和路径坐标。