Category Archives: BitmapData

Hidden Sierpiński

Actionscript:
  1. var canvas:BitmapData=new BitmapData(255,255,false,0x000000);
  2. addChild(new Bitmap(canvas, "auto", true));
  3.  
  4. scaleX = scaleY = 1.5;
  5.  
  6. addEventListener(Event.ENTER_FRAME, onLoop);
  7. function onLoop(evt:Event):void {
  8.     for (var i:int  = 0; i<canvas.width * canvas.height; i++) {
  9.         var ox:int= i % canvas.width;
  10.         var oy:int= i / canvas.width;
  11.         var col =  (ox | oy) * mouseX % 255;
  12.         canvas.setPixel(ox, oy, col <<16 | col <<8 | col);
  13.     }
  14. }

Sometimes when I'm writing a program that does some pixel pushing I'll save the file and then start arbitrarily adding bitwise operations to it.... just to see what happens. Sierpinski-esque stuff occurs often. This will work in your timeline - move your mouse left and right to generate images like these:





Also posted in pixel manipulation, setPixel | Tagged , , | Leave a comment

Texture cos(atan2())

Actionscript:
  1. var col:int, i:int, j:int, s:int = 500, div:Number =20, outcoord:Point = new Point(), points:Vector.<Point> = new Vector.<Point>();
  2. for (i = 0; i<5; i++) points.push(new Point(int(Math.random()*s),int(Math.random()*s)));
  3. var canvas:Bitmap = Bitmap(addChild(new Bitmap(new BitmapData(s,s, false, 0xFF0000), "auto", true)));
  4. for (i  = 0; i<canvas.width * canvas.height; i++){
  5.     outcoord= new Point( i % canvas.width, i / canvas.width);
  6.     col = 0;
  7.     for (j= 0; j<points.length; j++) col += Math.max(0,255 * Math.cos(Math.atan2(outcoord.y - points[j].y, outcoord.x - points[j].x)*outcoord.x/div) );
  8.     col /= points.length;
  9.     canvas.bitmapData.setPixel(outcoord.x, outcoord.y,  col <<16 |  col <<8 |  col);
  10. }

This is inspired by some stuff I've been doing with PixelBender. I think I'm going to convert this to processing to see how fast I can get it to run... will post that over at shapevent. People have been asking me to post swfs.... and I plan on starting to that a little bit... but since this one doesn't animate, here are a few jpgs:

Also posted in pixel manipulation, setPixel | Tagged , | Leave a comment

new BitmapData() One-Liner

Actionscript:
  1. Bitmap(addChild(new Bitmap(new BitmapData(100,100,false,0x000000)))).bitmapData.fillRect(new Rectangle(10,10,10,10), 0xFF0000);

Also posted in one-liners | Tagged , | Leave a comment

perlinNoise()

Actionscript:
  1. var canvas:BitmapData = new BitmapData(400,400,false, 0x000000);
  2. addChild(new Bitmap(canvas));
  3.  
  4. addEventListener(Event.ENTER_FRAME, onLoop);
  5. function onLoop(evt:Event):void {
  6.   canvas.perlinNoise(200,200, 2, 1, true, false,0, true,
  7.                               [new Point(mouseX, mouseY),
  8.                               new Point(-mouseX, -mouseY)]);
  9.                                                                                    
  10. }

There area few snippets on the way that involve perlin noise. Starting here with something simple. This creates 2 octave perlin noise and moves each octave based on the mouse location.

Perlin noise was invented by Ken Perlin.

Also posted in pixel manipulation | Tagged , , , | 1 Comment