Rainmeter binary clock line
Introduction
This tutorial will create a skin showing the number of seconds from the start of the year in binary with Rainmeter and Lua. Lua can be used with Rainmeter to load and execute skins. We'll make a binary clock that shows the number of seconds elapsed from the beginning of the year. The two source files are in this gist.
Create the .ini
file
First, create a new skin called BinaryTime. Then, create an .INI file named binaryLine.ini
for the skin. Inside it, put the following code: (Make sure to create [m3]
to [m24]
too)
[Rainmeter]
Update=1000
[Variables]
Radius=10
Spacing=5
FullColor=50,50,250,200
EmptyColor=140,140,140,100
[CircleStyle]
W=(#Radius#*2+#Spacing#)
H=(#Radius#*2+#Spacing#)
X=R
Y=0
LineLength=#Radius#
LineColor=#FullColor#
Solid=1
AntiAlias=1
[mDayOfYear]
Measure=Time
Format=%j
; The day of the year, from 1-366 inclusive
[mHours]
Measure=Time
Format=%H
; The hour, from 0-23 inclusive
[mMinutes]
Measure=Time
Format=%M
; The minute, from 0-59 inclusive
[mSeconds]
Measure=Time
Format=%S
; The second, from 0-59 inclusive
[mFinalDecimalCalc]
Measure=Calc
Formula=(mDayOfYear - 1)*24*60*60+mHours*60*60+mMinutes*60+mSeconds
; Calculates the seconds since the beginning of the year, in base 10
[mLua]
Measure=Script
ScriptFile=line.lua
[m1]
Meter=Roundline
MeterStyle=CircleStyle
X=0
[m2]
Meter=Roundline
MeterStyle=CircleStyle
; ...
; Include [m3] to [m24] here
; ...
[m25]
Meter=Roundline
MeterStyle=CircleStyle
When you load the skin, you should see something like this line of 25 blue circles:
Adding Lua
To convert the decimal representation to binary, we'll need to make a Lua script. In the same folder as binaryLine.ini
, make a Lua file line.lua
. Inside put the following code:
function Initialize()
mDecimalTime = SKIN:GetMeasure("mFinalDecimalCalc")
end
The Initialize
function runs when the skin is first loaded. The second line creates a variable mDecimalTime
and sets it to the measure [mFinalDecimalCalc]
. Now, add this code:
function Update()
decimalTime = mDecimalTime:GetValue()
for i = 24, 0, -1 do
if decimalTime - 2^i > 0 then
decimalTime = decimalTime - 2^i
SKIN:Bang("!SetOption m"..(25-i).." LineColor #FullColor#")
else
SKIN:Bang("!SetOption m"..(25-i).." LineColor #EmptyColor#")
end
end
end
The Update
function is called every time the skin is refreshed (in our case, every second) The second line in this code sets a new variable decimalTime
to the current value of [mFinalDecimalCalc]
. Then, it iterates backwards through each circle meter and sets the meter's color. #FullColor
corresponds to a binary value of 1 and #EmptyColor
to 0.
Conclusion
The binary 1000110110011011110111001 corresponds to 18560953 seconds in decimal, which means it's approximately 215 days from the beginning of the year (early August).