Flex中用AS3实现贝塞尔曲线图
????? ?周末在家研究了下用Flex实现神奇的贝塞尔曲线,这曲线主要采用的是FLex线程技术来实现,实现后,我一看运行效果,呵呵太神了…效果截图如下:
图片1
图2
代码如下:
CurveDemo.as
package org.luosijin.curve { import flash.display.*; import flash.events.*; import flash.filters.*; import flash.geom.*; import flash.utils.*; [SWF(width="730", height="500", backgroundColor="0x000000", frameRate="24")] public class CurveDemo2 extends Sprite { private var _radius:int = 100; private var _numPoints:Number = 30; private var _points:Array; private var _pre_r:Number = 0.000314159; private var _centX:Number; private var _centY:Number; private var _myTimer:Timer; private var _color:Number = 165375; private var _radians:Number = 0; private var _gf:GlowFilter; public function CurveDemo2() { _points = new Array(); _centX =900* 0.5; _centY =600* 0.5; _myTimer = new Timer(10, 0); _gf = new GlowFilter(); _myTimer.addEventListener(TimerEvent.TIMER,onTimerHandler); _myTimer.start(); var _loc_1:int; _gf.blurY = 32; _gf.blurX = _loc_1; _gf.color = 165375; filters = [_gf]; }// end function private function onTimerHandler(param1:Event) : void { run(); }// end function private function run() : void { var _loc_2:Point; graphics.clear(); _points = []; _radians = _radians + _pre_r; var _loc_1:Number=0; while (_loc_1 < _numPoints) { // label _loc_2 = new Point(); _loc_2.x = _centX + Math.cos(_radians * _loc_1) * 140; _loc_2.y = _centY + Math.sin(_radians * _loc_1) * 140; _points.push(_loc_2); _loc_1 = _loc_1 + 1; }// end while graphics.beginFill(_color, 0.2); graphics.lineStyle(1, _color, 0.8); graphics.moveTo(_centX, _centY); _loc_1 = 2; while(_loc_1 < _numPoints-2){ graphics.curveTo(_points[_loc_1-1].x, _points[_loc_1-1].y, _points[_loc_1].x, _points[_loc_1].y); graphics.curveTo(_points[_loc_1 + 1].x, _points[_loc_1 + 1].y, _centX, _centY); _loc_1 = _loc_1 + 1; } graphics.endFill(); }// end function } }?
?