flash绘图API flash player11新增的绘图API方法--cubicCurveTo

               

  今天除了更新的3D的api之前,另外在flash Graphics方法当中新增了一个cubicCurveTo的方法,能够使用其进行绘制贝塞尔曲线,奇怪是文档里面对应的flash 版本是12,不知道是不是写错了,呵呵。基本上用法很简单。和curveTo差不多,只是多了一个控制点。

提前使用这个api 运行时候,只能在安装最新flash player 11插件的浏览器运行。目前还没正式发布相应flash player11播放器正式版本。等待五月份官方会推出正式版,所以还需要耐心等待。另外一些非官方的播放器可以debug的时候使用脱离浏览器测试,要是等不及的可以下载来试试。

 

 

使用编译后的程序需要使用最新版本先可以看到效果。

可以在这里下载对应的flash player 11的版本:目前只是支持插件的形式。

http://labs.adobe.com/technologies/flashplatformruntimes/incubator/

 

新增的api方法,依旧在Graphics类找到,这次绘制贝塞尔曲线有利于制作绘图的时候,一些在线的ps工具可以利用这个函数进行设计贝塞尔的三次的运算,而不用使用其他运算公式模拟三次的效果。

 

public function cubicCurveTo(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number):void

flash绘图API flash player11新增的绘图API方法--cubicCurveTo

 

Language Version:  ActionScript 3.0

 

Runtime Versions:  AIR 1.0, Flash Player 12

 

 

测试代码:

import flash.display.Sprite;for (var i:int=0; i<4; i++){ var shape:Sprite=new Sprite(); addChild(shape); shape.x = 300; shape.y = 300; shape.graphics.lineStyle(0); shape.graphics.beginFill(Math.random()*0xffffff); shape.graphics.cubicCurveTo(-290,-280,290,-280,0,0); shape.graphics.endFill(); shape.rotation = i * 90;}

测试的效果如下:

 

 flash绘图API flash player11新增的绘图API方法--cubicCurveTo

 

使用的时候,恰当改一下复制10次数可以变化上面的效果;

import flash.display.Sprite;for (var i:int=0; i<10; i++){ var shape:Sprite=new Sprite(); addChild(shape); shape.x = 300; shape.y = 300; shape.graphics.lineStyle(0); shape.graphics.beginFill(Math.random()*0xffffff); shape.graphics.cubicCurveTo(-290,-280,290,-280,0,0); shape.graphics.endFill(); shape.rotation = i * 36;}

 

flash绘图API flash player11新增的绘图API方法--cubicCurveTo

import flash.display.Sprite;for (var i:int=0; i<360; i++){ var shape:Sprite=new Sprite(); addChild(shape); shape.x = 300; shape.y = 300; shape.graphics.lineStyle(0); shape.graphics.beginFill(Math.random()*0xffffff); shape.graphics.cubicCurveTo(-5,-280,5,-280,0,0); shape.graphics.endFill(); shape.rotation = i;}

 

 

除此之外,改变参数和复制次数会产生很多图片变化,这跟之前所制作的玫瑰线和旋轮线制作原理是一样的。

 

flash绘图API flash player11新增的绘图API方法--cubicCurveTo

 

把之前的程序修改一下,可以进行多点控制。

 

package { //贝塞尔曲线 import flash.display.Sprite; import flash.events.*; import flash.geom.*; public class Main extends Sprite {  private var pen:Sprite=new Sprite();  private var circleA:CirclePoint;  private var circleB:CirclePoint;  private var circleC:CirclePoint;  private var circleD:CirclePoint;  public function Main()  {   init();  }    //初始化  private function init():void  {   drawGrid(20,30,16,16);//绘制网格   addChild(pen);   pen.graphics.lineStyle(1,0xff0000);   pen.graphics.moveTo(20,160);   pen.graphics.cubicCurveTo(130,290,270,50,460,160);   circleA=new CirclePoint();   circleA.addEventListener(MouseEvent.MOUSE_DOWN,circle_DragHandler);   addChild(circleA);   circleA.x=20;   circleA.y=160;   circleB=circleA.clone();   circleB.addEventListener(MouseEvent.MOUSE_DOWN,circle_DragHandler);   addChild(circleB);   circleB.x=130;   circleB.y=290;   circleC=circleA.clone();   circleC.addEventListener(MouseEvent.MOUSE_DOWN,circle_DragHandler);   addChild(circleC);   circleC.x=270;   circleC.y=50;      circleD=circleA.clone();   circleD.addEventListener(MouseEvent.MOUSE_DOWN,circle_DragHandler);   addChild(circleD);   circleD.x=460;   circleD.y=160;         pen.graphics.moveTo(circleA.x,circleA.y);   pen.graphics.lineTo(circleB.x,circleB.y);            pen.graphics.lineTo(circleC.x,circleC.y);   pen.graphics.lineTo(circleD.x,circleD.y);      stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUpHandler);  }     private function circle_DragHandler(event:MouseEvent):void  {   stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMoveHandler);   event.currentTarget.startDrag(false,new Rectangle(10,10,460,300));//控制拖动区间  }  private function onMouseMoveHandler(event:MouseEvent):void  {   redraw();  }  private function onMouseUpHandler(event:MouseEvent):void  {   stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMouseMoveHandler);   circleA.stopDrag();   circleB.stopDrag();  }    //重绘  private function redraw():void  {   pen.graphics.clear();   pen.graphics.lineStyle(1,0xff0000);   pen.graphics.moveTo(circleA.x,circleA.y);            pen.graphics.cubicCurveTo(circleB.x,circleB.y,circleC.x,circleC.y,circleD.x,circleD.y);            pen.graphics.moveTo(circleA.x,circleA.y);            pen.graphics.lineTo(circleB.x,circleB.y);            pen.graphics.lineTo(circleC.x,circleC.y);   pen.graphics.lineTo(circleD.x,circleD.y);     }  //绘制网格  private function drawGrid(rows :int,cols:int,titleW:int,titleH:int):void  {          this.graphics.lineStyle(1,0xffffff,0.2);    for (var i:int=0; i<rows; i++)   {    for (var j:int=0; j<cols ; j++)    {           this.graphics.drawRect(j*titleW,i*titleH,titleW,titleH);//绘制矩形    }   }  }   }}//创建点类import flash.display.Sprite;internal class CirclePoint extends Sprite{ public function CirclePoint(R:int=8) {  this.graphics.lineStyle(0);  this.graphics.beginFill(0xffffff);  this.graphics.drawCircle(0,0,R);  this.graphics.endFill(); } public function clone():CirclePoint {  return new CirclePoint(); } public function move(x:Number,y:Number):void {  this.x=x;  this.y=y; }}

 

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.****.net/jiangjunshow