ActionScript3で、文字列を使ったアニメーションの習作を作成してみました。
AS3は、こういった処理をするが非常に楽です。
package practice { import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFieldType; [SWF(width = "440", height = "360", backgroundColor = "0xffffff", fps = "60")] public class Practice97 extends Sprite { private var list:Array; private var mode:Boolean; private var line:Array; public function Practice97() { list = new Array(); line = new Array(); var s1:Sprite = new Sprite(); s1.graphics.beginFill(0x007700,0.4); s1.graphics.drawRect(0, 0, 400, 80); s1.graphics.endFill(); s1.x = 1000; s1.y = 90; line.push(s1); addChild(s1); init(); stage.addEventListener(MouseEvent.MOUSE_UP, function up(e:MouseEvent):void { init(); } ); } private function init( ):void { while (this.numChildren > 1)this.removeChildAt(this.numChildren-1); while (list.length > 0) list.pop(); mode = false; insert("TM's", 64, -30, 50); insert("WorkSpace", 64, -30, 120); insert(" since 2009", 32, 0, 220); insert(" -- Java,js,as3 and more", 24, -30, 300); addEventListener(Event.ENTER_FRAME, update); } private function insert(str:String, size:int, xx:int, yy:int):void { for (var i:int = 0; i < str.length; i++) { if (xx > 420) { xx = size*.75; yy += size * .75; } xx += size*.75; var c:Strings = new Strings(str.charAt(i),xx,yy,size); c.x = Math.random() * 440; c.y = Math.random() * 440; c.z = -Math.random() * 10000; c.scale(Math.random() * 30 + 10); addChild(c); list.push(c); } } private function update(e:Event):void { var minz:Number = 100000000; for each(var p:Strings in list) { p.update(mode); if (!mode && p.z < minz) minz = p.z; } if (minz > 4000) mode = true; if (mode) { for each(var q:Sprite in line) { q.x += ( 20 - q.x) * 0.05; } } } } } import flash.display.Sprite; import flash.events.Event; import flash.filters.BlurFilter; import flash.filters.DropShadowFilter; import flash.text.TextField; import flash.text.TextFormat; class Strings extends Sprite { private var text:TextField; private var vec:Array; private var blur:BlurFilter; private var drop:DropShadowFilter; private var bx:Number; private var by:Number; public function Strings(s:String, bx:int, by:int, si:int) { this.bx = bx; this.by = by; text = new TextField(); addChild(text); text.background = false; var tf:TextFormat = new TextFormat(); tf.size = si; tf.color = 0x000000; text.defaultTextFormat = tf; text.text = s; text.width = text.textWidth + 5; text.height = text.textHeight + 5; this.rotationZ = Math.random() * 360; vec = [Math.random()*20-10,Math.random()*20-10,Math.random()*50+50]; blur = new BlurFilter(64,64,1); this.filters = [blur]; } public function scale(s:Number):void { this.scaleX = s; this.scaleY = s; } public function update(mode:Boolean):void { if (!mode) { this.x += vec[0]; this.y += vec[1]; this.z += vec[2]; if (this.rotationZ % 360 != 0) this.rotationZ += 1; if (this.z > 0) { var bn:Number= Math.max(1, 10000 / this.z); if (bn > 1) { blur.blurX = bn; blur.blurY = bn; this.filters = [blur]; }else { this.filters = []; } } }else { this.filters = []; this.x += (this.bx - this.x) * 0.1; this.y += (this.by - this.y) * 0.1; this.z += (0 - this.z) * 0.1; this.rotationZ = this.rotationZ % 360; if (this.rotationZ != 0) this.rotationZ += (360 - this.rotationZ) * 0.1; this.scaleX += (1 - this.scaleX) * 0.1; this.scaleY += (1 - this.scaleY) * 0.1; } } }