0

我正在尝试绘制一些动画的草叶,并且我想生成一条底部较厚而顶部较薄的锥形曲线。我能想到的唯一方法是绘制曲线,每条曲线的长度较短,线宽较大。

我很好奇是否有人有更好的方法来做到这一点。

4

1 回答 1

3

请尝试以下功能。它绘制了草的开放轮廓。您可以对其进行修改以满足您的需要。为拉斐尔编码。

/**
 * 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);
于 2013-04-16T07:17:49.683 回答