Skip to content

Instantly share code, notes, and snippets.

@qwzybug
Created February 27, 2009 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qwzybug/71281 to your computer and use it in GitHub Desktop.
Save qwzybug/71281 to your computer and use it in GitHub Desktop.
-- this version doesn't need prototype.lua
BarGraph = {
x = 0, y = 20,
width = 20, height = 100,
offset = 0,
update =
function (self, t)
self.height = 60 + 40 * math.sin(self.offset * math.pi / 10 + t / 10)
end
}
BarGraph.new = function(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
bars = {}
for i = 1, 10 do
bars[i] = BarGraph.new{x = 10 * i, offset = i}
end
for t = 1, 10 do
print("Step " .. t)
for _, bar in pairs(bars) do
bar:update(t)
print(bar.height)
end
end
--
-- Note: Uses my prototype.lua NewtonScript inheritance model code
-- from lua-cairo-cocoa
--
BarGraph = obj{
x = 0, y = 0,
width = 5, height = 10,
offset = 0,
update =
function (self, t)
self.height = 10 + math.sin(self.offset * math.pi / 10 + t / 10)
end
}
bars = {}
for i = 1, 10 do
bars[i] = obj{BarGraph, x = 10 * i, offset = i}
end
for t = 1, 10 do
print("Step " .. t)
for _, bar in pairs(bars) do
bar:update(t)
print(bar.height)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment