黄色い線

くるくるっていう線を作りたかったので。

黄色い線 – wonderfl build flash online

▼ActionScript AS3(FP10)
[sourcecode language=”as3″]
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;

/**
* …
* @author umhr
*/
[SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 30)]
public class Main extends Sprite
{
private var _mousePoint:Array/*Point*/= [];
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point

_mousePoint.unshift(new Point(mouseX, mouseY));
_mousePoint.unshift(new Point(mouseX, mouseY));

this.addEventListener(Event.ENTER_FRAME, onEnter);
}

private function onEnter(e:Event):void
{
var p0:Point = _mousePoint[0];
var p1:Point = _mousePoint[1];

var inertiaPoint:Point = p0.subtract(p1).add(p0);
//inertiaPoint.x = p0.x – p1.x + p0.x;
//inertiaPoint.y = p0.y – p1.y + p0.y;

inertiaPoint.x = inertiaPoint.x*0.9 + mouseX * 0.1;
inertiaPoint.y = inertiaPoint.y*0.9 + mouseY * 0.1;

_mousePoint.unshift(inertiaPoint);
_mousePoint.splice(100);
draw(_mousePoint);

}

/**
* 線を描画
* @param mousePoint
*/
private function draw(mousePoint:Array/*Point*/):void {
this.graphics.clear();
this.graphics.lineStyle(0, 0xFFFF00);
this.graphics.moveTo(mousePoint[0].x, mousePoint[0].y);
var n:int = mousePoint.length;
for (var i:int = 1; i < n; i++) {
this.graphics.lineTo(mousePoint[i].x, mousePoint[i].y);
}
}
}

}
[/sourcecode]