2024-03-27 03:57:50 +00:00
|
|
|
--local MAX_SECONDS = 60 * 60 * 12
|
2024-03-24 22:26:07 +00:00
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
--local Hand = {}
|
|
|
|
--Hand.__index = Hand
|
2024-03-24 22:26:07 +00:00
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
--function Hand:new(length, color, sec_per_turn, ticks_per_turn)
|
|
|
|
-- local h = {
|
|
|
|
-- length = (length or 10),
|
|
|
|
-- color = (color or {1,1,1}),
|
|
|
|
-- sec_per_turn = (sec_per_turn or 1),
|
|
|
|
-- ticks_per_turn = ticks_per_turn
|
|
|
|
-- }
|
|
|
|
-- return setmetatable(h, self)
|
|
|
|
--end
|
2024-03-24 22:26:07 +00:00
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
--function Hand:draw(sec_elapsed)
|
|
|
|
-- local turns = sec_elapsed / self.sec_per_turn
|
|
|
|
-- if self.ticks_per_turn then
|
|
|
|
-- turns = math.floor(turns * self.ticks_per_turn) / self.ticks_per_turn
|
|
|
|
-- end
|
|
|
|
-- love.graphics.push("all")
|
|
|
|
-- love.graphics.setColor(unpack(self.color))
|
|
|
|
-- love.graphics.rotate(2 * math.pi * turns)
|
|
|
|
-- love.graphics.rectangle("fill", -10, 10, 20, -self.length)
|
|
|
|
-- love.graphics.pop()
|
|
|
|
--end
|
2024-03-24 22:26:07 +00:00
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
--local clock = {rawseconds = 0, speedup = 120}
|
2024-03-24 22:26:07 +00:00
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
--function clock:advance(dt)
|
|
|
|
-- self.rawseconds = self.rawseconds + dt * self.speedup
|
|
|
|
-- if self.rawseconds >= MAX_SECONDS then
|
|
|
|
-- self.rawseconds = self.rawseconds - MAX_SECONDS
|
|
|
|
-- end
|
|
|
|
--end
|
|
|
|
|
|
|
|
--function clock:getHour()
|
|
|
|
-- local h = math.floor(self.rawseconds / 60 / 60 % 12)
|
|
|
|
-- if h == 0 then
|
|
|
|
-- h = 12
|
|
|
|
-- end
|
|
|
|
-- return h
|
|
|
|
--end
|
|
|
|
|
|
|
|
--function clock:getMinute()
|
|
|
|
-- return math.floor(self.rawseconds / 60 % 60)
|
|
|
|
--end
|
2024-03-24 22:26:07 +00:00
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
--function clock:getSecond()
|
|
|
|
-- return math.floor(self.rawseconds % 60)
|
|
|
|
--end
|
|
|
|
|
|
|
|
--function clock:fmt()
|
|
|
|
-- return string.format("%2d:%02d:%02d", self:getHour(), self:getMinute(), self:getSecond())
|
|
|
|
--end
|
|
|
|
|
|
|
|
--local secondhand = Hand:new(300, {0.5,0.5,0}, 60, 60)
|
|
|
|
--local minutehand = Hand:new(240, {1,0,0}, 60*60)
|
|
|
|
--local hourhand = Hand:new(180, {0,0.5,0.5}, 60*60*12)
|
|
|
|
|
|
|
|
-- New stuff:
|
|
|
|
local Clock = require"clock"
|
|
|
|
local clockTransform = love.math.newTransform(love.graphics.getWidth()/2, love.graphics.getHeight()/2)
|
|
|
|
local clock = Clock:new(nil, 400, clockTransform)
|
|
|
|
|
|
|
|
function love.mousemoved(x, y, dx, dy, istouch)
|
|
|
|
clock:movemouse(x, y)
|
2024-03-24 22:26:07 +00:00
|
|
|
end
|
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
-- todo mousepressed & mousereleased
|
|
|
|
function love.mousepressed(x, y, button, istouch, presses)
|
|
|
|
clock:pressmouse(x, y, button)
|
2024-03-24 22:26:07 +00:00
|
|
|
end
|
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
function love.mousereleased(x, y, button, istouch, presses)
|
|
|
|
clock:releasemouse(button)
|
|
|
|
end
|
2024-03-24 22:26:07 +00:00
|
|
|
|
|
|
|
function love.load()
|
|
|
|
love.graphics.setBackgroundColor(0,0,0)
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
2024-03-27 03:57:50 +00:00
|
|
|
love.graphics.print(clock:getTime():fmt())
|
|
|
|
clock:draw()
|
2024-03-24 22:26:07 +00:00
|
|
|
end
|