BitmapData Static

  1. var canvas:BitmapData = new BitmapData(500,500,false, 0x000000);
  2. addChild(new Bitmap(canvas));
  4. var pix:Vector.<uint> = new Vector.<uint>(canvas.width * canvas.height, true);
  6. addEventListener(Event.ENTER_FRAME, onLoop);
  7. function onLoop(evt:Event):void {
  8.     canvas.lock();
  9.     var i:int = pix.length;
  10.     while(--i> -1){
  11.         var c:uint = uint(Math.random() * 255);
  12.         pix[i] = c <<16 | c <<8 | c;
  13.     }
  14.     canvas.setVector(canvas.rect, pix);
  15.     canvas.unlock();
  16. }

This is an easy way to fill a BitmapData Object up with a bunch of TV-style static....

This post is meant to serve as filler while I work to get a good solid SIMPLE fp10, drawing api z-sorting example going... There seem to be 3 main ways of doing z-sorting all of which don't seem right to me for some reason... they all work... but I have a gut feeling there is a faster way... The winner so far (unexpectedly) is using Array.sortOn

This entry was posted in BitmapData, Vector, misc and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Posted August 24, 2009 at 7:07 pm | Permalink

    …and the other methods are? ;)

  2. Posted August 24, 2009 at 9:13 pm | Permalink

    1) Vector.sort (very slow for some reason)
    2) CustomVector sort (Quicksort, flashSort etc…) - can almost get it as fast as Array.sortOn, but a few ms behind
    3) Custom vector sortOn (faster than Vector.sort, but still slow - slower than QuickSort, flashSort etc…)

    There are more methods, those are the ones I was trying…. basically I’m going to make sure I can’t get any faster than Array.sortOn… once I do that I’ll create a demo using Array.sortOn…. then I’ll look into using Haxe, Alchemy and or PixelBender (although pretty sure PixelBender is NOT the way to go)…

  3. Posted August 27, 2009 at 11:52 am | Permalink

    and what’s wrong with noise () method…

  4. Posted August 28, 2009 at 1:29 am | Permalink

    nothing… and since it’s built in the BitmapData.noise() method will probably be faster than this. Like I said, this is just a filler post.

  5. Posted August 28, 2009 at 9:28 am | Permalink

    That doesn’t surprise me. if i remember correctly the Array.sortOn method combines quicksort and mergesort, which i’m pretty sure are quick sorting algs.

One Trackback

  1. By The facts about 3-D TV | on June 27, 2010 at 8:33 am

    [...] BitmapData Static [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *