It is currently March 29th, 2024, 1:01 pm

Dynamically change the color of a Roundline

Get help with installing and using Rainmeter.
kickka
Posts: 2
Joined: November 1st, 2016, 5:03 pm

Dynamically change the color of a Roundline

Post by kickka »

Pretty simple problem (I assume).

I have a RoundLine meter which I wish to change color based on the value of a number pulled from the webparser plugin.

What I have is:

Code: Select all

IfCondition=(MeasureReviews >= 0) && (MeasureReviews <= 150)
IfTrueAction=[!SetOption MeterRoundlineIndicator LineColor Floor((#RIndicator2# - #RIndicator1#)*(MeasureReviews / 150)),...truancated]
I cut out the green and blue values since it's basically the same and made the line way too long.

The formula I know works since I've tested it in a calc (which I also unsuccessfully tried to use to change the color).

Reason why it's in an ifcondition is that between 0 and 150 I want it to go from green to orange, then between 151 and 299 it goes from orange to red. Anything above 300 hundred activates a config which has a flashing animation.

I know for sure the condition is met and the action is done. If I replace the formula with numbers then everything works great. As it is, I get no change.

Anyone know?
Last edited by kickka on November 2nd, 2016, 7:10 am, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Dynamically change the color of a Roundline

Post by balala »

The condition can be met, but you can't set a color as you tried. Any color option (like LineColor, FontColor or SolidColor) require a string indicating the needed color code. This can't be achieved with a mathematical formula, like that used by you. Instead, as you said, you should use a Calc measure to set the color. I'd propose the following approach: replace the IfTrueAction option with something like:

Code: Select all

IfCondition=((MeasureReviews>=0)&&(MeasureReviews<=150))
IfTrueAction=[!SetVariable LineColor "0"]
IfCondition2=((MeasureReviews>=151)&&(MeasureReviews<=299))
IfTrueAction2=[!SetVariable LineColor "1"]
IfCondition3=(MeasureReviews>=300)
IfTrueAction3=[!SetVariable LineColor "2"]
In this case, LineColor will be a variable, used to set the appropriate color, through the following measure:

Code: Select all

[MeasureSetColor]
Measure=Calc
Formula=#LineColor#
IfCondition=(MeasureSetColor=0)
IfTrueAction=[!SetOption MeterRoundlineIndicator LineColor "The Code Of The Needed Color When (MeasureReviews >= 0) && (MeasureReviews <= 150)"]
IfCondition2=(MeasureSetColor=1)
IfTrueAction2=[!SetOption MeterRoundlineIndicator LineColor "The Code Of The Needed Color When (MeasureReviews >= 151) && (MeasureReviews <= 299)"]
IfCondition3=(MeasureSetColor=2)
IfTrueAction3=[!ActivateConfig "Whatever"]
DynamicVariables=1
In this code, you'll have to add the appropriate color codes and config name.
Try this solution, if you can't handle what I wrote, please post the entire code you have so far and exactly what you'd wish to achieve.
kickka
Posts: 2
Joined: November 1st, 2016, 5:03 pm

Re: Dynamically change the color of a Roundline

Post by kickka »

What you gave me was very similar to things I had already tried.

That said I figured out the solution. Was very simple but my inexperience with Rainmeter was holding me back.

My solution was as follows:

Code: Select all

IfCondition=MeasureReviews < 300
IfTrueAction=[!DeactivateConfig "BlackBar\flasher" "flasher.ini"]

IfCondition=2MeasureReviews >= 300
IfTrueAction=2[!ActivateConfig "BlackBar\flasher" "flasher.ini"]

OnUpdateAction=[!UpdateMeter MeterRoundlineIndicator][!Redraw]


[RLower]
Measure=Calc
Formula=MeasureReviews <= 150 ? Floor((#RIndicator2# - #RIndicator1#)*(MeasureReviews / 150)) : Floor(240+((#RIndicator3# - #RIndicator2#)*((MeasureReviews / 300)-1)))

[GLower]
Measure=Calc
Formula=MeasureReviews <= 150 ? Floor(198+((#GIndicator2#-#GIndicator1#)*(MeasureReviews / 150))) : Floor(230-((#GIndicator2#-#GIndicator3#)*((MeasureReviews / 300)-1)))

[BLower]
Measure=Calc
Formula=MeasureReviews <= 150 ? Floor((#BIndicator2#-#BIndicator1#)*(MeasureReviews / 150)) : Floor(140-((#BIndicator3#-#BIndicator2#)*((MeasureReviews / 300)-1)))

[ALower]
Measure=Calc
Formula=MeasureReviews <= 300 ? 255 : 0

Code: Select all

[MeterRoundlineIndicator]
Meter=Roundline
...
LineColor=[RLower],[GLower],[BLower],[ALower]
DynamicVariables=1
It never occurred to me that ternary operators might be a thing in Rainmeter. Became simple once I found out. The formulae could probably be improved but I'm not fussed, it only updates every 5 minutes so efficiency is irrelevant.

Thanks for your help anyway.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Dynamically change the color of a Roundline

Post by balala »

As I said, the color codes are in fact strings, that's why a calc measure can't be used to get them. But using three or four calc measures is perfectly ok, the only thing you have to be careful is to use the DynamicVariables=1 option on the meter which you'd like to use the values returned by those calc measures (in your case, the [MeterRoundlineIndicator] meter, but you did this).
I'm glad if your code is working well.