ごはんとWonderfl
// 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 fieldWidth:Number = stage.stageWidth - 100;
var fieldHeight:Number = stage.stageHeight - 100;
var centerX:Number = stage.stageWidth/2;
var centerY:Number = stage.stageHeight/2;
var radius:Number = 180;
var angle:Number = 2*Math.PI;
for( var i :int =0; i<10000; ++i ) {
//for( var j:int =0;j<200; ++j ) {
var a:Number = Math.random()*angle;
particles.push(
new Particle(
Math.random() * radius * Math.sin( a ) + centerX,
Math.random() * radius * Math.cos( a ) + centerY
)
);
//}
}
addChild( new Image() );
canvas = new BitmapData( stage.stageWidth, stage.stageHeight, true, 0x00FFFF00 );
var container:DisplayObject = addChild( new Bitmap(canvas) );
addEventListener( Event.ENTER_FRAME, onUpdate );
//container.blendMode = BlendMode.MULTIPLY;
//container.blendMode = BlendMode.ADD;
container.blendMode = BlendMode.OVERLAY;
setStartPoint();
}
private function setStartPoint():void{
var centerX:Number = stage.stageWidth>>1;
var centerY:Number = stage.stageHeight>>1;
for each( var p:Particle in particles ){
// p.x = centerX;
// p.y = centerY;
}
}
private var origin:Point = new Point();
private var blur:BlurFilter = new BlurFilter();
private var ctf:ColorTransform=new ColorTransform(1,1,1, 0.9, 2, 2, -4, 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 * 180/far;
var idy:Number = dy/far * 350/far;
p.vx = p.vx*0.99+ idx;
p.vy = p.vy*0.99+ idy;
p.x += (p.ax-(p.x+p.vx))*0.02;
p.y += (p.ay-(p.y+p.vy))*0.02;
}
canvas.lock();
//canvas.fillRect( canvas.rect, 0xFFFFFFFF );
canvas.colorTransform( canvas.rect, ctf );
for each ( p in particles ) {
canvas.setPixel32( p.x, p.y, 0xFFFFCC33 );
}
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;
}
}
import flash.events.*;
import flash.display.*;
import flash.system.*;
import flash.net.*;
class Image extends Loader{
public function Image (){
var img: String =
"http://assets.wonderfl.net/images/related_images/d/da/da89/da89d3a27fa31284b0afc58fdf4ef6e337349653";
addEventListener( Event.COMPLETE, onLoadComplete );
load( new URLRequest(img), new LoaderContext(true) );
}
public function onLoadComplete(e:Event):void{
}
}