Tag Archives: sine

setPixel() Radial Gradient

Actionscript:
  1. // add a BitmapData object to the stage in one line:
  2. addChild(new Bitmap(new BitmapData(200,200,false,0x00000)));
  3.  
  4. // draw a radial gradient
  5. for (var i:int = 0; i<200; i++) for (var j:int = 0; j<200; j++)
  6. Bitmap(getChildAt(0)).bitmapData.setPixel( i, j, 100 + 100 * Math.sin(Math.sqrt(Math.pow(i - 100, 2)+Math.pow(j - 100, 2)) * 40 * Math.PI/180) <<16 );
  7.  
  8. /*
  9. WARNING: This code was written for fun. Use at your own risk.
  10. */

Next I'll post a readable version, just wanted to see how compact I could get this...

This was inspired by all the pixel bender stuff that I've seen. I did the same thing with setVector() - will post about setVector() in the future.

Posted in BitmapData, pixel manipulation, setPixel | Also tagged , | Leave a comment