RandomWalker
個数
public static const NUM_OF_WALKER:int = 20;
幅
public static const STRIDE:Number = 5.0;
1フレームで何回
public static const NUM_OF_STEP:Number = 1;
角度の分割数
public static const NUM_OF_SEGMENT:Number = 4.11;
/**
* Copyright yyoosshhiinnaarrii ( http://wonderfl.net/user/yyoosshhiinnaarrii )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9mQ7
*/
/**
個数
public static const NUM_OF_WALKER:int = 20;
幅
public static const STRIDE:Number = 5.0;
1フレームで何回
public static const NUM_OF_STEP:Number = 1;
角度の分割数
public static const NUM_OF_SEGMENT:Number = 4.11;
**/
package {
import flash.system.Security;
import flash.system.SecurityDomain;
import flash.text.TextField;
import flash.geom.Point;
import flash.system.LoaderContext;
import flash.display.LoaderInfo;
import flash.display.Loader;
import flash.display.Graphics;
import flash.display.Shape;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.Sprite;
import com.adobe.images.*;
public class FlashTest extends Sprite {
public static const NUM_OF_WALKER:int = 100;
public static const STRIDE:Number = 5.0;
public static const NUM_OF_STEP:Number = 3;
public static const NUM_OF_SEGMENT:Number = 3.01;
public static const IMG_URL:String = "http://assets.wonderfl.net/images/related_images/b/bf/bf4b/bf4b7835c2f40f39ba81c0df721dd4324922caedm";//"http://assets.wonderfl.net/images/related_images/a/aa/aad6/aad64cb6bc2cc7ef38c6c910a071761e818280edm";
private var img:BitmapData;
private var bd:BitmapData;
public function get sWidth():Number{return stage.stageWidth;}
public function get sHeight():Number{return stage.stageHeight;}
public function FlashTest()
{
Security.allowDomain("assets.wonderfl.net");
Security.loadPolicyFile("http://assets.wonderfl.net/crossdomain.xml");
// write as3 code here..
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest(IMG_URL));
}
private function onLoadComplete(event:Event):void
{
var info:LoaderInfo = LoaderInfo( event.target );
img = Bitmap( info.content ).bitmapData;
bd = new BitmapData(sWidth,sHeight,false,0xffffffff);
addChild( new Bitmap(bd) );
init();
}
private var points:Vector.<Point>;
private function init(e:Event = null):void
{
points = new Vector.<Point>(NUM_OF_WALKER,true);
var p:Point = new Point( sWidth/2, sHeight/2);
for(var i:int=0; i<NUM_OF_WALKER;i++)
points[i] = p.clone();
addEventListener(Event.ENTER_FRAME,oef);
}
private function oef(event:Event):void
{
bd.lock();
for each( var p:Point in points )
{
for(var i:int = 0; i<NUM_OF_STEP; i++)
{
var s:Shape = new Shape();
var g:Graphics = s.graphics;
// move
var length:Number = STRIDE;
var rad:Number = Math.PI*2*int( Math.random()*NUM_OF_SEGMENT)/NUM_OF_SEGMENT;
var color:uint = img.getPixel( int( p.x/sWidth*img.width ), int( p.y/sHeight*img.height ) );
g.lineStyle(0.5, color, 0.5);
g.moveTo(p.x, p.y);
var d:Point = Point.polar(length, rad );
p.offset( d.x, d.y );
g.lineTo(p.x, p.y);
bd.draw( s );
}
}
bd.unlock();
}
private var tf:TextField;
public function _t(obj:*):void
{
if(!tf)
{
tf = new TextField();
tf.width = sWidth;
tf.height = sHeight;
addChild(tf);
}
tf.appendText( obj.toString() );
}
}
}