Javascript 拉斐尔的锥形线

Javascript 拉斐尔的锥形线,javascript,raphael,Javascript,Raphael,我试图画一些草叶动画,我想生成一个锥形曲线,底部较厚,顶部较薄。我能想象的唯一方法就是画出长度更小、线宽更大的曲线 我很好奇是否有人有更好的方法来做这件事。请尝试以下功能。它勾勒出一片草地的开放轮廓。您可以修改它以满足您的需要。为拉斐尔编码 /** * drawAGrass draws an open base grass. * @param paper Raphael paper instance * @param baseX X position of the gras

我试图画一些草叶动画,我想生成一个锥形曲线,底部较厚,顶部较薄。我能想象的唯一方法就是画出长度更小、线宽更大的曲线


我很好奇是否有人有更好的方法来做这件事。

请尝试以下功能。它勾勒出一片草地的开放轮廓。您可以修改它以满足您的需要。为拉斐尔编码

/**
 * 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);

请尝试以下功能。它勾勒出一片草地的开放轮廓。您可以修改它以满足您的需要。为拉斐尔编码

/**
 * 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);