パーティクルテキスト的な
もうちょっと手直ししたいけど
/**
* Copyright 16pavel ( http://wonderfl.net/user/16pavel )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9vyE
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.Timer;
import org.osmf.events.TimeEvent;
[SWF(backgroundColor=0x000000, width="800", height="600")]
public class TekitouParticle extends Sprite
{
//パーティクルをぶっこむ
private var particles:Array;
private var numParticles:uint;
//パーティクル描写
private var canvas:BitmapData;
//private var canvasData:BitmapData;
//テキスト描画
private var textCanvas:BitmapData;
//private var textCanvas2:BitmapData;
//最大距離
private var maxdis:int = 400;
private var tf:TextField;
//private var tf2:TextField;
private var myDate:Date;
private var min:Number;
private var min10:Number;
private var timer:Timer;
public function TekitouParticle()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
canvas = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x000000);
addChild(new Bitmap(canvas));
tf = new TextField();
tf.defaultTextFormat = new TextFormat("Swis721 BdRndBT",80,Math.random() *0xFFFFFF);
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = "IPLFlash会場"; //ここ変えれば表示も変わる
//tf.textColor = Math.random() * 0xffffff;
tf.filters = [new GlowFilter(0xffffff, 1.0, 5, 5)];
//入力から引っ張ってくるためのTextField
/*tf2 = new TextField()
tf.defaultTextFormat = new TextFormat("Swis721 BdRndBT",14,Math.random() *0xFFFFFF);
tf2.x = 100;
tf2.y = 100;
tf2.width = 100;
tf2.height = 100;
tf2.text = "しゃる"
addChild(tf2);
//textCanvas2 = new BitmapData(tf.textWidth, tf.textHeight, false, 0x000000);
//textCanvas2.draw(tf);
//createText();
*/
textCanvas = new BitmapData(tf.textWidth, tf.textHeight, false, 0x000000);
textCanvas.draw(tf);
particles = new Array();
createText();
stage.addEventListener(MouseEvent.CLICK, onClick);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
timer = new Timer(10000);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
}
public function createText():void
{
var ofx:Number = stage.stageWidth / 2 - textCanvas.width /2;
var ofy:Number = stage.stageHeight / 2 - textCanvas.height / 2;
for(var ex:int = 0 ; ex < textCanvas.width ; ex++){
for(var ey:int = 0 ; ey < textCanvas.height ; ey++){
var c:uint = textCanvas.getPixel(ex, ey);
if(c != 0x000000){
createParticle(ex + ofx, ey + ofy, c);
}
}
}
}
public function createParticle(ex:Number, ey:Number, c:uint):void
{
var p:Particle = new Particle();
p.ex = ex;
p.ey = ey;
p.c = c;
initParticle(p);
particles.push(p);
numParticles = 0;
}
public function initParticle(p:Particle):void
{
var rad:Number = Math.random()*(Math.PI * 2);
var dis:Number = Math.random() * maxdis;
p.x = p.ex + dis * Math.cos(rad);
p.y = p.ey + dis * Math.sin(rad);
}
public function onEnterFrame(e:Event):void
{
canvas.lock();
canvas.fillRect(canvas.rect, 0x000000);
for(var i:int = 0 ; i < numParticles ; i++){
var p:Particle = particles[i];
if(Math.abs(p.ex - p.x) < 0.5 && Math.abs(p.ey - p.y) < 0.5){
p.x = p.ex;
p.y = p.ey;
}
else{
p.x += (p.ex - p.x) * 0.2;
p.y += (p.ey - p.y) * 0.2;
}
canvas.setPixel(p.x, p.y, p.c);
}
var n:int = particles.length;
numParticles = (numParticles +150<n)?numParticles + 150:n;
//10を足す。もし、10を足すと超えてしまうならマックスの値をとる()サンプルだと100だった。
canvas.unlock();
}
public function onTimer(e:TimerEvent):void
{
init();
}
public function onClick(e:MouseEvent):void
{
init();
}
public function init():void
{
var n:int = particles.length;
while(n--){
var p:Particle = particles[n];
initParticle(p);
}
numParticles = 0;
}
}
}
class Particle{
public var x:Number;
public var y:Number;
public var ex:Number;
public var ey:Number;
public var c:int;
public function Particle():void
{
x = 0;
y = 0;
ex = 0;
ey = 0;
c = 0;
}
}