It is currently April 24th, 2024, 2:20 am

Converting time into radians for roundline

Get help with creating, editing & fixing problems with skins
dooey123
Posts: 10
Joined: May 5th, 2019, 1:04 pm

Converting time into radians for roundline

Post by dooey123 »

I'm trying to make a simple sunrise / sunset clock meter using roundlines.

It's a 24 hour clock and I'm able to parse the times from a website in a hh:mm 24hr format.

This is the example of what I want it to do.
Image


I'm having difficulty translating the hh:mm sunrise (e.g. 07:00) and sunset (e.g. 17:00) times into roundline Start and rotation angles so it maps to the clock.
I have the 24 hour hand working correctly though. Any help would be appreciated.
Here is the code:

Code: Select all

[Rainmeter]
SkinWidth=150
SkinHeight=200
AccurateText=1

[Metadata]
Author=Do
Name=sunrise
Information=
Version=1.3
License=Creative Commons
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

[MeasureTime]
Measure=Time

[MeasureSunRise]
Measure=Plugin
Plugin=WebParser.dll
URL=https://www.metaweather.com/api/location/44418/
RegExp=(?siU)"sun_rise":"\d\d\d\d-\d\d-\d\dT(.*):\d\d\..*"sun_set":"\d\d\d\d-\d\d-\d\dT(.*):\d\d\.
StringIndex=1
UpdateRate=3600


[MeasureSunSet]
Measure=Plugin
Plugin=WebParser.dll
URL=https://www.metaweather.com/api/location/44418/
RegExp=(?siU)"sun_rise":"\d\d\d\d-\d\d-\d\dT(.*):\d\d\..*"sun_set":"\d\d\d\d-\d\d-\d\dT(.*):\d\d\.
StringIndex=2
UpdateRate=3600


[MeterNight]
Meter=Roundline
X=-125
Y=-103
W=400
H=400
AntiAlias=1
DynamicVariables=1
LineLength=26
LineStart=18
LineColor=4F5E8E
RotationAngle=(RAD(360))
StartAngle=(RAD(0))
Solid=1
UpdateDivider=-1


[MeterDay]
Meter=Roundline
X=-125
Y=-103
W=400
H=400
AntiAlias=1
DynamicVariables=1
LineLength=26
LineStart=18
LineColor=1DA8FF
RotationAngle=(RAD([MeasureSunSet]-[MeasureSunRise]))
StartAngle=((RAD(90+[MeasureSunRise])))
Solid=1
UpdateDivider=-1


[MeterHand]
Meter=Roundline
MeasureName=MeasureTime
X=-125
Y=-103
W=400
H=400
AntiAlias=1
LineLength=26
LineStart=18
RotationAngle=((RAD(360)))
StartAngle=(RAD(90))
LineWidth=1
LineColor=255,255,255
ValueRemainder=86400
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Converting time into radians for roundline

Post by balala »

First you have to convert both the Sunrise and Sunset into numerical values. For this get the hour and the minute of both, using some String measures. Add the following ones to your code:

Code: Select all

[MeasureSunRiseHour]
Measure=String
String=[MeasureSunRise]
RegExpSubstitute=1
Substitute="^(\d{1,2}):(\d{1,2})$":"\1"
DynamicVariables=1

[MeasureSunRiseMin]
Measure=String
String=[MeasureSunRise]
RegExpSubstitute=1
Substitute="^(\d{1,2}):(\d{1,2})$":"\2"
DynamicVariables=1

[MeasureSunSetHour]
Measure=String
String=[MeasureSunSet]
RegExpSubstitute=1
Substitute="^(\d{1,2}):(\d{1,2})$":"\1"
DynamicVariables=1

[MeasureSunSetMin]
Measure=String
String=[MeasureSunSet]
RegExpSubstitute=1
Substitute="^(\d{1,2}):(\d{1,2})$":"\2"
DynamicVariables=1
I hope it's obviously that [MeasureSunRiseMin] and [MeasureSunRiseMin] are returning the number of hours and minutes of the Sunrise, while [MeasureSunSetMin] and [MeasureSunSetMin] the hours and minutes of Sunset.
Now you have to convert these values into decimal numbers. Do this using the following Calc measures (add them as well):

Code: Select all

[MeasureSunRiseVal]
Measure=Calc
Formula=(( 60 * [MeasureSunRiseHour] + [MeasureSunRiseMin] ) / 1440 )
DynamicVariables=1

[MeasureSunSetVal]
Measure=Calc
Formula=(( 60 * [MeasureSunSetHour] + [MeasureSunSetMin] ) / 1440 )
DynamicVariables=1
The returned values vary between 0 (for midnight) and 1 (next midnight). These are in fact the percents of the Sunrise and Sunset moment from the whole 24 hours length of the day.
You have to calculate only one more thing: the length of the day. You can do this by adding the following Calc measure:

Code: Select all

