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: forked from: 10万個ぱーてぃくる

Radioactive Fog
Get Adobe Flash player
by correa_elias 07 Nov 2009
// forked from correa_elias's forked from: forked from: 10万個ぱーてぃくる
//Radioactive Fog

package {
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
	
    public class Particles extends Sprite {
        protected const NUM_OF_PARTICLES:int=5000;
        protected const WIDTH:int=320;
        protected const HEIGHT:int=240;
        protected const BLUR:int=14;
        
        public var color:uint=0xffffff;
            
        private var main: TestMain;
        protected var timer:Timer;
		
        public function Particles() {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
		
        private function init(e:Event = null):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            main = new TestMain(WIDTH, HEIGHT, NUM_OF_PARTICLES, color, BLUR);
            main.resize(stage.stageWidth, stage.stageHeight);
	      addChild(main.view);
           
		stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.addEventListener(Event.RESIZE, onResize);
            addEventListener(Event.ENTER_FRAME, onEnter);
			
		timer=new Timer(5000);
		timer.addEventListener(TimerEvent.TIMER, changeForceMap);
		timer.start();
        }
		
        private function changeForceMap(event:TimerEvent):void{
        	var r:int=Math.random()*0xff;
            var g:int=Math.random()*0xff;
            var b:int=Math.random()*0xff;
            main.c=r<<16 | g<<8 | b;
                    	
        	main.change();
        }
		
        private function onEnter(e:Event):void {
            main.draw(mouseX, mouseY);
        }

         private function onResize(e:Event):void {
            main.resize(stage.stageWidth, stage.stageHeight);
        }
    }
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.utils.ByteArray;
import flash.filters.BlurFilter;

class TestMain {
    private var w: int;
    private var h: int;
    private var mw: int;
    private var mh: int;
    public var view: Bitmap;
    private var bmpData: BitmapData;
    private var forceMap: BitmapData;
    private var randomSeed: int;
    private var particles: Array = [];
    private var num: int;
    private var count: int = 0;
    private var colorTr: ColorTransform;
    public var c:uint;
    private var b:int;
	
    public function TestMain(w: int, h: int, numOfParticles: int, color:uint, blur:int){
        this.w = w;
        mw = w >> 1;
        this.h = h;
        mh = h >> 1;
        bmpData = new BitmapData(w, h, false, 0x00000000);
        forceMap = new BitmapData(mw, mh, false);
        forceMap.perlinNoise(mw >> 1, mh >> 1, 4, Math.random() * 0xFFFF, false, true, 3);
        view = new Bitmap(bmpData);
        num = numOfParticles;
        var i: int;
        var p: Particle;
        while (i < num) {
            p = new Particle();
            p.x = Math.random() * w;
            p.y = Math.random() * h;
            particles.push(p);
            i++;
        }
        colorTr = new ColorTransform(1, 1, 1, 1, 3, 2, 0, -2);
        c=color;
        b=blur;
    }

     public function draw(mouseX: Number, mouseY: Number): void {
        var i: int;
        var p: Particle;
        var col: uint;
        bmpData.lock();
        bmpData.colorTransform(bmpData.rect, colorTr);
        while (i < num) {
            p = Particle(particles[i]);
            col = forceMap.getPixel(p.x >> 1, p.y >> 1);
            p.vx = p.vx * 0.98 + (( col >> 16 & 0xff)-128) * 0.004;
            p.vy = p.vy * 0.98 + (( col >> 8 & 0xff)-128) * 0.004;
            p.x += p.vx;
            p.y += p.vy;
            if (p.x < 0) p.x += w;
            else if (p.x >= w) p.x -= w;
            if (p.y < 0) p.y += h;
            else if (p.y >= h) p.y -= h;
            bmpData.setPixel(p.x, p.y, c);
            i++;
        }
        bmpData.unlock();
        bmpData.applyFilter(bmpData, bmpData.rect, new Point(), new BlurFilter(b,b,1));
    }
	
    public function change(): void {
        forceMap.perlinNoise(mw, mh, 4, Math.random() * 0xFFFF, false, true, 7);
    }
	
    public function resize(w: Number, h: Number): void {
        view.width=w;
        view.height=h;
    }
}

class Particle {
    public var x: Number = 0;
    public var y: Number = 0;
    public var vx: Number = 0;
    public var vy: Number = 0;
}