Tag Archives: as3

Recursion Form

Actionscript:
  1. x = y = 10
  2. graphics.lineStyle(1,0);
  3. drawBox(6);
  4.  
  5. function drawBox(iter:Number=10, count:Number=1, y:Number=0, w:Number=500):void{
  6.        if (count <iter){
  7.                var width:Number = w / count
  8.                for (var i:int = 0; i<count; i++){
  9.                    graphics.drawRect(i * width, width * count/w, width, width);
  10.                }
  11.                count++;
  12.                drawBox(iter, count, y, width);
  13.        }
  14. }

This small snippet just draws this image:

If you have an idea for a short recursive snippet. Feel free to post it in the comments.

Posted in Graphics, functions | Also tagged , | 6 Comments

QuickBox2D Editor 2B Released

I'll be releasing the QuickBox2D on googlecode in the near future based on the response to yesterdays post.

Posted in QuickBox2D | Also tagged , , , | 16 Comments

AS Quiz #18

Today's quiz is about BitmapData and the Graphics class...

Number of Questions : 5
Difficulty : Medium
Topic : BitmapData, Graphics

True or False. Subpixel x and y coordinates for DisplayObjects are made possible by anti-aliasing.



Which of the following methods would you use to set a pixel with an alpha channel value?





Which of the following methods would you used if you wanted to boost performance when drawing to a BitmapData object?




True or False. Perlin Noise is built right into the BitmapData class.



Which of the following methods does not exist in the Graphics class?











Posted in Quiz | Also tagged , , | 8 Comments

Logistic Map Play

Actionscript:
  1. var offX:Number = 100;
  2. var offY:Number = 300;
  3. var scalarX:Number = 6;
  4. var scalarY:Number = 200;
  5. addEventListener(Event.ENTER_FRAME, onLoop);
  6. function onLoop(evt:Event):void{
  7.     var r:Number = mouseY / 100;
  8.     var xn:Number = (mouseX - 100) / 650;
  9.     var xn1:Number = 0;
  10.     graphics.clear();
  11.     graphics.lineStyle(0,0);
  12.     for (var i:int = 0; i<100; i++){
  13.       xn1 = r * xn * (1 - xn);
  14.       xn = xn1;
  15.       if (i == 0){
  16.         graphics.moveTo(offX+i*scalarX,offY+xn1*scalarY);  
  17.       }else{
  18.         graphics.lineTo(offX+i*scalarX, offY+xn1*scalarY);
  19.       }
  20.     }
  21. }

Whenever I can't decide what kind of snippet to make, I simply go to wikipedia or mathworld for a bit and I always end up with something. I've messed with Logistic Maps before (when learning about strange attractors). This is a simple rendering where the x and y axis change the biotic potential (r) and the starting value for x.

Here is the link I used for reference.


Have a look at the swf (just move your mouse around).

Posted in Graphics, Math, misc | Also tagged , | 2 Comments