It is currently February 4th, 2023, 2:51 am

Use Numerical Value of Time to scale a shape

Get help with creating, editing & fixing problems with skins
stingray
Posts: 2
Joined: January 23rd, 2023, 8:31 am

Use Numerical Value of Time to scale a shape

Post by stingray »

Hi all,

I just stumbled onto this app a couple of hours ago so I dont know much yet.
I wish to create a clock widget where a certain percentage of the numbers are masked by a shape dependent on the value of the time. ie. the seconds informs how much of the minute numbers you can see an the minute value informs what percentage of the Hour digits you can see. The goal is to create a terribly unreadable clock.

So for example if it were 13:40:20 : 66 % of the 40 would be masked as the seconds are a third of the way to 60 seconds and 33 % of the hour would be masked as you are 2/3 of the way to 60 minutes.
It would be even better if this could be done on a per digit basis, so the single second masks the tens of seconds which masks single minutes etc.
Also would like for the mask to go from the bottom up rather than top down; not sure how to implement that.

What I am struggling with is how to extract the individual numbers from the time to do the calculations with. Also should I work with the H:M:S string or extract them all into seperate measures?

This is what I have so far.

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0

[Variables]

[MeasureTime1]
Measure=Time
Format=%H:%M:%S

[MeterTime]
Meter=String
MeasureName=MeasureTime1
FontSize=40
FontColor="0,0,255"
AntiAlias=1

[CoverContainerHour]
Meter=Shape
Shape=Rectangle 0,0,60,30,0 | Fill Color 0,0,0 | Strokewidth 0
; I wish to alter the '30' here to be a  variable based on time

[CoverContainerMinute]
Meter=Shape
Shape=Rectangle 75,0,60,40,0 | Fill Color 0,0,0 | Strokewidth 0
; again the '40' here should be based on the seconds
Thanks!
User avatar
SilverAzide
Rainmeter Sage
Posts: 2250
Joined: March 23rd, 2015, 5:26 pm

Re: Use Numerical Value of Time to scale a shape

Post by SilverAzide »

stingray wrote: January 23rd, 2023, 8:57 am So for example if it were 13:40:20 : 66 % of the 40 would be masked as the seconds are a third of the way to 60 seconds and 33 % of the hour would be masked as you are 2/3 of the way to 60 minutes.
It would be even better if this could be done on a per digit basis, so the single second masks the tens of seconds which masks single minutes etc.
Also would like for the mask to go from the bottom up rather than top down; not sure how to implement that.

What I am struggling with is how to extract the individual numbers from the time to do the calculations with. Also should I work with the H:M:S string or extract them all into seperate measures?
The answer to your question is: "none of the above". ;-)

Oh, and welcome to Rainmeter!

