It is currently May 19th, 2024, 3:13 am

Modifying Color values with functions

Get help with creating, editing & fixing problems with skins
Eastwood
Posts: 35
Joined: November 1st, 2012, 10:50 pm

Modifying Color values with functions

Post by Eastwood »

The next thing I want to achieve is picking a root color, write a key in my styles.inc, and generate several variant colors.

This way I can pick a main color for my theme, and generate their variants with fixed parameters.
I have worked my way trough this Perlre manual to find a way to split the root color in R, G and B values. But I haven't learned a single useful bit for this case yet.

What I have in mind to start with is something like:

Code: Select all

;My styles.inc
[Variables]
 rootcolor=152,141,25,255
 downcolor="[downred],[downgreen],[downblue],255"
 overcolor="[overred],[overgreen],[overblue],255"
 morecolorvariants=...

[FindRed]
 measure=Calc
 formula=....some formula that can extract the "152" out of #rootcolor#...

[findgreen]
 ... same ...

[findblue]
 ... same ...

[downred]
 measure=Calc
 formula=([findred] * #modificationfactor#)

etc.....
The reason for splitting the color up in it's three basics is that perhaps I might want to modify the red in another way than the green and blue. That is yet to find out.

And also because just multiplying ((#rootcolor#)*(#factor#)) returns weird results, being mostly black, but not always.

I'm currently stuck with observing the string output of my colors to notice any patterns in the behavior.

Any useful hint to get me away from splitting my colors up would be greatly appreciated!
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5411
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Modifying Color values with functions

Post by eclectic-tech »

You are free to dig through my code for my Changeling skin... the color measures I created are in the @Resources\Measures\ColorMeasures.inc file.

It is definitely not resource friendly, but I generate colors based on CPU, RAM, and NETIN/OUT measures and also utilize several counters to drive red, blue, and green values for cycling graphic color effects.

EDIT: You might want to also look at this post by JSMorley
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Modifying Color values with functions

Post by MerlinTheRed »

If you want to create harmonizing colors from a base color, I would recommend you don't work in the rgb color space but convert your base color to hsv, make the changes there, and then convert them back to rgb. You can do this in a Lua script, which will also make setting some variables to the color values rather trivial. Converting rgb to hsv and back can be a little complicated math-wise but I'm sure there are guides for in all over the internet.

In hsv, you have the hue, saturation and value of the color represented as 3 distinct numbers, so if you want to make a color darker, just change one of the three instead of all of them. If you want to remove saturation, that's equally simple. Changing the hue itself I wouldn't even try to do in rgb cause I'm pretty sure you won't find an easy solution for moving the hue around the color circle if you have a rgb representation.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
Eastwood
Posts: 35
Joined: November 1st, 2012, 10:50 pm

Re: Modifying Color values with functions

Post by Eastwood »

MerlinTheRed wrote:If you want to create harmonizing colors from a base color, I would recommend you don't work in the rgb color space but convert your base color to hsv, make the changes there, and then convert them back to rgb. You can do this in a Lua script, which will also make setting some variables to the color values rather trivial. Converting rgb to hsv and back can be a little complicated math-wise but I'm sure there are guides for in all over the internet.

In hsv, you have the hue, saturation and value of the color represented as 3 distinct numbers, so if you want to make a color darker, just change one of the three instead of all of them. If you want to remove saturation, that's equally simple. Changing the hue itself I wouldn't even try to do in rgb cause I'm pretty sure you won't find an easy solution for moving the hue around the color circle if you have a rgb representation.
That's a very useful clue Merlin!
I already found that rgb_to_hsl() and hsl_to_rgb() are supported functions in Lua.
This means I should Convert to hsv -> Modify and generate variants -> Convert each variant back to RGB.

Unfortunately my understanding in the syntax of Lua is very poor, so it will be a struggle to get it all arranged.

I also took a peek inside Eclectic's code. Nice suite, but where exactly did you split up a certain color in it's R,G and B values? I found the Changeling\@Resources\Measures\ColorMeasures.inc , but can't really seem to find useful hints for my code.
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Modifying Color values with functions

Post by MerlinTheRed »

I don't think you can really split up a color of a variable into its separate parts without using lua. What you could do is set the r, g and b value to separate variables in the first place and then construct all the colors from these three (including the original one).
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Modifying Color values with functions

Post by smurfier »

Code: Select all

[FindRed]
 measure=Time
 Format=#rootcolor#
 RegExpSubstitute=1
 Substitute="([^,]*),.*":"\1"

[findgreen]
 measure=Time
 Format=#rootcolor#
 RegExpSubstitute=1
 Substitute="[^,]*,([^,]*),.*":"\1"

[findblue]
 measure=Time
 Format=#rootcolor#
 RegExpSubstitute=1
 Substitute="[^,]*,[^,]*,([^,]*).*":"\1"
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Modifying Color values with functions

Post by MerlinTheRed »

what a nasty little hack ;)
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
jsmorley
Developer
Posts: 22633
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Modifying Color values with functions

Post by jsmorley »

MerlinTheRed wrote:what a nasty little hack ;)
Dirty little secret... The Time measure makes a nice tool for messing with strings like this. You only have to be careful that your string doesn't actually contain any valid time codes like "%H" and such.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: Modifying Color values with functions

Post by moshi »

add support for colors with alpha value and hex colors:

Code: Select all

[FindRed]
 measure=Time
 Format=#rootcolor#
 RegExpSubstitute=1
 Substitute="^(.*),(.*),(.*),.*$":"\1,\2,\3","^(.*),.*,.*$":"\1"," ":"","^(..)(..)(..)..$":"\1\2\3","^(..)....$":"\1"

[findgreen]
 measure=Time
 Format=#rootcolor#
 RegExpSubstitute=1
 Substitute="^(.*),(.*),(.*),.*$":"\1,\2,\3","^.*,(.*),.*$":"\1"," ":"","^(..)(..)(..)..$":"\1\2\3","^..(..)..$":"\1"

[findblue]
 measure=Time
 Format=#rootcolor#
 RegExpSubstitute=1
 Substitute="^(.*),(.*),(.*),.*$":"\1,\2,\3","^.*,.*,(.*)$":"\1"," ":"","^(..)(..)(..)..$":"\1\2\3","^....(..)$":"\1"
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Modifying Color values with functions

Post by Kaelri »

Freaks.