It is currently March 9th, 2021, 11:27 am

Smart Chameleon Not Smart Enough

Help with creating, editing & fixing problems with skins
User avatar
ZipD
Posts: 31
Joined: September 10th, 2017, 4:31 pm

Smart Chameleon Not Smart Enough

Post by ZipD »

I've been a trying to get the Chameleon plugin to be a little smarter by comparing Foreground 1 with Background 1, and Foreground 2 with Background 2, choosing the 'brighter' color and replacing the measure values accordingly.

In this skin, I only use 4 colors (Foreground 1, 2, and Background 1, 2). The Light and Dark colors are repeats anyway and not useful in my opinion.

The problem I have with this is that whenever the wallpaper change, the new colors don't get updated, instead it still shows colors from the previous wallpaper. The picture I've added below shows the first 4 squares representing the current wallpaper's colors, and the 4 squares below SHOULD show the swapped colors (or not swapped, depending on brightness values):
Image

This is what should happen:
Image

But as you can see, the second row of 4 squares are not updating as expected. What I did try is add DynamicVariables to each of the chameleon measures (PreFG1, PreFG2, PreBG1 and PreBG2) and also add a force update of the measures that does the color swapping whenever they change but that doesn't seem to help. However, if I do a manual refresh, the swapping occurs.

Any help is appreciated.

Here's the code for the included file that does all the color swapping:

Code: Select all

--------------------------------------------------------------------------------------
; VARIABLES
--------------------------------------------------------------------------------------
[Variables]
; This will be populated with measures below once comparisons are done
FG1=""
FG2=""
BG1=""
BG2=""

--------------------------------------------------------------------------------------
; PRIMARY MEASURES
--------------------------------------------------------------------------------------
[ChameleonDesktop]
Measure=Plugin
Plugin=Chameleon
Type=Desktop
; Comment out Crop lines to disable color sampling under skin and instead use the entire wallpaper.
;CropX=#CURRENTCONFIGX#
;CropY=#CURRENTCONFIGY#
;CropW=#CURRENTCONFIGWIDTH#
;CropH=#CURRENTCONFIGHEIGHT#
ContextAwareColors=0
DynamicVariables=1

[PreFG1]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Foreground1
Format=Dec
OnChangeAction=[!UpdateMeasureGroup SwapColors]
DynamicVariables=1

[PreFG2]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Foreground2
Format=Dec
OnChangeAction=[!UpdateMeasureGroup SwapColors]
DynamicVariables=1

[PreBG1]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Background1
Format=Dec
OnChangeAction=[!UpdateMeasureGroup SwapColors]
DynamicVariables=1

[PreBG2]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Background2
Format=Dec
OnChangeAction=[!UpdateMeasureGroup SwapColors]
DynamicVariables=1

