Rect vs Ellipse

Actionscript:
  1. for (var i:int = 0; i<100; i++){
  2.     graphics.lineStyle(0,0);
  3.     graphics[["drawEllipse", "drawRect"][int(Math.random()*2)]](Math.random()*400, Math.random()*300, Math.random()*100,Math.random()*100)
  4. }
  5.  
  6. /*
  7. WARNING: This code was written for fun. Use at your own risk.
  8. */

And a more readable version:

Actionscript:
  1. var methodChoices:Array = ["drawEllipse", "drawRect"];
  2. var method:String;
  3. var xp:Number, yp:Number, w:Number, h:Number;
  4. for (var i:int = 0; i<100; i++){
  5.     method = methodChoices[int(Math.random()*methodChoices.length)];
  6.     graphics.lineStyle(0,0);
  7.     xp = Math.random()*400;
  8.     yp = Math.random()*300;
  9.     w = Math.random()*100;
  10.     h = Math.random()*100;
  11.     graphics[method](xp, yp, w, h)
  12. }
  13.  
  14. /*
  15. WARNING: This code was written for fun. Use at your own risk.
  16. */

Here I use yesterdays associative array function call technique to do something different. Not really all that useful, but interesting....

This entry was posted in Graphics, associative arrays, functions, random. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

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

*
*