Question

I made a particle class following a tutorial a while ago. Basically it uses some sort of a virtual list, replacing the array method, which makes it really fast solution. So everything is working perfectly fine except the fact that i really can't understand what actually is going on. It is pretty confusing so im trying to find the logic in this stuff, unfortunately with no success. I will be glad if someone can really explain this , so i can get it to something usefull.

package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import Part;
    import FPSCounter;

    public class Pixels extends Sprite
    {
        private var num:int = 500000;
        private var sw:Number = stage.stageWidth;
        private var sh:Number = stage.stageHeight;
        private var bdata:BitmapData=new BitmapData(sw,sh,false,0x111111);
        private var bmp:Bitmap = new Bitmap(bdata);
        private var firstParticle:Part;
        private var radius:Number;
        private var range:Number;
        private var color:uint = 0xffffff;

        public function Pixels()
        {
            addChild(bmp);
            addChild(new FPSCounter());
            createParticles();
            addEventListener(Event.ENTER_FRAME,anim);
        }

        private function createParticles():void
        {
            var lastParticle:Part;

            for (var i:int = 0; i < num; i++)
            {
                radius = Math.random() * (2 * Math.PI);
                range = Math.random() * (2 * Math.PI);
                var thisP:Part = new Part;
                thisP.x = sw / 2;
                thisP.y = sh / 2;
                thisP.xvel=Math.sin(range) * radius;
                thisP.yvel = Math.cos(range) * radius;

                if (i == 0) 
                {
                    firstParticle = thisP;                      }

                else
                {
                    lastParticle.next = thisP; // ???? 
                }

                lastParticle = thisP; 
            }
        }

        private function anim(event:Event):void
        {
            var p:Part = firstParticle;
            bdata.lock();
            p = firstParticle;
            bdata.fillRect(bdata.rect, 0x111111);

            do 
            {
                p.y += p.xvel;
                p.x += p.yvel;

                bdata.setPixel(p.x, p.y, color);
                p = p.next;
            } 
            while (p != null)

            bdata.unlock();
        }
    }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top