Monthly Archives: January 2009

Point.polar() Stars

Actionscript:
  1. [SWF(width=700, height=400, backgroundColor=0x000000, frameRate=30)]
  2.  
  3. var points:Array = new Array();
  4. var index:int = -1;
  5. function polar(thetaInc:Number, radius:Number):Point{
  6.     index++;
  7.     if (!points[index]) points[index] = 0;
  8.     return Point.polar(radius, points[index] += thetaInc)
  9. }
  10. ///////////////////////////////////////////////////
  11. // test it out:
  12.  
  13. var canvas:BitmapData = new BitmapData(700, 400, false, 0xFFFFFF);
  14.  
  15. addChild(new Bitmap(canvas, "auto", true));
  16.  
  17. var p0:Point = new Point(200, 200);
  18. var p1:Point = new Point(500, 200);
  19.  
  20. addEventListener(Event.ENTER_FRAME, onLoop);
  21. function onLoop(evt:Event):void {
  22.    
  23.     var rad:Point = polar(.05, 4);
  24.      
  25.     for (var i:int= 0; i<100; i++){
  26.        
  27.         // reset index;
  28.         index = -1;
  29.        
  30.         p0 = p0.add(polar(.025, 2).add(polar(-.05,rad.x)));
  31.         canvas.setPixel(p0.x, p0.y, 0x000000);
  32.        
  33.         p1 = p1.add(polar(.025, 2).add(polar(-.05,rad.x).add(polar(.1, rad.y))));
  34.         canvas.setPixel(p1.x, p1.y, 0x000000);
  35.     }
  36. }

This is pretty much the same as yesterdays... I just changed the way I use the polar() function to draw two more shapes:

Posted in BitmapData, motion, setPixel | Tagged , | Leave a comment

Playing with Curves Point.polar()

Actionscript:
  1. [SWF(width=600, height=500, backgroundColor=0x000000, frameRate=30)]
  2. var points:Array = new Array();
  3. var index:int = -1;
  4. function polar(thetaInc:Number, radius:Number):Point{
  5.     index++;
  6.     if (!points[index]) points[index] = 0;
  7.     return Point.polar(radius, points[index] += thetaInc);
  8. }
  9. ///////////////////////////////////////////////////
  10. // test it out:
  11.  
  12. var canvas:BitmapData = new BitmapData(600, 500, false, 0xFFFFFF);
  13.  
  14. addChild(new Bitmap(canvas, "auto", true));
  15.  
  16. var p0:Point = new Point(80, 100);
  17. var p1:Point = new Point(270, 100);
  18. var p2:Point = new Point(480, 40);
  19. var p3:Point = new Point(170, 180);
  20. var p4:Point = new Point(430, 300);
  21.  
  22. addEventListener(Event.ENTER_FRAME, onLoop);
  23. function onLoop(evt:Event):void {
  24.     for (var i:int= 0; i<100; i++){
  25.        
  26.         // reset index;
  27.         index = -1;
  28.        
  29.         p0 = p0.add(polar(.2, 4).add(polar(-.4,2).add(polar(.05, 1))));
  30.         canvas.setPixel(p0.x, p0.y, 0x000000);
  31.    
  32.         p1 = p1.add(polar(.1, 2).add(polar(-.2, 2).add(polar(.03, 1).add(polar(-.01,.5)))));
  33.         canvas.setPixel(p1.x, p1.y, 0x000000);
  34.      
  35.         p2 = p2.add(polar(.08, 3 ).add(polar(-.2, -12).add(polar(2, 10))));
  36.         canvas.setPixel(p2.x, p2.y, 0x000000);
  37.      
  38.         p3 = p3.add(polar(.08, 7).add(polar(-.2, -12).add(polar(2, 11))));
  39.         canvas.setPixel(p3.x, p3.y, 0x000000);
  40.        
  41.         p4 = p4.add(polar(.025, 2).add(polar(-.05,1)));
  42.         canvas.setPixel(p4.x, p4.y, 0x000000);
  43.     }
  44. }

The polar() function is the real trick here... the rest of the code just uses it to draw this:

The Point.polar() function is just a conversion from polar to cartesian coords:

Actionscript:
  1. x = radius * Math.cos(theta);
  2. y = radius * Math.sin(theta);

Posted in motion, setPixel | Tagged , | Leave a comment

Game of Life Snippets

SNIPPET ONE

SNIPPET TWO

I was very impressed when I saw Mario Klingemann's game of line in 3 lines of code blog post late last year. I've been meaning to post about it for awhile - finally got around to it.

Mario Klingemann is the developer of Peacock... an excellent node based image generator written in ActionScript.

BitmapData.paletteMap() is very powerful. I haven't done much with it, but I have some ideas floating around.

For those of you that are game of live savvy... try other rule sets from the lexicon... my personal favorite has always been coral (45678/3). Here's a link to some more.

Another short game of life recently appeared on on the 25lines.com forums.... here... the forum post features a nice explanation for using a ConvolutionFilter and Threshold to create The Game of Life. The technique is so small and impressive looking that I figured I'd post it as is right here:

Actionscript:
  1. addChild(new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, 0)))["bitmapData"].noise(int(Math.random()*int.MAX_VALUE),0,255,7,true);
  2. addEventListener(Event.ENTER_FRAME, function (e) {
  3.    getChildAt(0)["bitmapData"].applyFilter(getChildAt(0)["bitmapData"], getChildAt(0)["bitmapData"].rect, new Point(), new ConvolutionFilter(3, 3, [3,3,3,3,2,3,3,3,3],255,0,true,false,0,1));
  4.    getChildAt(0)["bitmapData"].threshold(getChildAt(0)["bitmapData"], getChildAt(0)["bitmapData"].rect, new Point(), "==", 8, 0xFFFFFFFF, 0xFC);
  5.    getChildAt(0)["bitmapData"].threshold(getChildAt(0)["bitmapData"], getChildAt(0)["bitmapData"].rect, new Point(), "!=", 0xFFFFFFFF, 0x00000000)})

The above code is by Daniil Tutubalin 25lines.com forums.

UPDATE:

Since writing this post the 25lines.com forum thread has grown to include a 4 line version and some additional discussion about this topic... be sure to check it out.

Posted in BitmapData, misc, pixel manipulation | Tagged , | Leave a comment

Parallax Displacement Map w/BlendMode

Actionscript:
  1. var blends:Array = [BlendMode.ADD, BlendMode.DARKEN, BlendMode.DIFFERENCE, BlendMode.HARDLIGHT, BlendMode.INVERT, BlendMode.LIGHTEN, BlendMode.MULTIPLY, BlendMode.OVERLAY, BlendMode.SCREEN, BlendMode.SUBTRACT];

and a little later...

Actionscript:
  1. displace.perlinNoise(150,150, 3, 30, true, false,0,true);
  2. var currentBlend:String = blends[ blendCount % blends.length];
  3. displace.draw(radial, null ,null, currentBlend);
  4. blendCount++;

The above are excepts from a recommendation I made in the comments of yesterdays post...


Try some different blend modes.... take a look at the swf here.

Posted in 3D, BitmapData, misc | Tagged , | Leave a comment