- typo in the Lua
[/Update]
This post led me to this which inspired me to write this:
Unfortunately, thus far I have been unable to exactly reproduce the original Colour Clock, but it's oh-so-close:
If anyone has any insights for improving the conversion, I'd appreciate it.
I just can't seem to get a handle on how the original version is coming up with its numbers.
Skin Code:
Code: Select all
[Rainmeter]
Author=FlyingHyrax | flyinghyrax.deviantart.com
Update=1000
[Metadata]
Name=ColourClock.ini
Version=1.0
Information=Inspired by Jack Hughes: http://www.thecolourclock.co.uk/
License=Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
[Variables]
transparent=0,0,0,1
;;====================================================
;; Measures
;;====================================================
[MeasureHour]
Measure=Time
Format="%H"
[MeasureMinute]
Measure=Time
Format="%M"
[MeasureSecond]
Measure=Time
Format="%S"
[MeasureScript]
Measure=Script
ScriptFile=timeToHex.lua
;;====================================================
;; Meters
;;====================================================
[StyleAllRoundline]
X=5
Y=5
W=100
H=100
LineWidth=1
LineStart=0
Solid=1
StartAngle=0
RotationAngle=6.28
AntiAlias=1
[MeterRoundBgBacking]
Meter=RoundLine
MeterStyle=StyleAllRoundline
LineColor=255,255,255,150
LineLength=50
[MeterRoundBgColor]
Meter=RoundLine
MeterStyle=StyleAllRoundline
LineColor=[MeasureScript]F0
LineLength=48
DynamicVariables=1
[MeterSpacer]
Meter=Image
SolidColor=#transparent#
X=R
Y=R
W=5
H=5
[StyleAllString]
AntiAlias=1
FontColor=255,255,255,240
FontSize=18
FontFace=Segoe UI Light
StringAlign=CenterCenter
X=55
Y=55
SolidColor=#transparent#
StringEffect=Shadow
FontEffectColor=60,60,60,60
[MeterTime]
Meter=String
MeasureName=MeasureHour
MeasureName2=MeasureMinute
MeasureName3=MeasureSecond
MeterStyle=StyleAllString
Text=%1:%2:%3
Hidden=1
LeftMouseDoubleClickAction=[!HideMeter "MeterTime"][!ShowMeter "MeterColor"][!Redraw]
[MeterColor]
Meter=String
MeasureName=MeasureScript
MeterStyle=StyleAllString
Text=%1
LeftMouseDoubleClickAction=[!ShowMeter "MeterTime"][!HideMeter "MeterColor"][!Redraw]
Code: Select all
--[=[
HexTime - the current time as a hexadecimal color value
author FlyingHyrax
version 28-06-2014
license MIT
]=]
-- represents a color channel determined using the given measure and max value.
ColorComponent = function( msr, max, smi )
local self = {
measure = msr,
value = 0,
maxval = max,
smoothWith = smi
}
-- private -- uses AsPercent of another instance to add an additional fractional part to the
-- value of this instance. e.g., uses minutes instance to smooth hours instance, so that instead
-- of just h / 24, the value is (h + (m / 60) / 24), and the color associated with the hour
-- value can change more gradually
local smoothed = function()
return (self.smoothWith and (self.value + self.smoothWith.AsPercent()) or self.value)
end
-- update the value from the measure
self.UpdateValue = function()
self.value = self.measure and self.measure:GetValue() or 0
end
-- return value as percent of max
self.AsPercent = function()
return self.value / self.maxval
end
-- return value converted to hexadecimal string
self.AsHex = function()
local v = math.floor( (smoothed() / self.maxval) * 255)
return string.format( "%02X", v )
end
return self
end
local pieces = {}
Initialize = function()
local sec = ColorComponent(SKIN:GetMeasure('MeasureSecond'), 60, nil)
local min = ColorComponent(SKIN:GetMeasure('MeasureMinute'), 60, sec)
local hour = ColorComponent(SKIN:GetMeasure('MeasureHour'), 24, min)
table.insert( pieces, hour )
table.insert( pieces, min )
table.insert( pieces, sec )
end
Update = function()
local str = ""
for _, c in ipairs(pieces) do
c.UpdateValue()
str = str .. c.AsHex()
end
return str
end