Gaming Your Way

May contain nuts.

Kaleidoscope effect ( Plasma revisited )

I needed a bit of a break from all things gamey this evening, so I looked back over my old plasma source.

By stripping the maths down to the bare minimum and using a for...each loop along with other bits and bobs ( Double buffering the screen helped too ) I managed to increase the fps from the 31/32 mark to 42/43.
Pretty sweet.

I thought I could either post it like that, smug in the knowledge that I've speeded up a pretty intensive routine by ( In real terms ) quite a lot, or do something slightly different.

I opted for a bit of a play, and was really surprised ( And pleased ) to see you can attach the same bitmap to multiple sprites and it still updates. From there it was a no brainer what to do with it. In real terms this is plotting less pixels than the plasma effect ( That was 150x150 doubled ), this is a 120x120, but it's a much bigger effect in terms of screen size.

Kaleidoscope

Squize.


Comments (4) -

  • Rich

    9/10/2008 8:49:42 AM |

    Kaleidoscopes... aka "I only have to do a quarter of the work to achieve the effect" :) How are you doing the palette? (HSV cycle, or something else?)

  • tonypa

    9/10/2008 1:59:45 PM |

    Your experiments usually run slowly in my poor Opera but this is very fast (I get 48 fps). Looks good too :)

  • Squize

    9/10/2008 3:30:41 PM |

    Hi guys,

    The plasma effect is the same as the one before, so a pre-calculated colour table and using some sine values you to read it and then setPixel to plot it.

    private function createColourTable():void{
      colourTable=new Array();
      var cnt:Number=-1;
      var col:Number;
      var r:int;
      var g:int;
      var b:int;
      var offset:Number=3.1415;

    //To avoid /4 for each pixel every frame, we just make the colour table 4 times as big
      while(++cnt!=256*4){
        r = 128 + 128 * Math.sin(offset * cnt / 32);
                    g = 128 + 128 * Math.sin(offset * cnt / 64);
              b = 128 + 128 * Math.sin(offset * cnt / 128);
        col=(r << 16)+(g << 8)+b;
        colourTable.push(col);
        colourTable.push(col);
        colourTable.push(col);
        colourTable.push(col);
      }
    }

    The tricky bit, aside from keeping it running quick, is picking a good formula to run through the colours.

    And yep Kaleidoscopes are just a big hacky cheat :)

    Glad it runs ok for you Tony. To be honest with all the experiments I just drop a swf down, I imagine it would pick up some fps if I bothered embedding them in a html page ( That's before using any wmode workarounds ).
    Also some I just pump up to 120fps to see how they perform when messing with the code, which actually has an adverse effect on the overall performance.

    With both this and the tunnel effect I'm hitting a lot of pixels every frame ( 14,400 pixels in this effect ), I was toying with the idea of using lots of sprites instead and just colour tinting them. I'm not sure if it'll work out better or not.
    When not plotting pixels the code runs around 10fps quicker, when not running the maths it's 20fps quicker, so it's not the actual plotting which is hurting this.

Comments are closed