Made the hands pretty
This commit is contained in:
parent
f3da84db34
commit
0ba4f6ccca
40
clock.lua
40
clock.lua
@ -1,5 +1,8 @@
|
||||
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 function pointToTurns(x, y)
|
||||
@ -16,33 +19,45 @@ end
|
||||
local Hand = {}
|
||||
Hand.__index = Hand
|
||||
|
||||
function Hand:new(length, color)
|
||||
function Hand:new(length, width, lineWidth)
|
||||
local h = {
|
||||
length = (length or 10),
|
||||
color = (color or {1,1,1})
|
||||
l = (length or 10),
|
||||
w = (width or 40),
|
||||
lineWidth = (lineWidth or 3)
|
||||
}
|
||||
return setmetatable(h, self)
|
||||
end
|
||||
|
||||
function Hand:draw(turns)
|
||||
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.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()
|
||||
end
|
||||
|
||||
|
||||
local function drawFaceCanvas(r)
|
||||
local function drawFaceCanvas(r, lineWidth)
|
||||
local oldCanvas = love.graphics.getCanvas()
|
||||
local canvas = love.graphics.newCanvas(2*r,2*r)
|
||||
love.graphics.setCanvas(canvas)
|
||||
love.graphics.push("all")
|
||||
love.graphics.translate(r, r)
|
||||
love.graphics.setColor(0.93, 0.8, 0)
|
||||
love.graphics.circle("fill", 0, 0, r)
|
||||
local rbezel = r-lineWidth/2
|
||||
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.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)
|
||||
for i=1,60 do
|
||||
love.graphics.rotate(math.pi/30)
|
||||
@ -76,15 +91,16 @@ Clock.__index = Clock
|
||||
function Clock:new(time, diameter)
|
||||
local radius = diameter and diameter/2 or 300
|
||||
local transform = love.math.newTransform(radius, radius)
|
||||
local lineWidth = radius/200
|
||||
local c = {
|
||||
time = (time or Time:new()),
|
||||
minuteHand = Hand:new(240, {1,0,0}),
|
||||
hourHand = Hand:new(180, {0,0.5,0.5}),
|
||||
minuteHand = Hand:new(radius*0.75, radius*0.08, lineWidth),
|
||||
hourHand = Hand:new(radius*0.55, radius*0.08, lineWidth),
|
||||
dragging = false,
|
||||
radius = radius,
|
||||
onSetHands = nil,
|
||||
transform = transform,
|
||||
faceCanvas = drawFaceCanvas(radius)
|
||||
faceCanvas = drawFaceCanvas(radius, lineWidth)
|
||||
}
|
||||
return setmetatable(c, self)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user