パーティクルでテキストは重い。
テキストはシェイプより重い。
矢印 100個
@author paq
// forked from paq's cacheAsBitmapを使うと高速化するよ
// forked from clockmaker's シェイプだけだともっさりするよ
// forked from clockmaker's 3D Flow Simulation with Field of Blur
// forked from clockmaker's 3D Flow Simulation
// forked from clockmaker's Interactive Liquid 10000
// forked from clockmaker's Liquid110000 By Vector
// forked from munegon's forked from: forked from: forked from: forked from: Liquid10000
// forked from Saqoosha's forked from: forked from: forked from: Liquid10000
// forked from nutsu's forked from: forked from: Liquid10000
// forked from nutsu's forked from: Liquid10000
// forked from zin0086's Liquid10000
package
{
/**
* テキストはシェイプより重い。
* 矢印 100個
* @author paq
*/
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.utils.*;
import flash.geom.*;
import net.hires.debug.Stats;
[SWF(width="465", height="465", backgroundColor="0xFFFFFF")]
public class MainGr extends Sprite {
private const NUM_PARTICLE:uint = 100;
private var forceMap:BitmapData = new BitmapData( 233, 233, false, 0x000000 );
private var randomSeed:uint = Math.floor( Math.random() * 0xFFFF );
private var particleList:Vector.<TextParticle> = new Vector.<TextParticle>(NUM_PARTICLE, true);
private var rect:Rectangle = new Rectangle( 0, 0, 465, 465 );
private var seed:Number = Math.floor( Math.random() * 0xFFFF );
private var offset:Array = [new Point(), new Point()];
private var timer:Timer;
private var world:Sprite = new Sprite();
public function MainGr() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.frameRate = 60;
addChild(world);
// フォースマップの初期化をおこないます
resetFunc();
// ループ処理
addEventListener( Event.ENTER_FRAME, loop );
// 時間差でフォースマップと色変化の具合を変更しています
var timer:Timer = new Timer(1000)
timer.addEventListener(TimerEvent.TIMER, resetFunc);
timer.start();
// パーティクルを生成します
for (var i:int = 0; i < NUM_PARTICLE; i++) {
var px:Number = Math.random() * 465;
var py:Number = Math.random() * 465;
particleList[i] = new TextParticle(px, py);
world.addChild(particleList[i]);
}
// デバッグ用のスタッツを表示しています
addChild(new Stats);
}
private function loop( e:Event ):void {
var len:uint = particleList.length;
var col:Number;
for (var i:uint = 0; i < len; i++) {
var txt:TextParticle = particleList[i];
var oldX:Number = txt.x;
var oldY:Number = txt.y;
col = forceMap.getPixel( txt.x >> 1, txt.y >> 1);
txt.ax += ( (col & 0xff) - 0x80 ) * .0005;
txt.ay += ( (col >> 8 & 0xff) - 0x80 ) * .0005;
txt.vx += txt.ax;
txt.vy += txt.ay;
txt.x += txt.vx;
txt.y += txt.vy;
var _posX:Number = txt.x;
var _posY:Number = txt.y;
//txt.rotation = - Math.atan2((_posX - oldX), (_posY - oldY)) * 180 / Math.PI + 90;
txt.ax *= .96;
txt.ay *= .96;
txt.vx *= .92;
txt.vy *= .92;
( _posX > 465 ) ? txt.x = 0 :
( _posX < 0 ) ? txt.x = 465 : 0;
( _posY > 465 ) ? txt.y = 0 :
( _posY < 0 ) ? txt.y = 465 : 0;
}
}
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.text.TextField;
import flash.text.TextFormat;
class TextParticle extends TextField
{
public var vx:Number = 0;
public var vy:Number = 0;
public var ax:Number = 0;
public var ay:Number = 0;
function TextParticle( x:Number, y:Number) {
this.x = x;
this.y = y;
this.defaultTextFormat = new TextFormat(null, Math.floor(2+Math.random()*25));
this.text = "Wonderfl!";
this.cacheAsBitmap = true;
}
}