36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
(function(){
|
|
// 注册雪花形状渲染函数 恢复为原始六角雪花绘制样式
|
|
window.YooneSnowShapeRenderers = window.YooneSnowShapeRenderers || {};
|
|
window.YooneSnowShapeRenderers.flake = function(context, positionX, positionY, baseSize){
|
|
// 将基础尺寸转换为原始函数中的 size 参数 以保持形状大小一致
|
|
const branchSize = baseSize * 3;
|
|
context.save();
|
|
context.translate(positionX, positionY);
|
|
context.fillStyle = 'rgba(255,255,255,0.9)';
|
|
context.strokeStyle = 'rgba(255,255,255,0.9)';
|
|
context.lineWidth = branchSize * 0.15;
|
|
// 循环绘制六个分支 每次旋转 60 度
|
|
for (let branchIndex = 0; branchIndex < 6; branchIndex++) {
|
|
context.rotate(Math.PI / 3);
|
|
context.beginPath();
|
|
context.moveTo(0, 0);
|
|
context.lineTo(0, branchSize);
|
|
context.stroke();
|
|
// 在主分支上绘制三个小分叉 保持与原始实现一致
|
|
context.beginPath();
|
|
context.moveTo(0, branchSize * 0.3);
|
|
context.lineTo(branchSize * 0.3, branchSize * 0.5);
|
|
context.stroke();
|
|
context.beginPath();
|
|
context.moveTo(0, branchSize * 0.5);
|
|
context.lineTo(-branchSize * 0.3, branchSize * 0.7);
|
|
context.stroke();
|
|
context.beginPath();
|
|
context.moveTo(0, branchSize * 0.7);
|
|
context.lineTo(branchSize * 0.3, branchSize * 0.9);
|
|
context.stroke();
|
|
}
|
|
context.restore();
|
|
};
|
|
})();
|