Hypocycloid Spiral

x = stage.stageWidth / 2;
y = stage.stageHeight / 2;
// change n to alter number of spikes (cuspes)
var n:Number = 8;
var xp:Number = 0, yp:Number = 0, a:Number = 10, t:Number = 0;

graphics.lineStyle(0, 0x000000);
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
	for (var i:int = 0; i<10; i++){
	  // unoptimized for simplicity and similarity to original equations from here:
          // http://mathworld.wolfram.com/Hypocycloid.html
      xp = a/n * ((n - 1) * Math.cos(t) + Math.cos(Math.abs((n - 1) * t)));
	  yp = a/n * ((n - 1) * Math.sin(t) - Math.sin(Math.abs((n - 1) * t)))  ;
	  
	  a *= 1.002;
	   if (t == 0){
		   graphics.moveTo(xp, yp);
	   }else{
		   graphics.lineTo(xp, yp);   
	   }
	   t += .1;
	}
}

This code draws a Hypocycloid with a radius that increments – this results in a spiral formation.

I got the math from mathworld… here.

2 comments

  1. yeah, at first i didn’t realize that it looked like a spider web, needs some weights, some imperfection and some lines coming from the center going outward….

Leave a Reply

Your email address will not be published. Required fields are marked *