It is currently April 27th, 2024, 10:52 pm

Extracting variables from RGB code and then editing (Help Wanted!)

Get help with creating, editing & fixing problems with skins
Mr_House_Plants
Posts: 1
Joined: March 4th, 2024, 9:12 am

Extracting variables from RGB code and then editing (Help Wanted!)

Post by Mr_House_Plants »

Hello,

I would like some help with something related to chameleon plugin that I am working on.
I think it would be easiest for me to post the code, and share my objective, rather than just the objective.

Code: Select all

[Rainmeter]
Update=1000
Author=Connect-R
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1
AccurateText=1
MouseScrollUpAction=[!SetVariable Scale "(#Scale#+#ScrollMouseIncrement#)"][!WriteKeyValue Variables Scale "(#Scale#+#ScrollMouseIncrement#)"][!Refresh] 
MouseScrollDownAction=[!SetVariable Scale "(#Scale#-#ScrollMouseIncrement# < 0.5 ? 0.5 : #Scale#-#ScrollMouseIncrement#)"][!WriteKeyValue Variables Scale "(#Scale#-#ScrollMouseIncrement# < 0.5 ? 0.5 : #Scale#-#ScrollMouseIncrement#)"][!Refresh] 
LeftMouseDoubleClickAction=!ToggleConfig "Mond\Settings" "Settings.ini"

[Variables]
@include=#@#Variables.inc
@include2=#@#Language\#Language#.inc
Scale=1

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

[AverageLight]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Format=Dec
Color=Average
RegExp="(?siU)\[Variables\]\r\nColor1=(.+50*),(.+50*),(.+50*)
OnChangeAction=[!UpdateMeasureGroup Luminance]

[AverageDark]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Format=Dec
Color=Average
RegExp="(?siU)\[Variables\]\r\nColor1=(.-50*),(.-50*),(.-50*)
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 "[AverageDark]"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetVariable Color1 "[AverageLight]"][!UpdateMeter *][!Redraw]
IfConditionMode=1

;-------------------------------------------------------------
;-------------------------------------------------------------

[MeasureTime]
Measure=Time
Format="%#Format#:%M"

[MeasureAmPm]
Measure=Time
Format="%p"

[MeasureDay]
Measure=Time
Format=%A
Substitute=#Date#

[MeasureDate]
Measure=Time
Format=%d  %B,  %Y.
Substitute=#Date#

;-------------------------------------------------------------
;-------------------------------------------------------------

