Created
August 30, 2011 15:19
-
-
Save lclarkmichalek/1181145 to your computer and use it in GitHub Desktop.
Spiral 1
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
-- Constants | |
a = 1 | |
n = 1 | |
function spiral(theta) | |
-- Work out the polar equation | |
local r = a * theta ^ (1/n) | |
-- Convert to cartesian coordinates | |
local x = r * math.sin(theta) | |
local y = r * math.cos(theta) | |
return x, y | |
end | |
function love.draw() | |
-- Draw for theta between 0 and 3pi, with sample period of pi/100 | |
for theta=0, 3 * math.pi, math.pi/100 do | |
local x, y = spiral(theta) | |
-- Adjust the points to be in the middle of the screen, and scale by 20 | |
love.graphics.point(width / 2 + x * 20, height / 2 + y * 20) | |
end | |
end | |
function love.load() | |
width = love.graphics.getWidth() | |
height = love.graphics.getHeight() | |
love.graphics.setPoint(3, "smooth") | |
love.graphics.setColor(255, 255, 255, 255) | |
love.graphics.setBackgroundColor(0, 0, 0) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment