It is currently March 28th, 2024, 1:25 pm

Colour Clock (sort of)

Clocks and timer skins
Post Reply
FlyingHyrax
Posts: 232
Joined: July 1st, 2011, 1:32 am
Location: US

Colour Clock (sort of)

Post by FlyingHyrax »

[Update]
- typo in the Lua
[/Update]

This post led me to this which inspired me to write this:

Image

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]
Unnecessarily complex Lua:

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
Last edited by FlyingHyrax on June 28th, 2014, 3:52 pm, edited 3 times in total.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Colour Clock (sort of)

Post by smurfier »

Edit:

Here's a less crazy version of the Lua script.

Code: Select all

function Initialize()
	BoxAlpha = string.format('%02X', math.floor(255 * ((100 - NumberVar('Back.Opc')) / 100)))
	BorderAlpha = string.format('%02X', 255 * ((NumberVar('Round') == 1 and 100 or (100 - NumberVar('Bor.Opc'))) / 100))
	Round, Type, Format = NumberVar('Round') * 0.25, 0, NumberVar('Hr.Format') == 1
end

function Update()
	Time = os.date('*t')
	
	local temp = {
		red = math.floor((Time.hour / 24) * 255),
		green = math.floor((Time.min / 60) * 255),
		blue = math.floor((Time.sec / 60) * 255),
	}
	local Color = string.format('%02X%02X%02X', temp.red, temp.green, temp.blue)
	
	if Type == 0 then
		local Text = string.format('%d:%02d:%02d', (Time.hour - ((Time.hour > 12 and not Format) and 12 or 0)), Time.min, Time.sec)
		SKIN:Bang('!SetOptionGroup', 'Clock', 'Text', Text)
	else
		SKIN:Bang('!SetOptionGroup', 'Clock', 'Text', Color)
	end
	
	SKIN:Bang('!SetOption', 'mTLRound', 'LineColor', Color .. BorderAlpha)
	SKIN:Bang('!SetOptionGroup', 'Solid', 'SolidColor', Color .. ' ' .. BorderAlpha)
	SKIN:Bang('!SetOption', 'Block1', 'SolidColor', '255,255,255,' .. (Type == 0 and 255 or 100))
	SKIN:Bang('!SetOption', 'Block2', 'SolidColor', '255,255,255,' .. (Type == 1 and 255 or 100))
	SKIN:Bang('!SetOption', 'mBox', 'SolidColor', Color .. BoxAlpha)
	return Round
end

function NumberVar(a)
	return tonumber(SKIN:GetVariable(a))
end
FlyingHyrax
Posts: 232
Joined: July 1st, 2011, 1:32 am
Location: US

Re: Colour Clock (sort of)

Post by FlyingHyrax »

smurfier wrote:*snip*
Ha! I new I'd seen this before. (Did a quick forum search and missed it.) Please excuse me while I go pillage your source code.

[Update]
Typo in the Lua code was preventing it from doing what I thought it was doing...
The idea was to use the value of the next smallest unit of time down to cause the color channel for the larger units to update more, especially for the hours. i.e., instead of each of the 24 hours mapping to one possible value in a range of 0..255, by using partial hours you could increase the resolution on that channel so that each of the 255 possible options was used for that color channel.

I can't think of good variable names for the concept, which is probably why in my original post the 'smoothed' function called 'self.smoother' instead of 'self.smoothWith.'
Post Reply