forked from: forked from: [1日1Wonderfl]9日目:メッシュ的なもの
// forked from yd_niku's forked from: [1日1Wonderfl]9日目:メッシュ的なもの
// forked from yd_niku's [1日1Wonderfl]9日目:メッシュ的なもの
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.filters.*;
public class FlashTest extends Sprite {
private var canvas :BitmapData;
private var particles:Vector.<Particle> = new Vector.<Particle>();
public function FlashTest() {
var wLength:Number = stage.stageWidth*0.005;
var hLength:Number = stage.stageHeight*0.005;
for( var i :int =0; i<200; ++i ) {
for( var j:int =0;j<200; ++j ) {
particles.push( new Particle( i*wLength, j*hLength ) );
}
}
canvas = new BitmapData( stage.stageWidth, stage.stageHeight, true, 0xFFFFFF00 );
addChild( new Bitmap(canvas) );
addEventListener( Event.ENTER_FRAME, onUpdate );
}
private var origin:Point = new Point();
private var blur:BlurFilter = new BlurFilter();
private var ctf:ColorTransform=new ColorTransform(1,1,1,1, 2, 2, -2, 0);
private function onUpdate( e:Event ):void {
for each ( var p:Particle in particles ) {
var dx:Number = mouseX - p.x;
var dy:Number = mouseY - p.y;
var far:Number = Math.sqrt( dx*dx +dy*dy );
var idx:Number = dx/far * 350/far;
var idy:Number = dy/far * 350/far;
p.vx = p.vx*0.98+ idx;
p.vy = p.vy*0.98+ idy;
p.x += (p.ax-(p.x+p.vx))*0.98;
p.y += (p.ay-(p.y+p.vy))*0.98;
}
canvas.lock();
//canvas.fillRect( canvas.rect, 0xFFFFFF00 );
canvas.colorTransform( canvas.rect, ctf );
for each ( p in particles ) {
canvas.setPixel32( p.x, p.y, 0xFFCC0066 );
}
canvas.applyFilter( canvas, canvas.rect, origin, blur );
canvas.unlock();
}
}
}
internal class Particle {
public var x:Number = 0;
public var y:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
public var ax:Number = 0;
public var ay:Number = 0;
public function Particle( x:Number, y:Number ){
this.x = this.ax = x;
this.y = this.ay = y;
}
}