用Graphics的 drawPath 来画曲线(1)

1 用最简单的代码 画一条最简单的曲线

代码在这里:

注意:Graphics的 drawPath 需要 flash player10

package
{
    import flash.display.GraphicsPathCommand;
    import flash.display.Sprite;

    public class drawCurveLine0 extends Sprite
    {
        public function drawCurveLine0()
        {
            super();
            graphics.lineStyle(0, 0x000000);
            var data:Vector.<Number>=new Vector.<Number>();
            data.push(200, 200); graphics.drawCircle(200, 200, 10); //起点
            data.push(250, 100); graphics.drawCircle(250, 100,5); //控制点1
           
            data.push(300, 200); graphics.drawCircle(300, 200, 10); //节点2
            data.push(400, 250); graphics.drawCircle(400, 250,5); //控制点2
           
            data.push(300, 300);
            data.push(250, 400);
            data.push(200, 300);
            data.push(100, 250);
            data.push(200, 200);

            var commands:Vector.<int>=new Vector.<int>();
            commands.push(GraphicsPathCommand.MOVE_TO);
            commands.push(GraphicsPathCommand.CURVE_TO);//样式:曲线
            commands.push(GraphicsPathCommand.CURVE_TO);
            commands.push(GraphicsPathCommand.CURVE_TO);
            commands.push(GraphicsPathCommand.CURVE_TO);

            graphics.drawPath(commands, data);//画路径


        }

    }
}

 

看明白了么?

就是定义一堆点的数组,再定义一个每两个点之间线型的数组,然后drawPath。

很简单吧,很简洁吧。

 

另:如果用GraphicsPathCommand.CURVE_TO,

貌似会认为你的节点数组里的点的作用为:

节点1,控制点1,节点2,控制点2,节点3.。。。。。。。。。。。

 

如果用GraphicsPathCommand.LINE_TO,则是画折现,点数组中点的含义变为:

节点1, 节点2, 节点3.  节点4,   节点5。。。。。。。。。

 

明天请看用Graphics的 drawPath 来画曲线(2),实现 鼠标拖动节点和控制点的功能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值