hybrid-brush-01
...
@author bouze
package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
/**
* ...
* @author bouze
*/
public class Main extends Sprite
{
private var drawLayer:Sprite;
private var particles:Array = new Array();
private var pNum:int = 10;
private var maxDistance:Number = 20;
private var friction:Number = 0.3;
public function Main()
{
init();
}
private function init():void
{
drawLayer = new Sprite();
addChild(drawLayer);
initParticles();
addEventListener(Event.ENTER_FRAME, update);
}
private function initParticles():void
{
var i:int;
for (i = 0; i < pNum; i++)
{
/*
var circle:Sprite = new Sprite();
var g:Graphics = circle.graphics;
g.lineStyle( 1 );
g.drawCircle( 0, 0, 4 );
drawLayer.addChild( circle );
*/
particles.push(
{
//ref: circle,
x: mouseX,
y: mouseY,
dx: 0,
dy: 0
} );
}
}
private function move():void
{
var i:int;
for (i = 0; i < pNum; i++)
{
var p:Object = particles[ i ];
var pp:Object = particles[ i - 1 ];
if ( i == 0 )
{
p.x += ( mouseX - p.x ) * friction;
p.y += ( mouseY - p.y ) * friction;
}
else
{
p.x += ( pp.x - p.x ) * friction * ( pNum - i ) * 0.1;
p.y += ( pp.y - p.y ) * friction * ( pNum - i ) * 0.1;
}
//p.ref.x = p.x;
//p.ref.y = p.y;
}
}
private function draw():void
{
var g:Graphics = drawLayer.graphics;
g.clear();
g.lineStyle(1);
var i:int;
for (i = 0; i < pNum - 2; i++)
{
g.moveTo( particles[ i ].x, particles[ i ].y );
g.lineTo( particles[ i + 1 ].x, particles[ i + 1 ].y );
g.lineTo( particles[ i + 2 ].x, particles[ i + 2 ].y );
g.lineTo( particles[ i ].x, particles[ i ].y );
}
}
private function update(e:Event):void
{
move();
draw();
}
}
}