Created
July 3, 2010 03:25
-
-
Save nodename/462269 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.Graphics; | |
import flash.display.Shape; | |
import flash.display.Sprite; | |
import flash.geom.Point; | |
public class LogarithmicSpiralTest extends Sprite | |
{ | |
public function LogarithmicSpiralTest() | |
{ | |
var shape:Shape = new Shape(); | |
addChild(shape); | |
shape.x = shape.y = 200; | |
shape.graphics.lineStyle(0, 0xff0000, 1.0, true); | |
plot(shape.graphics); | |
} | |
private function plot(canvas:Graphics):void | |
{ | |
const eightPi:Number = Math.PI * 8; | |
var interval:Number = Math.PI/20; // this is the space between rays on the Wolfram page | |
var steps:uint = 160; | |
var point:Point; | |
var lastPoint:Point = new Point(0, 0); | |
canvas.moveTo(lastPoint.x, lastPoint.y); | |
for (var theta:Number = interval; --steps > -1; theta += interval) | |
{ | |
point = Point.polar(r(theta), theta); | |
// flip y for Flash coordinate system: | |
canvas.lineTo(point.x, -point.y); | |
lastPoint = point; | |
} | |
} | |
} | |
} | |
function r(theta:Number):Number | |
{ | |
const a:Number = 0.25; | |
const b:Number = 0.25; | |
return a * Math.exp(b * theta); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A comment on http://xtyler.com/code/104 asked how to implement the formula at http://mathworld.wolfram.com/LogarithmicSpiral.html