i made a clock and you can set the time yourself in the code or with the little knob on the side, if you pull it out a bit like a normal watch you can adjust the time and if you dont you can turn the mainspring (but it doesnt affect the power beause i dont want to have to wind my virtual watch lol)
its real messy. i can label it if someone wants but to adjust to your timezone youre gonna wanna change the line in _update that says hour = date sub - 6. the - 6 is subtracting 6 hours from the default gmt to get mountain time where i live but you can change it to whatever you like
you can copy this into a file you make called clock.lua wherever your toolbar widget things are stored and then add a line in appdata/system/startup.lua to create it on startup like this
create_process("/tooltray/clock.lua", {window_attribs = {workspace = "tooltray", x=2, y=2, width=128, height=128}})
if you dont have startup.lua just create one in appdata/system and add the above line to it. the path for my clock.lua is just /tooltray/clock.lua because i made a tooltray folder for my widget things in my root folder.
-- clock
function _init()
mx, my, mb, ms = mouse()
lastX = mx
lastY = my
winding = false
windNum = 0
setMin = 0
setHour = 0
springA = 0
movedX = 0
moved = false
clock = 0
wind = 0
windX = 84
windY = 39
end
function _update()
cls(1)
lastX = mx
lastY = my
mx, my, mb, ms = mouse()
winder()
clock += 1
hour = (date():sub(12,13) - 6)%12
minute = (date():sub(15,16) + setMin)
second = (date():sub(18,19))
end
function _draw()
--spr(2-windNum%2,windX,windY)
drawWinder(windX,windY)
background()
flywheel()
mainspring()
local sx = (sin(second/60+0.25)) 10
local sy = (-cos(second/60+0.25)) 10
line(42,59,42+sy,59+sx,24)
local hx = (sin(hour/12+0.25+(minute/60)/12)) 16
local hy = (-cos(hour/12+0.25+(minute/60)/12)) 16
--line(42,42,42+hy,42+hx,7)
local ha = hour/12 +(minute/60)/12
drawHand((ha-1)*-1,16,42,42)
local mx = (sin(minute/60+0.25)) 24
local my = (-cos(minute/60+0.25)) 24
--line(42,42,42+my,42+mx,7)
local ma = minute/60
drawHand((ma-1)*-1,28,42,42)
-- print(second,128,16,7)
-- print(minute,128,32,7)
-- print(hour,128,48,7)
end
function drawHand(a,l,x,y)
local x1 = (sin(a - 1/12)) 2
local y1 = (-cos(a - 1/12)) 2
local x2 = (sin(a + 1/12)) 2
local y2 = (-cos(a + 1/12)) 2
local x3 = (sin(a)) l
local y3 = (-cos(a)) l
local x4 = (sin(a)) 2
local y4 = (-cos(a)) 2
line(x+x1,y+y1,x+x3,y+y3,6)
line(x+x2,y+y2,x+x3,y+y3,6)
line(x+x4,y+y4,x+x3,y+y3,7)
circfill(x,y,2,6)
circfill(x,y,1,1)
end
function drawWinder(x,y)
local n = windNum%2
rectfill(x,y,x+2,y+6,13)
line(x-1,y+1,x-1,y+5)
if n == 0 then
for i= 0,2 do
local xx = x+1
local yy = y+1
line(xx,yy+i2,xx+1,yy+i2,29)
end
elseif n == 1 then
for i= 0,3 do
local xx = x+1
local yy = y
line(xx,yy+i2,xx+1,yy+i2,29)
end
end
end
function winder()
if mx >= windX and mx <= windX + 16 and my >= windY and my <= windY + 16 then
if mb == 1 then
winding = true
end
end
if winding == true then
if mb != 1 then
winding = false
end
end
if winding then
if not moved then
local n = lastY - my
if n > 0 then
springA += lastY - my
end
else
setMin -= lastY - my
end
windNum += lastY - my
movedX -= lastX - mx
end
if mb == 0 then movedX = 0 end
if movedX >= 8 and not moved then
windX += 1
movedX = 0
moved = true
end
if moved and movedX <= -8 then
windX -= 1
movedX = 0
moved = false
end
end
function mainspring()
circfill(42,28,16,18)
for i = 1,3 do
local a = i/3 - springA/60
local x = sin(a) 6
local y = -cos(a) 6
circ(42+x,28+y,6,22)
end
for i = 1,3 do
local a = i/3 + 5/12 - springA/60
local x = sin(a) 10
local y = -cos(a) 10
circfill(42+x,28+y,5,18)
end
circ(42,28,12,22)
circ(42,28,13,22)
circ(42,28,15,29)
end
function flywheel()
circ(24,47,9,9)
for i = 1,3 do
local a = i/3+0.25+(cos(clock/24)/3)%2
local x = sin(a)
local y = -cos(a)
line(24,47,24+x9,47+y9,9)
end
end
function acos(x)
return atan2(x,-sqrt(1-x*x))
end
function asin(y)
return atan2(sqrt(1-y*y),-y)
end
function background()
--circ(240,135,36,7)
--circ(240,135,37,7)
circfill(42,42,40,1)
circfill(42,42,30,13)
circ(42,42,41,29)
circ(42,42,29,29)
circ(42,59,10,1)
circ(42,59,11,1)
for i = 1,12 do
local a = i/12+0.25
local x = sin(a)
local y = -cos(a)
line(42+x32,42+y32,42+x36,42+y36,6)
end
for i = 1,12 do
local a = i/12+0.25
local x = sin(a)
local y = -cos(a)
pset(42+x9,59+y9,7)
end
for i = 1,60 do
local a = i/60+0.25
local x = sin(a)
local y = -cos(a)
pset(42+x38,42+y38,7)
end
for i = 1,12 do
local a = i/12+0.25
local x = sin(a)
local y = -cos(a)
pset(42+x38,42+y38,8)
end
end
Nice watch, you can use triple back ticks do make a code block
like this |
[Please log in to post a comment]