In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Apparition Titre Apparence particule

Get Adobe Flash player
by Etienne.Verhote 08 Mar 2012
    Embed
// forked from bradsedito's forked from: forked from: forked from: particleText
// forked from Laurence.Bannister's forked from: forked from: particleText
// forked from bradsedito's forked from: particleText
// forked from dimentity's particleText
// MdN BOOKS - THE NETA-cho Deluxe FLASH TECHNIC 参考
// wonderfl用にクラスを1つにまとめました。
// コメント省いてすみません。

package {
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.geom.Rectangle;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    [SWF(width = "800", height = "265", backgroundColor = "0x000000", frameRate = "30")]

    public class ParticleText extends Sprite {
        private var canvas:BitmapData;
        private var textCanvas:BitmapData;
        private var _num:int = 0;
        private var maxDis:int = 400;
        
        // particles
        private var particleX:Array = new Array();
        private var particleY:Array = new Array();
        private var particleEx:Array = new Array();
        private var particleEy:Array = new Array();
        private var particleC:Array = new Array();
        
        public function ParticleText() {
            canvas = new BitmapData(
                stage.stageWidth,
                stage.stageHeight,
                false,
                0x000000
            );
            addChild(new Bitmap(canvas));
            
            var tf:TextField = new TextField();
            tf.defaultTextFormat = new TextFormat(
                "Edwardian Script ITC",
                80,
                0xFFFFFF
            );
            tf.autoSize = TextFieldAutoSize.LEFT;
            tf.text = "Le Créateur d'apparences. \n Créateur de vêtements magiques  ";
            
            textCanvas = new BitmapData(
                tf.textWidth,
                tf.textHeight,
                false,
                0x000000
            );
            
            textCanvas.draw(tf);
            
            var ofx:Number = stage.stageWidth / 2 - textCanvas.width / 2;
            var ofy:Number = stage.stageHeight / 2 - textCanvas.height / 2;
            
            var num:Number = 0;
            var rad:Number;
            var dis:Number;

            for (var ex:Number = 0; ex < textCanvas.width; ex++) {
                for (var ey:Number = 0; ey < textCanvas.height; ey++) {
                    var c:uint = textCanvas.getPixel(ex, ey);
                    if (c != 0x000000) {
                        particleEx[num] = ex + ofx;
                        particleEy[num] = ey + ofy;
                        particleC[num] = c;
                        rad = Math.random() * (Math.PI * 2);
                        dis = Math.random() * maxDis;
                        particleX[num] = ex + dis * Math.cos(rad);
                        particleY[num] = ex + dis * Math.sin(rad);
                        num++;
                    }
                }
            }

            stage.addEventListener(Event.ENTER_FRAME, onEnterframe);
        }

        private function onEnterframe( evt:Event ):void {
            canvas.lock();
            canvas.fillRect(canvas.rect, 0x000000);
            for(var i:int = 0; i < _num; i++) {
                if(Math.abs(particleEx[i] - particleX[i]) < 0.5 &&
                     Math.abs(particleEy[i] - particleY[i]) < 0.5) {
                    particleX[i] = particleEx[i];
                    particleY[i] = particleEy[i];
                } else {
                    particleX[i] += (particleEx[i] - particleX[i]) * 0.1;
                    particleY[i] += (particleEy[i] - particleY[i]) * 0.1;
                }
                canvas.setPixel(particleX[i], particleY[i], particleC[i]);
            }
            
            var n:int = particleX.length;
            
            _num = (_num + 30 < n) ? _num + 30 : particleX.length;
            canvas.unlock();
        }
    }
}