It is currently April 23rd, 2024, 9:54 pm

Change Color (Gradient) based on value

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change Color (Gradient) based on value

Post by balala »

Carje wrote: March 22nd, 2019, 8:47 pm Perfect, it worked!

So, to understand the code:
R = Clamp((5.1*[MeasureCPU]),0,255) -> R is 5.1 * MeasureCPU value with a value of min 0 and max 255
G = Clamp((255-(2.55*[MeasureCPU])),0,255) -> G is 2.55 * MeasureCPU value, subtracted from 255, with a value of min 0 and max 255
B = 0
MeasureCPU value being an integer of CPU usage between 0 and 100

Is this right ?
It is, perfectly.
To explain why have I done it this way, you probably know that green is 0,255,0, red is 255,0,0, while orange is 255,127,0. So, from green to orange (from 0% up to 50%), the red component of the color code has to increase from 0 up to 255 and above 50% it has to be kept on 255. Multiplying the CPU usage percent (the value of the [MeasureCPU] measure) with 5.1, I got exactly this variation. Since the product above 50% would increase above 255 (which shouldn't have to go on), I used the Clamp function, to limit the result.
The green component has to decrease from 255 (the green component of the color used for 0%), to 0% (the same green component for the color used on 100%). The result of multiplication of 2.55 with the CPU usage increases from 0 to 255. I substracted this value from 255. Just for safe I also added another Clamp function.
I suppose is clare what have I done for the blue component: I kept it on 0, since it's not involved at all in non of the needed colors.
I'm glad if it does work as you wanted.
Carje
Posts: 6
Joined: March 22nd, 2019, 4:23 pm

Re: Change Color (Gradient) based on value

Post by Carje »

balala wrote: March 22nd, 2019, 9:01 pm It is, perfectly.
To explain why have I done it this way, you probably know that green is 0,255,0, red is 255,0,0, while orange is 255,127,0. So, from green to orange (from 0% up to 50%), the red component of the color code has to increase from 0 up to 255 and above 50% it has to be kept on 255. Multiplying the CPU usage percent (the value of the [MeasureCPU] measure) with 5.1, I got exactly this variation. Since the product above 50% would increase above 255 (which shouldn't have to go on), I used the Clamp function, to limit the result.
The green component has to decrease from 255 (the green component of the color used for 0%), to 0% (the same green component for the color used on 100%). The result of multiplication of 2.55 with the CPU usage increases from 0 to 255. I substracted this value from 255. Just for safe I also added another Clamp function.
I suppose is clare what have I done for the blue component: I kept it on 0, since it's not involved at all in non of the needed colors.
I'm glad if it does work as you wanted.
I was wondering how you got those multipliers, I suppose you just tested till it worked
It does work as intended, thank you!
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change Color (Gradient) based on value

Post by balala »

Carje wrote: March 22nd, 2019, 9:18 pm I was wondering how you got those multipliers, I suppose you just tested till it worked
No, at all. I calculated them with a simple division. For example the green component has to vary between 255 and 0, while the percentage goes from 0 to 100. This means for every percent, the color component has to increase with 2.55, given by 255/100.
Carje wrote: March 22nd, 2019, 9:18 pm It does work as intended, thank you!
I'm glad. :thumbup:
User avatar
HUNTwerker
Posts: 20
Joined: February 2nd, 2024, 12:33 pm

Re: Change Color (Gradient) based on value

Post by HUNTwerker »

balala wrote: March 22nd, 2019, 8:04 pm Try to add the following FontColor option to the [meterValueCPU] meter: FontColor=(Clamp((5.1*[MeasureCPU]),0,255)),(Clamp((255-(2.55*[MeasureCPU])),0,255)),0. Along with this FontColor, you have to add as well a DynamicVariables=1 option to the same [meterValueCPU] meter. Don't forget nor this.
Hi,

why does this work for the CPU and GPU but not for the RAM? :(


Thanks for Help... ;-)

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[MeasurePhysMemTotal]
Measure=PhysicalMemory
Total=1
UpdateDivider=3600

[MeasurePhysMemUsed]
Measure=PhysicalMemory
UpdateDivider=2

[MeasurePhysMemFree]
Measure=PhysicalMemory
InvertMeasure=1
UpdateDivider=2


[MeterText]
Meter=String
MeasureName=MeasurePhysMemUsed
FontColor=(Clamp((2.55*[MeasurePhysMemUsed]),0,255)),(Clamp((255-(2.55*[MeasurePhysMemUsed])),0,255)),0
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=1
AutoScale=1
DynamicVariables=1
Last edited by HUNTwerker on February 11th, 2024, 1:10 pm, edited 1 time in total.
User avatar
Yincognito
Rainmeter Sage
Posts: 7151
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Change Color (Gradient) based on value

Post by Yincognito »

HUNTwerker wrote: February 10th, 2024, 9:42 pm Hi,

why does this work for the CPU and GPU but not for the RAM? :(


Thanks for Help... ;-)

Code: Select all

; ----------------------------------
; RAM USE 
; ----------------------------------

[MeasurePhysMemUsed]
Measure=PhysicalMemory
UpdateDivider=2
DynamicVariables=1

[MeterRAM]
Meter=STRING
MeasureName=MeasurePhysMemUsed
X=32
Y=31r
W=56
H=56
FontColor=(Clamp((2.55*[MeasurePhysMemUsed]),0,255)),(Clamp((255-(2.55*[MeasurePhysMemUsed])),0,255)),0
FontWeight=#Default_FontWeight#
StringEffect=#Default_StringEffect#
StringAlign=#Default_StringAlign#
Fontsize=#Default_Fontsize#
Fontface=#Default_Fontface#
Scale=1073741824
Might be wrong as I didn't test it, but I suspect that's because again, you didn't completely follow the instructions. Read the last two sentences in the part you just quoted above and apply them to your case, and you'll understand. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
HUNTwerker
Posts: 20
Joined: February 2nd, 2024, 12:33 pm

Re: Change Color (Gradient) based on value

Post by HUNTwerker »

Yincognito wrote: February 11th, 2024, 12:43 pm Might be wrong as I didn't test it, but I suspect that's because again, you didn't completely follow the instructions. Read the last two sentences in the part you just quoted above and apply them to your case, and you'll understand. ;-)
I'm sorry, but no matter where I enter DynamicVariables=1, either the free ram is displayed green or red

The color does not change dynamically depending on the RAM used, it works without problems when the CPU or GPU is under load.

Unfortunately I don't know what to do next :yawn:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[MeasurePhysMemTotal]
Measure=PhysicalMemory
Total=1
UpdateDivider=3600

[MeasurePhysMemUsed]
Measure=PhysicalMemory
UpdateDivider=2

[MeasurePhysMemFree]
Measure=PhysicalMemory
InvertMeasure=1
UpdateDivider=2


[MeterText]
Meter=String
MeasureName=MeasurePhysMemUsed
FontColor=(Clamp((2.55*[MeasurePhysMemUsed]),0,255)),(Clamp((255-(2.55*[MeasurePhysMemUsed])),0,255)),0
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=1
AutoScale=1
DynamicVariables=1
User avatar
Yincognito
Rainmeter Sage
Posts: 7151
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Change Color (Gradient) based on value

Post by Yincognito »

HUNTwerker wrote: February 11th, 2024, 1:13 pm I'm sorry, but no matter where I enter DynamicVariables=1, either the free ram is displayed green or red

The color does not change dynamically depending on the RAM used, it works without problems when the CPU or GPU is under load.

Unfortunately I don't know what to do next :yawn:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[MeasurePhysMemTotal]
Measure=PhysicalMemory
Total=1
UpdateDivider=3600

[MeasurePhysMemUsed]
Measure=PhysicalMemory
UpdateDivider=2

[MeasurePhysMemFree]
Measure=PhysicalMemory
InvertMeasure=1
UpdateDivider=2


[MeterText]
Meter=String
MeasureName=MeasurePhysMemUsed
FontColor=(Clamp((2.55*[MeasurePhysMemUsed]),0,255)),(Clamp((255-(2.55*[MeasurePhysMemUsed])),0,255)),0
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
NumOfDecimals=1
AutoScale=1
DynamicVariables=1
Ah, I see. I think the difference in this case is that the memory measures yield much bigger values (in bytes) than the 0 to 100 ones that were provided by the (percentage) values in the CPU / GPU case (remember, these formulas were designed for the latter case). I reckon that dividing the used memory value by the memory total one and multiplying with 100, and using this instead of the plain used memory value will solve this.

Or, you can try to directly use the percentual value of memory used, via [MeasurePhysMemUsed:%].
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change Color (Gradient) based on value

Post by balala »

HUNTwerker wrote: February 11th, 2024, 1:13 pm The color does not change dynamically depending on the RAM used, it works without problems when the CPU or GPU is under load.

Unfortunately I don't know what to do next :yawn:
Yincognito is perfectly right above: the [MeasurePhysMemUsed] measure is returning the value of the used memory in bytes. It is, for instance something like 7,216,500,736 (obviously this is just an example). In any case, this value is definitely not a percent, varying between 0 and 100%, to can be used as you've used it.
And again, as Yincognito wrote, you have to divide this value by the value returned by the [MeasurePhysMemTotal] measure, to get the needed percentage. This way the FontColor option of the [MeterText] should look for example as: FontColor=(Clamp((255*[MeasurePhysMemUsed]/[MeasurePhysMemTotal]),0,255)),(Clamp((255-(255*[MeasurePhysMemUsed]/[MeasurePhysMemTotal])),0,255)),0
Note that besides adding the [MeasurePhysMemTotal] into the above formulas, I also replaced the 2.55 value by 255. I had to do this because the [MeasurePhysMemUsed]/[MeasurePhysMemTotal] ration is varying between 0 and 1, not between 0 and 100, so the number it is multiplied by has to be 255.
User avatar
HUNTwerker
Posts: 20
Joined: February 2nd, 2024, 12:33 pm

Re: Change Color (Gradient) based on value

Post by HUNTwerker »

balala wrote: February 11th, 2024, 2:35 pm

It worked wonderfully, thank you and have a nice day 👍😎
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change Color (Gradient) based on value

Post by balala »

HUNTwerker wrote: February 11th, 2024, 2:52 pm It worked wonderfully, thank you and have a nice day 👍😎
Glad to help, even if Yincognito helped you at least as much...
Wish you a nice day as well.