The way to handle this is using a Time measure like you have, but do your calculations with the numeric timestamp value it returns and modulus math. The time measure returns a numeric value of the time in seconds (since a certain date, which you don't care about). So, for example:

Code: Select all

[MeasureTime]
Measure=Time

[MeasureHours]
Measure=Calc
Formula=Trunc((MeasureTime % (60 * 60 * 24)) / (60 * 60))

[MeasureMinutes]
Measure=Calc
Formula=(Trunc((MeasureTime % (60 * 60 * 24)) / 60) % 60)

[MeasureSeconds]
Measure=Calc
Formula=((MeasureTime % (60 * 60 * 24)) % 60)
You can you these as your starting point to calculate the percentage of an hour or day or whatever for your clock.
Gadgets Wiki GitHub More Gadgets...
stingray
Posts: 2
Joined: January 23rd, 2023, 8:31 am

Re: Use Numerical Value of Time to scale a shape

Post by stingray »

Thanks for the tips.

Now I have read in the minutes and seconds individually and done the math on them which is all good now, however The shape object doesnt accept these numbers as an input to the dimensions. Do I need to set something as a dynamic variable somewhere or will shapes just not take dimensions which constantly change?

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0

[Variables]

[MeasureTime1]
Measure=Time
Format=%H:%M:%S

[MeasureMinutes]
Measure=Time
Format=%M

[MeasureSeconds]
Measure=Time
Format=%S

[MeasureM1]
Measure=Calc
Formula=((1-((MeasureMinutes / 60))*60)

[MeasureS1]
Measure=Calc
Formula=((1-(MeasureSeconds / 60))*60)
; This is rectangle height in pixels based on seconds

[MeterTime]
Meter=String
MeasureName=MeasureTime1
FontSize=40
FontColor="0,0,255"
AntiAlias=1

[CoverContainerHour]
Meter=Shape
Shape=Rectangle 0,0,60,MeasureM1,0 | Fill Color 0,0,0 | Strokewidth 0
; Putting 'DynamicVariables=1' here does not fix it

[CoverContainerMinute]
Meter=Shape
;MeasureName=MeasureS1
Shape=Rectangle 75,0,60,MeasureS1,0 | Fill Color 0,0,0 | Strokewidth 0
; Why cant it use the Measure S1 value?
User avatar
SilverAzide
Rainmeter Sage
Posts: 2250
Joined: March 23rd, 2015, 5:26 pm

Re: Use Numerical Value of Time to scale a shape

Post by SilverAzide »

stingray wrote: January 23rd, 2023, 11:27 pm
It's just a minor syntax issue; you didn't use the square brackets to denote a measure:

Shape=Rectangle 0,0,60,[MeasureM1],0 | Fill Color 0,0,0 | Strokewidth 0

Measures need square brackets ("[measure]"), variables use hash signs ("#var#"). There are some exceptions and variations to this (like they aren't needed in formulas in calc measures), but this is the basic rule. You sometimes need parentheses around math expressions that use measures or variables; and it never hurts to add them if you run into issues.
Gadgets Wiki GitHub More Gadgets...
User avatar
balala
Rainmeter Sage
Posts: 14935
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Use Numerical Value of Time to scale a shape

Post by balala »

A little bit late to the party, but I probably would try to use Bar meters as containers. Different design than the posted code, but here is an example:

Code: Select all

[Rainmeter]
Update=1000

[ColonStyle]
X=-8R
FontColor=220,220,220
SolidColor=0,0,0,1
FontSize=38
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=:

[TimeStyle]
FontColor=220,220,220
SolidColor=0,0,0,1
FontSize=38
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=%1

[ShadowStyle]
Y=-18r
FontColor=220,220,220,80
SolidColor=250,0,0,1
FontSize=38
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=%1

[BarStyle]
BarColor=0,0,0
W=56
H=38

[MeasureHour]
Measure=Time
Format=%H

[MeasureMinute]
;Measure=Calc
;Formula=59
Measure=Time
Format=%M
MinValue=0
MaxValue=59

[MeasureSecond]
Measure=Time
Format=%S
MinValue=0
MaxValue=59

[MeterHourBar]
Meter=Bar
MeterStyle=BarStyle
MeasureName=MeasureMinute
X=12
Y=18

[MeterHour]
Meter=STRING
MeterStyle=TimeStyle
MeasureName=MeasureHour
X=-12
Y=-18
Container=MeterHourBar

[MeterHourShadow]
Meter=STRING
MeterStyle=ShadowStyle
MeasureName=MeasureHour
X=-12r

[MeterHourMin]
Meter=STRING
MeterStyle=ColonStyle
Y=0r

[MeterMinutesBar]
Meter=Bar
MeterStyle=BarStyle
MeasureName=MeasureSecond
X=32r
Y=20r

[MeterMinute]
Meter=STRING
MeterStyle=TimeStyle
MeasureName=MeasureMinute
X=-10
Y=-18
Container=MeterMinutesBar

[MeterMinuteShadow]
Meter=STRING
MeterStyle=ShadowStyle
MeasureName=MeasureMinute
X=-10r

[MeterMinSec]
Meter=STRING
MeterStyle=ColonStyle
Y=-74R

[MeterSecond]
Meter=STRING
MeterStyle=TimeStyle
MeasureName=MeasureSecond
X=-8R
Y=2r