It is currently March 28th, 2024, 10:41 pm

Weather Temperature Dynamic Color, a different perspective

Tips and Tricks from the Rainmeter Community
gator
Posts: 14
Joined: May 29th, 2020, 3:35 pm

Weather Temperature Dynamic Color, a different perspective

Post by gator »

I have been using the dynamic temperature color changing routine (https://forum.rainmeter.net/viewtopic.php?f=5&t=11612&p=143352#p143352) for about a year now and wanted to come up with a method to change the color based on temperature that would provide an individual RGB value for each degree of temperature. After a few attempts at applying the RGB values in different gradients, I have settled on a method that I am satisfied with that will change the RGB value for a given temperature that approximates similar colors within the range of the previous version referenced above and yet will give a different RGB value for every degree change in the temperature.

Code: Select all

;Fahrenheit calculation
[MeasureColorF]
Measure=String
DynamicVariables=1
IfCondition=MeasureTemp >= 115
IfTrueAction=[!SetOption MeasureColorF String "176,0,0"]
IfCondition2=(MeasureTemp > 73.5) && (MeasureTemp < 115)
IfTrueAction2=[!SetOption MeasureColorF String "255,(ROUND(((115-[MeasureTemp])/41.5)*255)),0"]
IfCondition3=(MeasureTemp > 32) && (MeasureTemp <= 73.5)
IfTrueAction3=[!SetOption MeasureColorF String "(ROUND((([MeasureTemp]-32)/41.5)*255)),255,(ROUND(((73.5-[MeasureTemp])/41.5)*255))"]
IfCondition4=MeasureTemp = 32
IfTrueAction4=[!SetOption MeasureColorF String "0,255,255"]
IfCondition5=(MeasureTemp > -51) && (MeasureTemp < 32)
IfTrueAction5=[!SetOption MeasureColorF String "0,(ROUND((([*MeasureTemp*]+51)/83)*255)),255"]
IfCondition6=MeasureTemp <= -51
IfTrueAction6=[!SetOption MeasureColorF String "0,0,144"]
IfConditionMode=1

;Celsius calculation
[MeasureColorC]
Measure=String
DynamicVariables=1
IfCondition=MeasureTemp >= 46
IfTrueAction=[!SetOption MeasureColorC String "176,0,0"]
IfCondition2=(MeasureTemp > 23) && (MeasureTemp < 46)
IfTrueAction2=[!SetOption MeasureColorC String "255,(ROUND(((46-[MeasureTemp])/23)*255)),0"]
IfCondition3=(MeasureTemp > 0) && (MeasureTemp <= 23)
IfTrueAction3=[!SetOption MeasureColorC String "(ROUND(([MeasureTemp]/23)*255)),255,(ROUND(((23-[MeasureTemp])/23)*255))"]
IfCondition4=MeasureTemp = 0
IfTrueAction4=[!SetOption MeasureColorC String "0,255,255"]
IfCondition5=(MeasureTemp > -46) && (MeasureTemp < 0)
IfTrueAction5=[!SetOption MeasureColorC String "0,(ROUND(((46+[MeasureTemp])/46)*255)),255"]
IfCondition6=MeasureTemp <= -46
IfTrueAction6=[!SetOption MeasureColorC String "0,0,144"]
IfConditionMode=1

[MeterCurrentTemp]
Meter=String
MeasureName=@CurrentTemperature
X=0
Y=0
FontColor=[MeasureColor[&@UnitsTemperature]]
FontFace=Arial Bold
FontSize=28
StringAlign=Left
StringEffect=Border
FontEffectColor=0,0,0
AntiAlias=1
DynamicVariables=1
Text=%1#Degrees#
The MeasureTemp escaped with asterisks in IfTrueAction5 of MeasureColorF above is necessary in this step. If MeasureTemp was not escaped with asterisks there, the value for green was incorrectly calculated when MeasureTemp was a positive number. Also, I used a bold font as it allows for a little more color to be visible and makes it easier to see slight differences in the colors.
DynamicColor_1.0.rmskin
One issue I haven't been able to work out -
When run as it is in the attached skin where there are two measures each for both temperature types/scales (MeasureColorFCalc, MeasureColorF, MeasureColorCCalc, MeasureColorC), the degree symbol will load in blue and then it is replaced with the temperature and degree symbol in the correct color. If I comment out the measures MeasureColorF and MeasureColorC and then rename the measures MeasureColorFCalc and MeasureColorCCalc to MeasureColorF and MeasureColorC, respectively (as it is shown above and which would be my preferred method as everything is contained in a single measure for each temperature type/scale), the degree symbol will load in white and then it is replaced with the temperature and degree symbol in the same blue color as before, then finally it is replaced with the temperature and degree symbol in the correct color. This only occurs on initial load or a skin refresh. Once loaded, the color changes on the update cycle directly from the previous color to the new color without any interim white or blue. The blue I am assuming is the RGB value associated with zero degrees for either temperature type/scale. I can't figure out how to pause the display of the temperature and degree symbol on initial load and/or refresh until the actual RGB value for the temperature is resolved. I have tried making the measures and/or the meter a disabled group and enabling the group after @CurrentTemperature is parsed in @CurrentConditionsParent (from WeatherComJSONMeasures3Day.inc), but that doesn't seem to work. I've also tried !PauseMeasure and that didn't seem to work either.
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Weather Temperature Dynamic Color, a different perspective

Post by SilverAzide »

How about setting the meter to hidden (Hidden=1) until you are ready to display the proper color?
After the !SetOption bang that sets the colors, add [!ShowMeter MeterCurrentTemp][!UpdateMeter MeterCurrentTemp] to show it and have it update immediately. There are other ways also, but this is one...
Gadgets Wiki GitHub More Gadgets...
gator
Posts: 14
Joined: May 29th, 2020, 3:35 pm

Re: Weather Temperature Dynamic Color, a different perspective

Post by gator »

Thank you for the suggestion. If I apply it to the code sample in my first post, it eliminates the white degree symbol but I still see the blue temperature and degree symbol before it changes to the correct color on a load or refresh. If I apply it to the code in the attached skin where there is an extra measure where the RGB value is set and the measure doing the calculation has a different name, that worked great. I'll use that "working" version with the extra measure for each temperature scale if there isn't a way to get it to work with the code in my first post.