我正在尝试绘制一些动画的草叶,我想生成一个锥形曲线,该曲线的底部较粗,顶部较细。我能想到的唯一方法是绘制一条长度较短且线宽较大的曲线。
我很好奇是否有人有更好的方法。
最佳答案
请尝试以下功能。它绘制草的开放轮廓。您可以修改它以满足您的需要。为Raphael编码。
/**
* drawAGrass draws an open base grass.
* @param paper Raphael paper instance
* @param baseX X position of the grass base center
* @param baseY Y position of the grass base center
* @param baseW Width of the grass base
* @param length Length of the grass
* @param tilt Angle of shift of the grass tip; Safe range: [-45, 45]
*/
function drawAGrass (paper, baseX, baseY, baseW, length, tilt) {
var x1 = baseX + baseW * 0.5,
x2 = baseX - baseW * 0.5,
ang = (180 - tilt) * Math.PI / 180,
x = Math.round(baseX + length * Math.sin(ang)),
y = Math.round(baseY + length * Math.cos(ang));
paper.path(['M', baseX, baseY, 'Q', baseX, y, x, y]);
paper.path(['M', x1, baseY, 'Q', x1, y, x, y]);
paper.path(['M', x2, baseY, 'Q', x2, y, x, y]);
}
如下使用它。
var paper = Raphael(0, 0, 500, 350);
drawAGrass(paper, 250, 330, 15, 150, 25);