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

forked from: パーティクルの練習

// forked from matsu4512's パーティクルの練習
package {
    
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    [SWF(width="500",height="500")]
    
    public class String_Particle extends Sprite
    {
        
        private var canvas:BitmapData;
        private var p_num:int;
        private var particles:Array = new Array();
        
        public function String_Particle(){
            canvas = new BitmapData(500,500,false,0x00000);
            addChild(new Bitmap(canvas));
            
            var tf:TextField = new TextField;
            tf.defaultTextFormat = new TextFormat("Helvetica",70,0xffffff);
            tf.autoSize = TextFieldAutoSize.LEFT;
            tf.text = "Hello,world!";
        
            
            /*
            var sp:Shape = new Shape();
            sp.graphics.beginFill(0xFFFFFF);
            sp.graphics.drawCircle(250,250,50);
            */
            canvas.draw(tf);
            
            
            
            for(var ex:int=0; ex<canvas.width; ex++){
                for(var ey:int = 0; ey<canvas.height; ey++){
                    var c:uint = canvas.getPixel(ex,ey);
                    
                    if(!c == 0x000000){
                        createParticle(ex,ey,c);
                    }
                }
            }
            
            addEventListener(Event.ENTER_FRAME,loop);
        }
        
        private function createParticle(ex:int,ey:int,c:uint):void{
            var particle:Particle = new Particle();
            
            var rad:Number = Math.random() * Math.PI * 2;
            var dis:Number = Math.random() * 300;
            particle.x = ex + dis * Math.cos(rad);
            particle.y = ey + dis * Math.sin(rad);
            particle.ex = ex;
            particle.ey = ey;
            particle.c = c;
            
            particles.push(particle);
        }
        
        private function pixles():void{
            var c:uint = 0xFF0000;
            canvas.setPixel(450,450,c);
        }
        
        
        private function loop(e:Event):void{
            canvas.unlock();
            canvas.fillRect(canvas.rect, 0x000000);
            
            for(var i:int=0; i<p_num; i++){
                
                particles[i].x +=(particles[i].ex - particles[i].x)*0.3;
                particles[i].y +=(particles[i].ey - particles[i].y)*0.3;
                
                if( Math.abs(particles[i].ex - particles[i].x) < 0.3 || Math.abs(particles[i].ey - particles[i].y) < 0.3){
                    particles[i].x =  particles[i].ex;
                    particles[i].y =  particles[i].ey;
                }
                
                canvas.setPixel(particles[i].x, particles[i].y, particles[i].c);
            }
            
            
            var n:uint = particles.length;
            p_num = (p_num + 100 < n) ? p_num + 100 : n;
            
            
            canvas.lock();
        }
    }
}


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(){
        x = 0;
        y = 0;
        ex = 0;
        ey = 0;
        c = 0;
    }
}