It is currently April 25th, 2024, 4:50 am

How to choose a color based on the value of luminance (Chameleon)

Get help with creating, editing & fixing problems with skins
Neon
Posts: 3
Joined: June 8th, 2018, 11:21 am

How to choose a color based on the value of luminance (Chameleon)

Post by Neon »

Hey guys this is my first post and I want to say beforehand, that I'm not really code-savvy.

On to my problem: I started using the Chameleon Plugin by socks-the-fox (https://software.socksthefox.net/chameleon/), which basically chooses colors for measures based on your desktop wallpaper colors. You probably know it anyway ;-)
The thing is, I want to use the "Luminance" function implemented, which gives you a value between 0-1 by looking at the overall brightness of the wallpaper. What I want to do is, to implement an IfCondition that changes the Colors of my measures based on this luminance value. In other words when the value is above 0.5, which means the wallpaper is bright/white, the skin color changes to black and vice versa, to garantuee that the skin is actually visible no matter which wallpaper is loaded.

The thing is, i don't really know how to write and where to even place this IfCondition. I imagined it might be something like this:

Code: Select all

[ChameleonDesktop]
Measure=Plugin
Plugin=Chameleon
Type=Desktop

[DesktopBG1]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Luminance
IfAboveValue=0.5
IfAboveAction=[!SetOption MeterBatteryPercent FontColor "0,0,0,255"] [!Redraw]
IfBelowValue=0.5
IfBelowAction=[!SetOption MeterBatteryPercent Fontcolor "255,255,255,255"] [!Redraw]

[MeasureBatteryPercent]
Measure=Plugin
Plugin=PowerPlugin
PowerState=Percent

[MeterBatteryPercent]
Meter=String
MeasureName=MeasureBatteryPercent
X=250
Y=237
StringAlign=CENTER
FontSize=15
FontFace=Century Gothic
FontColor=255,255,255,255
Text=%1%
AntiAlias=1
DynamicVariables=1
I would be glad if someone could help me!
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: How to choose a color based on the value of luminance (Chameleon)

Post by FreeRaider »

I would use an IF Condition statement.

For example
Skin.ini

Code: Select all

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

[ChameleonDesktop]
Measure=Plugin
Plugin=Chameleon
Type=Desktop

[DesktopBG1]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Luminance
IfCondition=DesktopBG1 >= 0.5
IfTrueAction=[!SetOption MeterBatteryPercent FontColor "0,0,0,255"][!Redraw]
IfFalseAction=[!SetOption MeterBatteryPercent Fontcolor "255,255,255,255"][!Redraw]
DynamicVariables=1

[MeasureBatteryPercent]
Measure=Plugin
Plugin=PowerPlugin
PowerState=Percent

[MeterBatteryPercent]
Meter=String
MeasureName=MeasureBatteryPercent
X=250
Y=237
StringAlign=CENTER
FontSize=15
FontFace=Century Gothic
FontColor=255,255,255,255
Text=%1%
AntiAlias=1
DynamicVariables=1
If luminance is greater than or equal to 0.5 then font is black (0,0,0,255), else it is white (255,255,255,255).
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to choose a color based on the value of luminance (Chameleon)

Post by balala »

The IfCondition statements are newer options then the IfActions and probably are a bit better, but anyway with the initial IfActions, posted by Neon, there is a small problem. The case when the value of the measure is exactly 0.5 isn't included nowhere:
Neon wrote:

Code: Select all

...IfAboveValue=0.5
IfAboveAction=[!SetOption MeterBatteryPercent FontColor "0,0,0,255"] [!Redraw]
IfBelowValue=0.5
IfBelowAction=[!SetOption MeterBatteryPercent Fontcolor "255,255,255,255"] [!Redraw]
...
The IfAboveAction is executed when the value of the measure is (strictly) greater then 0.5, while the IfBelowAction is executed when the value of the measure is (strictly) below 0.5. What if the value of the measure is exactly 0.5?
The IfCondition posted by FreeRaider simply includes this case, too: IfCondition=DesktopBG1 >= 0.5.

Just one more. This isn't something which would affect anyway how the the posted codes are working (and here I'm talking about both posted codes, by Neon and FreeRaider), but if you set a Fontcolor through a !SetOption bang, doesn't worth to simply redraw the skin. Instead you should have to update the appropriate meter, then redraw the skin:

Code: Select all

[DesktopBG1]
...
IfAboveValue=0.5
IfAboveAction=[!SetOption MeterBatteryPercent FontColor "0,0,0,255"][!UpdateMeter "MeterBatteryPercent"][!Redraw]
IfBelowValue=0.5
IfBelowAction=[!SetOption MeterBatteryPercent Fontcolor "255,255,255,255"][!UpdateMeter "MeterBatteryPercent"][!Redraw]
or:

Code: Select all

[DesktopBG1]
...
IfCondition=DesktopBG1 >= 0.5
IfTrueAction=[!SetOption MeterBatteryPercent FontColor "0,0,0,255"][!UpdateMeter "MeterBatteryPercent"][!Redraw]
IfFalseAction=[!SetOption MeterBatteryPercent Fontcolor "255,255,255,255"][!UpdateMeter "MeterBatteryPercent"][!Redraw]
Neon
Posts: 3
Joined: June 8th, 2018, 11:21 am

Re: How to choose a color based on the value of luminance (Chameleon)

Post by Neon »

Thank you both, it seems to work. Now I just have to implement it for every part of my skin. I can just put in another [!SetOption ...] command after the first one for the battery, right? So it also changes my clock and background.

Edit: Nervermind, it works!
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to choose a color based on the value of luminance (Chameleon)

Post by balala »

Neon wrote:I can just put in another [!SetOption ...] command after the first one for the battery, right? So it also changes my clock and background.

Edit: Nervermind, it works!
Yes, as it seems you've figured out by yourself, you can. Even more then two. Practically no upper limit.
Just a small adjustment: [!SetOption ...] is a bang, not a command in the Rainmeter terminology.
Neon
Posts: 3
Joined: June 8th, 2018, 11:21 am

Re: How to choose a color based on the value of luminance (Chameleon)

Post by Neon »

Good to know, learning something new everyday. Thanks again
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to choose a color based on the value of luminance (Chameleon)

Post by balala »

Neon wrote:Good to know, learning something new everyday.
:17good