[MeasureDayLength]
Measure=Calc
Formula=( MeasureSunSetVal - MeasureSunRiseVal )
Same way as I explaing above, this measure will return the length of the day as a percent.
Last step is to modify the [MeterHand] Roundline meter to use the above calculated values. Modify it this way:

Code: Select all

[MeterHand]
Meter=Roundline
MeasureName=MeasureDayLength
X=-125
Y=-103
W=400
H=400
AntiAlias=1
LineLength=26
LineStart=18
RotationAngle=((RAD(360)))
StartAngle=(RAD(90+360*[MeasureSunRiseVal]))
LineWidth=1
Solid=1
LineColor=255,255,255
DynamicVariables=1
;ValueRemainder=86400
See that beside modifying the MeasureName and StartAngle options, I also commented out the not needed ValueReminder option.
Please give a try to this solution and let me know if it does what you need.
dooey123
Posts: 10
Joined: May 5th, 2019, 1:04 pm

Re: Converting time into radians for roundline

Post by dooey123 »

Thanks Very Much!

I had an idea it was to do with the values going by the values in the About console but had no clue how to get there.

I've tinkered a little and added your comments for future reference and also tested with other time zones and it's working great.

code here:
Thanks again!

Code: Select all

[Rainmeter]
SkinWidth=500
SkinHeight=500
AccurateText=1

[Metadata]
Author=Do
Name=sunrise
Information=
Version=1.3
License=Creative Commons
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

[MeasureTime]
Measure=Time

[MeasureSunRise]
Measure=Plugin
Plugin=WebParser.dll
URL=https://www.metaweather.com/api/location/44418/
RegExp=(?siU)"sun_rise":"\d\d\d\d-\d\d-\d\dT(.*):\d\d\..*"sun_set":"\d\d\d\d-\d\d-\d\dT(.*):\d\d\.
StringIndex=1
UpdateRate=3600

[MeasureSunSet]
Measure=Plugin
Plugin=WebParser.dll
URL=https://www.metaweather.com/api/location/44418/
RegExp=(?siU)"sun_rise":"\d\d\d\d-\d\d-\d\dT(.*):\d\d\..*"sun_set":"\d\d\d\d-\d\d-\d\dT(.*):\d\d\.
StringIndex=2
UpdateRate=3600

;====================================================================================
; First you have to convert both the Sunrise and Sunset into numerical values. For this get the hour and the minute of both, using some String measures.
;
[MeasureSunRiseHour]
Measure=String
String=[MeasureSunRise]
RegExpSubstitute=1
Substitute="^(\d{1,2}):(\d{1,2})$":"\1"
DynamicVariables=1

[MeasureSunRiseMin]
Measure=String
String=[MeasureSunRise]
RegExpSubstitute=1
Substitute="^(\d{1,2}):(\d{1,2})$":"\2"
DynamicVariables=1

[MeasureSunSetHour]
Measure=String
String=[MeasureSunSet]
RegExpSubstitute=1
Substitute="^(\d{1,2}):(\d{1,2})$":"\1"
DynamicVariables=1

[MeasureSunSetMin]
Measure=String
String=[MeasureSunSet]
RegExpSubstitute=1
Substitute="^(\d{1,2}):(\d{1,2})$":"\2"
DynamicVariables=1

;Now you have to convert these values into decimal numbers. Do this using the following Calc measures.

[MeasureSunRiseVal]
Measure=Calc
Formula=(( 60 * [MeasureSunRiseHour] + [MeasureSunRiseMin] ) / 1440 )
DynamicVariables=1

[MeasureSunSetVal]
Measure=Calc
Formula=(( 60 * [MeasureSunSetHour] + [MeasureSunSetMin] ) / 1440 )
DynamicVariables=1

;You have to calculate only one more thing: the length of the day.
[MeasureDayLength]
Measure=Calc
Formula=( MeasureSunSetVal - MeasureSunRiseVal )

[MeterNight]
;darkblue
Meter=Roundline
X=-125
Y=-103
W=500
H=500
AntiAlias=1
DynamicVariables=1
LineLength=50
LineStart=30
LineColor=4F5E8E
RotationAngle=(RAD(360))
StartAngle=(RAD(0))
Solid=1
UpdateDivider=-1

[MeterDay2]
;lightblue daylight hours
Meter=Roundline
MeasureName=MeasureDayLength
X=-125
Y=-103
W=500
H=500
AntiAlias=1
LineLength=50
LineStart=30
RotationAngle=((RAD(360)))
StartAngle=(RAD(90+360*[MeasureSunRiseVal]))
LineWidth=1
Solid=1
LineColor=1DA8FF
DynamicVariables=1
;ValueRemainder=86400

[MeterHand]
;yellow sun
Meter=Roundline
MeasureName=MeasureTime
X=-125
Y=-103
W=500
H=500
AntiAlias=1
LineLength=50
LineStart=30
RotationAngle=((RAD(360)))
StartAngle=(RAD(90))
LineWidth=3
LineColor=255,255,0
ValueRemainder=86400
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Converting time into radians for roundline

Post by balala »

You're welcome. My pleasure to help.