[Meter24hClock]
Meter=String
MeasureName=MeasureTime
StringAlign=Center
StringCase=Upper
FontFace=Quicksand
FontColor=#Color1#
FontSize=(14*#Scale#)
X=(340*#Scale#)
Y=(120*#Scale#)
Text="- %1 -"
AntiAlias=1
Hidden=#Hidden#
DynamicVariables=1

[Meter12hClock]
Meter=String
MeasureName=MeasureTime
MeasureName2=MeasureAmPm
StringAlign=Center
StringCase=Upper
FontFace=Quicksand
FontColor=[Average]
FontSize=(14*#Scale#)
X=(340*#Scale#)
Y=(120*#Scale#)
Text="- %1 %2 -"
AntiAlias=1
Hidden=#Hidden2#
DynamicVariables=1

[MeterDay]
Meter=String
MeasureName=MeasureDay
StringAlign=Center
StringCase=Upper
FontFace=Anurati
FontColor=#Color1#
FontSize=(40*#Scale#)
X=(340*#Scale#)
Y=(0*#Scale#)
Text="%1"
InlineSetting=CharacterSpacing | 10 | 10
AntiAlias=1
DynamicVariables=1

[MeterDate]
Meter=String
MeasureName=MeasureDate
StringAlign=Center
StringCase=Upper
FontFace=Quicksand
FontColor=#Color1#
FontSize=(14*#Scale#)
X=(340*#Scale#)
Y=(75*#Scale#)
Text="%1"
AntiAlias=1
DynamicVariables=1



There are 2 underlined sections of the code which I stole from @jsmorley in: https://forum.rainmeter.net/viewtopic.php?t=11185

EDIT: the lines weren't underlined. - the two lines were:
RegExp="(?siU)\[Variables\]\r\nColor1=(.-50*),(.-50*),(.-50*)
and
RegExp="(?siU)\[Variables\]\r\nColor1=(.+50*),(.+50*),(.+50*)

but me being new to rainmeter like I am, I thought I could just add + signs after the variables were there. :?
the goal is to check if the lumiance of the background is dark, and increase the brightness of the text if it is, and vice versa if it is dark.

However, nothing happens.
The clock will show up with the average color of the background, but there just isn't enough contrast for me. - and the colors aren't being added to the extracted RGB.

Any help is greatly appreciated!
Thank-You in advance.
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Extracting variables from RGB code and then editing (Help Wanted!)

Post by balala »

You can't apply a RegExp option to a Chameleon plugin measure, because it doesn't support this option. RegExp belongs basically to WebParser measures, jsmorley as well applied this option onto a WebParser measure (in 2012, when he posted the linked reply, WebParser was a Plugin measure, in meantime it has been converted to an internal measure - but this matters less). What I understood from your description, is that you'd like to add 50 to each component of the color code. If this is correct and this is indeed what you1d like to achieve, unfortunately it's not quite simple, however can be done.
Unfortunately you'll need three measures for each color code you'd like to alter. Each of them will return one of the components of the color code. Then you need another three measures, to get the value which is increased by what you want to add. Finally after this step, you can use the values returned by these last measures, to create the altered color code.
Here is a quick example:
First this is the measure I'll work with:

Code: Select all

[AverageLight]
Measure=Plugin
Plugin=Chameleon
Parent=ChameleonDesktop
Format=Dec
Color=Average
;RegExp="(?siU)\[Variables\]\r\nColor1=(.+50*),(.+50*),(.+50*)
OnChangeAction=[!UpdateMeasureGroup Luminance]
Note the commented out RegExp option.
Add the following three measures, which will return the three components of the color code returned by the measure:

Code: Select all

[AverageLightRed]
Measure=String
String=[AverageLight]
RegExpSubstitute=1
Substitute="(\d{1,3}),(\d{1,3}),(\d{1,3})":"\1"
DynamicVariables=1

[AverageLightGreen]
Measure=String
String=[AverageLight]
RegExpSubstitute=1
Substitute="(\d{1,3}),(\d{1,3}),(\d{1,3})":"\2"
DynamicVariables=1

[AverageLightBlue]
Measure=String
String=[AverageLight]
RegExpSubstitute=1
Substitute="(\d{1,3}),(\d{1,3}),(\d{1,3})":"\3"
DynamicVariables=1
Finally the measures which are returning the values increased by 50 each, will be the following ones:

Code: Select all

[AverageLightRed+50]
Measure=Calc
Formula=( [AverageLightRed] + 50 )
DynamicVariables=1

[AverageLightGreen+50]
Measure=Calc
Formula=( [AverageLightGreen] + 50 )
DynamicVariables=1

[AverageLightBlue+50]
Measure=Calc
Formula=( [AverageLightBlue] + 50 )
DynamicVariables=1
When you have these measure, the altered color code can be used as [AverageLightRed+50],[AverageLightGreen+50],[AverageLightBlue+50].

Sorry if I misunderstood your need. Please let me know if I did or got the idea.
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Extracting variables from RGB code and then editing (Help Wanted!)

Post by Yincognito »

FYI, if your background is really diverse in terms of colors and their layout, it won't help much to draw the text with a lighter / darker version of the average color for the skin region. In other words, the resulting color might be different enough to stand out when compared to some background pixels, but might not be that different when compared to other neighboring background pixels. I know this because I already did what you asked (the proper way, by keeping the hue of the color unchanged), and didn't post it yet for this reason.

Personally, I would additionally use either the plain or inline versions of StringEffect with a suited FontEffectColor for these String meters, in order to draw a border or a shadow around the text and making it more obvious over the background.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth