forked from: 高速な蟻
参考文献:http://moringo.moo.jp/wordpress/?p=128
FULL SCREEN にできま・・・せん
/**
* Copyright paq ( http://wonderfl.net/user/paq )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lURC
*/
// forked from clockmaker's 高速な蟻
// forked from tktr90755's 蟻
//参考文献:http://moringo.moo.jp/wordpress/?p=128
//FULL SCREEN にできま・・・せん
package {
// フォーク回数が20回までいって・・・ません
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.filters.*;
import flash.utils.*;
import flash.geom.*;
import net.hires.debug.Stats;
[SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="60")]
public class Main extends Sprite {
private var forceMap:BitmapData = new BitmapData( 233, 233, false, 0xFFFFFFFF );
private var randomSeed:uint = Math.floor( Math.random() * 0xFFFF );
private var seed:Number = Math.floor( Math.random() * 0xFFFF );
private var offset:Array = [new Point(), new Point()];
private var timer:Timer;
private var buffer:BitmapData = new BitmapData(465, 465, true, 0xFFFFFFFF);
private var screen:Bitmap = new Bitmap(buffer);
private var particleList:Array = [];
private var point:Point = new Point();
function Main()
{
// フォースマップの初期化をおこないます
//resetFunc();
// ループ処理
addEventListener( Event.ENTER_FRAME, loop );
// 時間差でフォースマップと色変化の具合を変更しています
/*var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, resetFunc);
timer.start();*/
// 矢印をプレレンダリング
var dummyHolder:Sprite = new Sprite();
drawAnt();
dummyHolder.addChild(ant);
var temp:BitmapData;
var rect:Rectangle;
var matrix:Matrix = new Matrix();
var j:int = ALPHA_STEPS;
while(j--) {
var i:int = ROT_STEPS;
var k:int = j * ROT_STEPS;
while (i--) {
matrix.identity();
matrix.rotate( ( 360 / ROT_STEPS * i )* Math.PI / 180);
matrix.translate(11, 11);
temp = new BitmapData(17, 17, true, 0x000000);
temp.draw(dummyHolder, matrix);
rotArr[i+k] = new DisplayImage(temp, 11, 11);
}
}
// パーティクルを生成します
for (i = 0; i < NUM_PARTICLE; i++) {particleList[i] = new Arrow(Math.random() * 465, Math.random() * 465);}
addChild(screen);
// デバッグ用のスタッツを表示しています
addChild(new Stats);
stage.quality = "low";
}
private var ant :Sprite;
//アリの見た目がしょぼいです・・
private function drawAnt():void
{
ant = new Sprite();
ant.scaleX=
ant.scaleY = 0.2;
this.addChild( ant );
var hip:Shape = new Shape();
hip.graphics.beginFill(0x000000, 1);
hip.graphics.drawEllipse( -23, -9, 19, 18 );
hip.graphics.endFill();
ant.addChild( hip );
var head:Shape = new Shape();
head.graphics.beginFill(0x000000, 1);
head.graphics.drawEllipse( 9, -9, 19, 18 );
head.graphics.endFill();
ant.addChild( head );
var body:Shape = new Shape();
body.graphics.beginFill(0x000000, 1);
body.graphics.drawEllipse( -14, -10, 28, 20 );
body.graphics.endFill();
ant.addChild( body );
var reg:Shape = new Shape();
reg.graphics.lineStyle (2, 0x000000, 1);
reg.graphics.moveTo (10, 0);
reg.graphics.lineTo (15, 15);
reg.graphics.lineTo (30, 20);
reg.graphics.moveTo (10, 0);
reg.graphics.lineTo (15, -15);
reg.graphics.lineTo (30, -20);
reg.graphics.moveTo (0, 0);
reg.graphics.lineTo (0, 15);
reg.graphics.lineTo ( -10, 20);
reg.graphics.moveTo (0, 0);
reg.graphics.lineTo (0, -15);
reg.graphics.lineTo ( -10, -20);
reg.graphics.moveTo ( -10, 0);
reg.graphics.lineTo ( -15, 15);
reg.graphics.lineTo ( -30, 20);
reg.graphics.moveTo ( -10, 0);
reg.graphics.lineTo ( -15, -15);
reg.graphics.lineTo ( -30, -20);
ant.addChild(reg);
}
private function loop( e:Event ):void {
var len:int = particleList.length;
var arrow:Arrow;
buffer.lock();
//buffer.colorTransform(buffer.rect, new ColorTransform(1, 1, 1, 0));
buffer.fillRect(buffer.rect , 0xFFFFFFFF);
//particleList.sortOn("speed", Array.NUMERIC);
for (var i:int = 0; i < len; i++) {
arrow = particleList[i];
//arrow.step(forceMap.getPixel( arrow.x >> 1, arrow.y >> 1));
arrow.step(Math.random()*0xFFFFFF);
point.x = arrow.x-arrow.img.cx;
point.y = arrow.y-arrow.img.cy;
buffer.copyPixels(arrow.img.bmp, arrow.img.bmp.rect, point, null, null, true);
}
buffer.unlock();
}
private function resetFunc(e:Event = null):void {
forceMap.perlinNoise(117, 117, 3, seed, false, true, 6, false, offset);
offset[0].x += 1.5;
offset[1].y += 1;
seed = Math.floor( Math.random() * 0xFFFFFF );
}
}
}
import flash.display.*;
import flash.geom.*;
const NUM_PARTICLE:uint = 2000;
const ROT_STEPS:int = 128;
const ALPHA_STEPS:int = 20;
var rotArr:Vector.<DisplayImage> = new Vector.<DisplayImage>(ROT_STEPS * ALPHA_STEPS, true);
var multiplyConst:Number = 64 / Math.PI;
class DisplayImage {
public var bmp:BitmapData;
public var rect:Rectangle;
public var cx:int, cy:int;
function DisplayImage(bmp:BitmapData, cx:int, cy:int) {
this.bmp = bmp;
this.rect = bmp.rect;
this.cx = cx;
this.cy = cy;
trimming();
}
private function trimming():void {
var rect:Rectangle = bmp.getColorBoundsRect(0xFF000000, 0x00000000);
var temp:BitmapData = new BitmapData(rect.width, rect.height, true, 0x00000000);
cx -= rect.x;
cy -= rect.y;
temp.copyPixels(bmp, rect, new Point(0, 0));
bmp = temp;
}
}
class Arrow {
public var img:DisplayImage;
public var x:int, y:int;
public var vx:Number = 0, vy:Number = 0, ax:Number = 0, ay:Number = 0;
public var rot:int = 0, speed:int = 0;
function Arrow(x:int, y:int) {
this.x = x;
this.y = y;
}
public function step(col:uint):void {
if (Math.random()*5>>0)
{
ax += ( (col & 0xff) - 0x80 ) * .0002;
ay += ( (col >> 8 & 0xff) - 0x80 ) * .0002;
vx += ax;
vy += ay;
x += vx;
y += vy;
var dir:Number = Math.atan2( vy, vx );
rot = ((128 + dir * multiplyConst) & 127);
speed = Math.min(ALPHA_STEPS-1, (vx*vx + vy*vy) >> 1); // *0.5
}
img = rotArr[rot + (Math.random()*10>>0) + ROT_STEPS * speed];
ax *= .96;
ay *= .96;
vx *= .92;
vy *= .92;
( x > 465 ) ? x = 1 : ( x < 1 ) ? x = 465 : 0;
( y > 465 ) ? y = 1 : ( y < 1 ) ? y = 465 : 0;
}
}