Made the hands pretty

This commit is contained in:
Brandon Dyck 2024-04-13 13:27:19 -06:00
parent f3da84db34
commit 0ba4f6ccca

View File

@ -1,5 +1,8 @@
local Time = require"time" local Time = require"time"
local YELLOW = {0.93, 0.8, 0}
local DARK_YELLOW = {0.74, 0.64, 0}
local numberFont = love.graphics.newFont(100) local numberFont = love.graphics.newFont(100)
local function pointToTurns(x, y) local function pointToTurns(x, y)
@ -16,33 +19,45 @@ end
local Hand = {} local Hand = {}
Hand.__index = Hand Hand.__index = Hand
function Hand:new(length, color) function Hand:new(length, width, lineWidth)
local h = { local h = {
length = (length or 10), l = (length or 10),
color = (color or {1,1,1}) w = (width or 40),
lineWidth = (lineWidth or 3)
} }
return setmetatable(h, self) return setmetatable(h, self)
end end
function Hand:draw(turns) function Hand:draw(turns)
love.graphics.push("all") love.graphics.push("all")
love.graphics.setColor(unpack(self.color)) love.graphics.setColor(YELLOW)
local vertices = {-self.w/2,0, 0,self.w*0.75, self.w/2,0, 0,-self.l}
love.graphics.rotate(turnsToRads(turns) + 0.5 * math.pi) love.graphics.rotate(turnsToRads(turns) + 0.5 * math.pi)
love.graphics.rectangle("fill", -10, 10, 20, -self.length) love.graphics.polygon("fill", vertices)
love.graphics.setColor(DARK_YELLOW)
love.graphics.setLineWidth(self.lineWidth)
love.graphics.polygon("line", vertices)
love.graphics.pop() love.graphics.pop()
end end
local function drawFaceCanvas(r) local function drawFaceCanvas(r, lineWidth)
local oldCanvas = love.graphics.getCanvas() local oldCanvas = love.graphics.getCanvas()
local canvas = love.graphics.newCanvas(2*r,2*r) local canvas = love.graphics.newCanvas(2*r,2*r)
love.graphics.setCanvas(canvas) love.graphics.setCanvas(canvas)
love.graphics.push("all") love.graphics.push("all")
love.graphics.translate(r, r) love.graphics.translate(r, r)
love.graphics.setColor(0.93, 0.8, 0) local rbezel = r-lineWidth/2
love.graphics.circle("fill", 0, 0, r) love.graphics.setColor(YELLOW)
love.graphics.circle("fill", 0, 0, rbezel)
love.graphics.setLineWidth(lineWidth)
love.graphics.setColor(DARK_YELLOW)
love.graphics.circle("line", 0, 0, rbezel)
local rcrystal = 0.84*r
love.graphics.setColor(1, 1, 1) love.graphics.setColor(1, 1, 1)
love.graphics.circle("fill", 0, 0, 0.84*r) love.graphics.circle("fill", 0, 0, rcrystal)
love.graphics.setColor(DARK_YELLOW)
love.graphics.circle("line", 0, 0, rcrystal)
love.graphics.setColor(0,0,0) love.graphics.setColor(0,0,0)
for i=1,60 do for i=1,60 do
love.graphics.rotate(math.pi/30) love.graphics.rotate(math.pi/30)
@ -76,15 +91,16 @@ Clock.__index = Clock
function Clock:new(time, diameter) function Clock:new(time, diameter)
local radius = diameter and diameter/2 or 300 local radius = diameter and diameter/2 or 300
local transform = love.math.newTransform(radius, radius) local transform = love.math.newTransform(radius, radius)
local lineWidth = radius/200
local c = { local c = {
time = (time or Time:new()), time = (time or Time:new()),
minuteHand = Hand:new(240, {1,0,0}), minuteHand = Hand:new(radius*0.75, radius*0.08, lineWidth),
hourHand = Hand:new(180, {0,0.5,0.5}), hourHand = Hand:new(radius*0.55, radius*0.08, lineWidth),
dragging = false, dragging = false,
radius = radius, radius = radius,
onSetHands = nil, onSetHands = nil,
transform = transform, transform = transform,
faceCanvas = drawFaceCanvas(radius) faceCanvas = drawFaceCanvas(radius, lineWidth)
} }
return setmetatable(c, self) return setmetatable(c, self)
end end