--------------------------------------------------------------------------------------
; PRE SWAP COLOR VALUE MEASURES
--------------------------------------------------------------------------------------
; Pre FG1
	[MeasureRedPreFG1]
	Measure=String
	String=[PreFG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\1"
	DynamicVariables=1

	[MeasureGreenPreFG1]
	Measure=String
	String=[PreFG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\2"
	DynamicVariables=1

	[MeasureBluePreFG1]
	Measure=String
	String=[PreFG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\3"
	DynamicVariables=1

; Pre FG2
	[MeasureRedPreFG2]
	Measure=String
	String=[PreFG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\1"
	DynamicVariables=1

	[MeasureGreenPreFG2]
	Measure=String
	String=[PreFG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\2"
	DynamicVariables=1

	[MeasureBluePreFG2]
	Measure=String
	String=[PreFG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\3"
	DynamicVariables=1

; Pre BG1
	[MeasureRedPreBG1]
	Measure=String
	String=[PreBG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\1"
	DynamicVariables=1

	[MeasureGreenPreBG1]
	Measure=String
	String=[PreBG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\2"
	DynamicVariables=1

	[MeasureBluePreBG1]
	Measure=String
	String=[PreBG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\3"
	DynamicVariables=1

; Pre BG2
	[MeasureRedPreBG2]
	Measure=String
	String=[PreBG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\1"
	DynamicVariables=1

	[MeasureGreenPreBG2]
	Measure=String
	String=[PreBG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\2"
	DynamicVariables=1

	[MeasureBluePreBG2]
	Measure=String
	String=[PreBG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\3"
	DynamicVariables=1

--------------------------------------------------------------------------------------
; PRE SWAP COLOR TOTAL MEASURES
--------------------------------------------------------------------------------------
[MeasureColorPreFG1]
Measure=Calc
Formula=( [MeasureRedPreFG1] + [MeasureGreenPreFG1] + [MeasureBluePreFG1] )
DynamicVariables=1

[MeasureColorPreFG2]
Measure=Calc
Formula=( [MeasureRedPreFG2] + [MeasureGreenPreFG2] + [MeasureBluePreFG2] )
DynamicVariables=1

[MeasureColorPreBG1]
Measure=Calc
Formula=( [MeasureRedPreBG1] + [MeasureGreenPreBG1] + [MeasureBluePreBG1] )
DynamicVariables=1

[MeasureColorPreBG2]
Measure=Calc
Formula=( [MeasureRedPreBG2] + [MeasureGreenPreBG2] + [MeasureBluePreBG2] )
DynamicVariables=1

--------------------------------------------------------------------------------------
; SWAP MEASURES
--------------------------------------------------------------------------------------
[MeasureSwapFG1withBG1]
Measure=Calc
IfCondition=MeasureColorPreFG1>MeasureColorPreBG1
IfTrueAction=[!SetVariable "FG1" "[PreFG1]"][!SetVariable "BG1" "[PreBG1]"]
IfFalseAction=[!SetVariable "FG1" "[PreBG1]"][!SetVariable "BG1" "[PreFG1]"]
Group=SwapColors
DynamicVariables=1

[MeasureSwapFG2withBG2]
Measure=Calc
IfCondition=MeasureColorPreFG2>MeasureColorPreBG2
IfTrueAction=[!SetVariable "FG2" "[PreFG2]"][!SetVariable "BG2" "[PreBG2]"]
IfFalseAction=[!SetVariable "FG2" "[PreBG2]"][!SetVariable "BG2" "[PreFG2]"]
Group=SwapColors
DynamicVariables=1

--------------------------------------------------------------------------------------
; SET VALUES MEASURES
--------------------------------------------------------------------------------------
[ChamFG1]
Measure=String
String=#FG1#
Group=SwapColors
DynamicVariables=1

[ChamFG2]
Measure=String
String=#FG2#
Group=SwapColors
DynamicVariables=1

[ChamBG1]
Measure=String
String=#BG1#
Group=SwapColors
DynamicVariables=1

[ChamBG2]
Measure=String
String=#BG2#
Group=SwapColors
DynamicVariables=1
You do not have the required permissions to view the files attached to this post.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4226
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Smart Chameleon Not Smart Enough

Post by eclectic-tech »

Edit '@Resources\SmartChameleon.inc'

Add IfConditionMode=1 to [MeasureSwapFG1withBG1] and [MeasureSwapFG2withBG2].

Comment out (or delete) OnChangeAction=[!UpdateMeasureGroup SwapColors] from [PreFG1], [ PreFG2]. [PreBG1], and [PreBG2]. That is not needed since adding IfConditionMode=1.

Remove DynamicVariables=1 from those same 4 'Pre' chameleon measures and from the parent chameleon measure, as they are not needed.

This will now swap FG/BG based on the luminance values of chameleon colors obtained from the current wallpaper.
User avatar
ZipD
Posts: 31
Joined: September 10th, 2017, 4:31 pm

Re: Smart Chameleon Not Smart Enough

Post by ZipD »

Always super helpful. Thanks eclectic-tech, this worked perfectly!
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4226
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Smart Chameleon Not Smart Enough

Post by eclectic-tech »

Happy to help.
User avatar
jsmorley
Developer
Posts: 21564
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Smart Chameleon Not Smart Enough

Post by jsmorley »

What works for me when using "luminance" to set colors based on the brightness of the wallpaper under the skin in question is this:

Code: Select all

[Variables]
Color1=255,255,255
Color2=0,255,0

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

[Light1]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Format=Dec
Color=Light1
OnChangeAction=[!UpdateMeasureGroup Luminance]

[Light2]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Format=Dec
Color=Light2
OnChangeAction=[!UpdateMeasureGroup Luminance]

[Dark1]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Format=Dec
Color=Dark1
OnChangeAction=[!UpdateMeasureGroup Luminance]

[Dark2]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Format=Dec
Color=Dark2
OnChangeAction=[!UpdateMeasureGroup Luminance]

[MeasureChangePosition]
Measure=Calc
Formula=#CURRENTCONFIGX#
DynamicVariables=1
OnChangeAction=[!UpdateMeasureGroup Luminance]

[ChameleonLuminance]
Measure=Plugin
Group=Luminance
Plugin=Chameleon
Type=Desktop
UpdateDivider=-1
CropX=#CURRENTCONFIGX#
CropY=#CURRENTCONFIGY#
CropW=#CURRENTCONFIGWIDTH#
CropH=#CURRENTCONFIGHEIGHT#
DynamicVariables=1

[Luminance]
Measure=Plugin
Group=Luminance
Plugin=Chameleon
Parent=ChameleonLuminance
Format=Dec
Color=Luminance
UpdateDivider=-1
IfCondition=Luminance <= 0.5
IfTrueAction=[!SetVariable Color1 "[Light1]"][!SetVariable Color2 "[Light2]"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetVariable Color1 "[Dark1]"][!SetVariable Color2 "[Dark2]"][!UpdateMeter *][!Redraw]
IfConditionMode=1
So I'm watching for any or all of the overall colors of the background to change. I also check to see if the skin's "position" on the screen has changed. Those cause me to trigger the "luminance" measures to fire off, check the luminance of the bit of the wallpaper under the skin, and set color variables accordingly.

The idea is that I want the "colors" to be based on the entire screen background, but I want the test of the "luminance" to be based on what is under the actual skin.

It's true that IfConditionMode=1 is important in this, as the answer can easily be "true" twice in a row, and yet you still want the colors to change. However, this approach doesn't allow IfConditionMode to hammer pointless !SetVariable's on every single skin update, due to the UpdateDivider=-1 on the "luminance" measures.
User avatar
ZipD
Posts: 31
Joined: September 10th, 2017, 4:31 pm

Re: Smart Chameleon Not Smart Enough

Post by ZipD »

I forgot to give back from all the help I got, so this is the final code I'm using. Just put this in a .inc file that you include in the usual variable section (overriding the chameleon.inc) and you can still use the ChamFG1, ChamFG2, ChamBG1, and ChamBG2 for your existing skins.

This will sort all 4 colors (ChamFG1, FG2, BG1 and BG2) according to their total RGB values, highest being the brightest and lowest being the darkest.

Code: Select all

--------------------------------------------------------------------------------------
; VARIABLES
--------------------------------------------------------------------------------------
[Variables]
; This will be populated with measures below once comparisons are done
FG1=""
FG2=""
BG1=""
BG2=""

--------------------------------------------------------------------------------------
; PRIMARY MEASURES
--------------------------------------------------------------------------------------
[ChameleonDesktop]
Measure=Plugin
Plugin=Chameleon
Type=Desktop
; Comment out Crop lines to disable color sampling under skin and instead use the entire wallpaper.
;CropX=#CURRENTCONFIGX#
;CropY=#CURRENTCONFIGY#
;CropW=#CURRENTCONFIGWIDTH#
;CropH=#CURRENTCONFIGHEIGHT#
ContextAwareColors=0
DynamicVariables=1

[PreFG1]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Foreground1
Format=Dec

[PreFG2]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Foreground2
Format=Dec

[PreBG1]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Background1
Format=Dec

[PreBG2]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Color=Background2
Format=Dec

--------------------------------------------------------------------------------------
; PRE SWAP COLOR VALUE MEASURES
--------------------------------------------------------------------------------------
; Pre FG1
	[MeasureRedPreFG1]
	Measure=String
	String=[PreFG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\1"
	DynamicVariables=1

	[MeasureGreenPreFG1]
	Measure=String
	String=[PreFG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\2"
	DynamicVariables=1

	[MeasureBluePreFG1]
	Measure=String
	String=[PreFG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\3"
	DynamicVariables=1

; Pre FG2
	[MeasureRedPreFG2]
	Measure=String
	String=[PreFG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\1"
	DynamicVariables=1

	[MeasureGreenPreFG2]
	Measure=String
	String=[PreFG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\2"
	DynamicVariables=1

	[MeasureBluePreFG2]
	Measure=String
	String=[PreFG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\3"
	DynamicVariables=1

; Pre BG1
	[MeasureRedPreBG1]
	Measure=String
	String=[PreBG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\1"
	DynamicVariables=1

	[MeasureGreenPreBG1]
	Measure=String
	String=[PreBG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\2"
	DynamicVariables=1

	[MeasureBluePreBG1]
	Measure=String
	String=[PreBG1]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\3"
	DynamicVariables=1

; Pre BG2
	[MeasureRedPreBG2]
	Measure=String
	String=[PreBG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\1"
	DynamicVariables=1

	[MeasureGreenPreBG2]
	Measure=String
	String=[PreBG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\2"
	DynamicVariables=1

	[MeasureBluePreBG2]
	Measure=String
	String=[PreBG2]
	RegExpSubstitute=1
	Substitute="^(\d{1,}),(\d{1,}),(\d{1,})":"\3"
	DynamicVariables=1

--------------------------------------------------------------------------------------
; PRE SWAP COLOR TOTAL MEASURES
--------------------------------------------------------------------------------------
[MeasureColorPreFG1]
Measure=Calc
Formula=( [MeasureRedPreFG1] + [MeasureGreenPreFG1] + [MeasureBluePreFG1] )
DynamicVariables=1

[MeasureColorPreFG2]
Measure=Calc
Formula=( [MeasureRedPreFG2] + [MeasureGreenPreFG2] + [MeasureBluePreFG2] )
DynamicVariables=1

[MeasureColorPreBG1]
Measure=Calc
Formula=( [MeasureRedPreBG1] + [MeasureGreenPreBG1] + [MeasureBluePreBG1] )
DynamicVariables=1

[MeasureColorPreBG2]
Measure=Calc
Formula=( [MeasureRedPreBG2] + [MeasureGreenPreBG2] + [MeasureBluePreBG2] )
DynamicVariables=1

--------------------------------------------------------------------------------------
; SWAP MEASURES
--------------------------------------------------------------------------------------
[MeasureSwapFG1withBG1]
Measure=Calc
Formula=MeasureColorPreFG1
; IfConditionMode=1 will execute the appropriate actions in IfTrueAction or IfFalseAction on every update of the measure
IfConditionMode=1
IfCondition=MeasureColorPreFG1>MeasureColorPreBG1
IfTrueAction=[!SetVariable "FG1" "[PreFG1]"][!SetVariable "BG1" "[PreBG1]"]
IfFalseAction=[!SetVariable "FG1" "[PreBG1]"][!SetVariable "BG1" "[PreFG1]"]
DynamicVariables=1

[MeasureSwapFG2withBG2]
Measure=Calc
Formula=MeasureColorPreFG2
; IfConditionMode=1 will execute the appropriate actions in IfTrueAction or IfFalseAction on every update of the measure
IfConditionMode=1
IfCondition=MeasureColorPreFG2>MeasureColorPreBG2
IfTrueAction=[!SetVariable "FG2" "[PreFG2]"][!SetVariable "BG2" "[PreBG2]"]
IfFalseAction=[!SetVariable "FG2" "[PreBG2]"][!SetVariable "BG2" "[PreFG2]"]
DynamicVariables=1

[MeasureSwapFG1withFG2]
Measure=Calc
Formula=MeasureColorPreFG1
; IfConditionMode=1 will execute the appropriate actions in IfTrueAction or IfFalseAction on every update of the measure
IfConditionMode=1
IfCondition=MeasureColorPreFG1>MeasureColorPreFG2
IfTrueAction=[!SetVariable "FG2" "[PreFG2]"][!SetVariable "FG1" "[PreFG1]"]
IfFalseAction=[!SetVariable "FG1" "[PreFG2]"][!SetVariable "FG2" "[PreFG1]"]
DynamicVariables=1

[MeasureSwapBG1withBG2]
Measure=Calc
Formula=MeasureColorPreBG1
; IfConditionMode=1 will execute the appropriate actions in IfTrueAction or IfFalseAction on every update of the measure
IfConditionMode=1
IfCondition=MeasureColorPreBG1>MeasureColorPreBG2
IfTrueAction=[!SetVariable "BG2" "[PreBG2]"][!SetVariable "BG1" "[PreBG1]"]
IfFalseAction=[!SetVariable "BG1" "[PreBG2]"][!SetVariable "BG2" "[PreBG1]"]
DynamicVariables=1

--------------------------------------------------------------------------------------
; SET VALUES MEASURES
--------------------------------------------------------------------------------------
[ChamFG1]
Measure=String
String=#FG1#
DynamicVariables=1

[ChamFG2]
Measure=String
String=#FG2#
DynamicVariables=1

[ChamBG1]
Measure=String
String=#BG1#
DynamicVariables=1

[ChamBG2]
Measure=String
String=#BG2#
DynamicVariables=1