A spinning wheel for indicating wait or loading. http://youtu.be/WueJTkQNfjI
Edit: Just updated version here, but please always check on Codea Community for the latest version.
Main tab
--Version: Alpha 1.3
--Comments: Fixed line cap mode issue
LineCaps = {ROUND, SQUARE, PROJECT}
function setup()
stars = {}
table.insert(stars, Star(WIDTH/4, HEIGHT*3/4, 50, 10, 0.6, 3, 400))
table.insert(stars, Star(WIDTH*3/4, HEIGHT*3/4, 50, 170, 0.6, 12, 250))
table.insert(stars, Star(WIDTH/4, HEIGHT/4, 50, 30, 0.5, 4, 150))
table.insert(stars, Star(WIDTH*3/4, HEIGHT/4, 50, 160, 0, 8, 100))
star = Star(WIDTH/2, HEIGHT/2, 100, 3)
parameter.integer("Radio", 5, 500, 170)
parameter.integer("Spikes", 2, 180, 4)
parameter.integer("LineCapMode", 1, 3)
parameter.number("LengthFactor", 0, 3, 0.5)
parameter.number("WidthFactor", 0.1, 20, 2)
parameter.integer("Speed", 10, 800, 400)
parameter.integer("Background", 0, 255, 255)
end
function draw()
background(Background, Background, Background)
star.r = Radio
star.spikes = Spikes
star.lengthFactor = LengthFactor
star.widthFactor = WidthFactor
star.speed = Speed
star.lineCap = LineCaps[LineCapMode]
star:draw()
for _,st in ipairs(stars) do
st:draw()
end
end
Star tab
Star = class()
function Star:init(x, y, r, spikes, lengthFactor, widthFactor, speed, lineCap)
self.x = x
self.y = y
self.r = r
self.spikes = self:valueOrDefault(spikes, 10)
self.lengthFactor = self:valueOrDefault(lengthFactor, 0.5)
self.widthFactor = self:valueOrDefault(widthFactor, 2)
self.speed = self:valueOrDefault(speed, 400)
self.lineCap = self:valueOrDefault(lineCap, ROUND)
self.light = 0
self.visible = true
end
function Star:valueOrDefault(value, defaultValue)
if value then return value
else return defaultValue end
end
function Star:draw()
if self.visible then
self.delta = 2 * math.pi / self.spikes
self.shift = math.ceil(ElapsedTime * self.speed)
pushMatrix()
pushStyle()
local x1, y1, x2, y2
translate(self.x, self.y)
for a = -math.pi, math.pi, self.delta do
x1 = math.cos(a) * self.r
y1 = math.sin(a) * self.r
x2 = x1 * self.lengthFactor
y2 = y1 * self.lengthFactor
self.light = 255 * (a + math.pi) / (2 * math.pi)
self.light = math.mod(self.light + self.shift, 256)
stroke(self.light, self.light, self.light, 255)
lineCapMode(self.lineCap)
strokeWidth(self.r * self.widthFactor / self.spikes)
line(x1, y1, x2, y2)
end
popStyle()
popMatrix()
end
end