It is currently April 27th, 2024, 7:17 pm

Change colour of bar depending on value

Get help with creating, editing & fixing problems with skins
PandaFace
Posts: 3
Joined: May 27th, 2012, 10:13 am

Change colour of bar depending on value

Post by PandaFace »

Basically what i'm trying to do is have a bar that shows my battery, from 0-100%
on its own this works fine, but in trying to make it change colour depending on how much battery you have left - so red if its lower than 20%, green if its full, or blue (default) if its anywhere between. this is my code so far:

Code: Select all

[colourBat]
Measure=Calc
Formula=([MeasurePercent] < 21 ? 2 : ([MeasurePercent] < 96 ? 3 : 1))
Substitute=".00000":"", "1":"0, 200, 0, 255", "2":"200, 0, 0, 255", "3":"0, 150, 208, 255"
DynamicVariables=1

[Bat_BAR]
MeasureName=MeasurePercent
Meter=ROUNDLINE
X=-51
Y=135
W=150
H=45
LineLength=68
LineStart=65
StartAngle=-6.28159265
RotationAngle=-1.95 ;.14159265
LineColor=[colourBat]
Solid=1
AntiAlias=1
DynamicVariables=1
ive been playing around with it for several hours now, so any help would be GREATLY appreciated :)
Thanks!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change colour of bar depending on value

Post by jsmorley »

You are almost there, good work. The only problem is that you have some conflicts in your Substitute option. You need to remember that the substitutions are done left to right, one at a time, and iterative. So the second substitute will replace things in the string "after" it has had the first substitute applied, and so on.

http://rainmeter.net/cms/Measures-Substitute_beta

So if you simply change [colourBat] to:

Code: Select all

[colourBat]
Measure=Calc
Formula=([MeasurePercent] < 21 ? -2 : ([MeasurePercent] < 96 ? -3 : -1))
Substitute="-1":"0,200,0,255","-2":"200,0,0,255","-3":"0,150,208,255"
DynamicVariables=1
You should be all set, as negative numbers are never going to be found in either the original or substituted value.
PandaFace
Posts: 3
Joined: May 27th, 2012, 10:13 am

Re: Change colour of bar depending on value

Post by PandaFace »

Thank you so much! judging by your success on this and every other problem you've solved, you must be some sort of super genius! (i'm hoping the Wile E Coyote reference isn't lost on you...) ;)
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change colour of bar depending on value

Post by jsmorley »

Glad to help. Now if I could only get those ACME rocket shoes to work right...