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

Plasma demo

Flash version of http://lib.ivank.net/?p=demos&d=plasma
Get Adobe Flash player
by Ivan_Kuckir 14 Mar 2014
    Embed
/**
 * Copyright Ivan_Kuckir ( http://wonderfl.net/user/Ivan_Kuckir )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/z18D
 */

package 
{
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.utils.ByteArray;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class Demo extends Sprite 
    {
        var bd, time=0;
        var a=1, b=2, c=1, d=1, e=1;
        var sin:Array = new Array(512);
        var w=400, h=200;
        
        public function Demo() 
        {
            stage.frameRate = 60;
            for (var i=0; i<512; i++) sin[i] = Math.round(Math.sin(2*Math.PI/512*i) * 127 + 127);            

            bd = new BitmapData(w, h, true, 0xff000000);
            var bm = new Bitmap(bd);
            bm.scaleX = stage.stageWidth/w;
            bm.scaleY = stage.stageHeight/h;
            stage.addChild(bm);
            stage.addEventListener(Event.ENTER_FRAME, onEF);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMD);
        }
        
        function onEF(ev) { drawPlasma(); time++; }

        function drawPlasma()
        {
            var hh = h*0.5 +10*d-400;
            var hw = w*0.5 +10*e-400;
            var fr = time<<2, i3 = 1/3;
            var am = a-1, bm = b-1, es = e<<2;
            for(var y=0; y<h; y++)    // rows
                for(var x=0; x<w; x++)    // columns
                {
                   var di = Math.floor( Math.sqrt((hh-y)*(hh-y) + (hw-x)*(hw-x)) );
                    var hi = (sin[(x*b+fr)&511]+sin[(di*a+fr*b)&511]+sin[359-(y*a+x*b+fr)&511])*i3;
                    var re = sin[((hi << am)+d)  & 511];
                    var gr = sin[((hi << bm)+es) & 511];
                    var bl = sin[ (hi << bm)     & 511];
                    bd.setPixel(x,y,(re<<16 | gr<<8 | bl));
                }
                
        }
        function onMD(ev) { a = rand(4); b = rand(4); c = rand(8); d = rand(180); e = rand(180); }
        function rand(n)  { return 1+Math.floor(Math.random()*n); }
    }
}