I was playing around with rose graphs earlier and thought they might make a cool little loading indicator or something.
Here’s the code:
--# Main
-- Rose Graph
function setup()
rose = Rose(100, 3)
end
function draw()
background(255)
stroke(255, 0, 0) strokeWidth(5) --noSmooth()
pushMatrix()
translate(WIDTH / 2, HEIGHT / 2)
rose:draw()
popMatrix()
end
--# Rose
Rose = class()
function Rose:init(a, b)
a = a or 100
b = b or 3
local rose = function(angle)
return a * math.cos(b * angle)
end
self.points = {}
for theta = 0, math.pi * 2, 0.05 do
local r = rose(theta)
local x, y = r * math.cos(theta), r * math.sin(theta)
table.insert(self.points, vec2(x, y))
end
end
function Rose:draw()
for i = 70, #self.points - 1 do
line(self.points[i].x, self.points[i].y, self.points[i + 1].x, self.points[i + 1].y)
end
local last = self.points[#self.points]
for i = #self.points, 2, -1 do
self.points[i] = self.points[i - 1]
end
self.points[1] = last
end
function Rose:touched(touch)
-- Codea does not automatically call this method
end