Fermat’s Spiral

Actionscript:
  1. x = stage.stageWidth / 2;
  2. y = stage.stageHeight / 2;
  3.  
  4. var xp:Number = 0, yp:Number = 0;
  5. var r:Number = 0, t:Number = 0;
  6. var speed:Number = .07;
  7. var scale:Number = 20;
  8.  
  9. var plot0:Shape = Shape(addChild(new Shape()));
  10. var plot1:Shape = Shape(addChild(new Shape()));
  11. plot0.graphics.lineStyle(0,0x000000);
  12. plot1.graphics.lineStyle(0,0x000000);
  13.  
  14. addEventListener(Event.ENTER_FRAME, onLoop);
  15. function onLoop(evt:Event):void {
  16.      r =  scale * Math.sqrt(t);
  17.      xp =  r * Math.cos(t);
  18.      yp =  r * Math.sin(t);
  19.      t += speed;
  20.      
  21.     plot0.graphics.lineTo(xp, yp);
  22.     plot1.graphics.lineTo(-xp, -yp);
  23. }

This snippet draws Fermat's Spiral.

This entry was posted in Graphics, Math, motion and tagged , . 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 *

*
*