It is currently March 28th, 2024, 3:53 pm

Complementary color

Tips and Tricks from the Rainmeter Community
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Complementary color

Post by mak_kawa »

Now I know how to make "complementary color" for given RGB color. Calculation method of the complementary color is as follows. This method is said to be after "Adobe Illustrator", but exact source is unknown for me.

1. Max(RGB) = Maxmimum value among original R, G, B
2. Min(RGB) = Minimum value among original R, G, B
3. compR = (Max(RGB) + Min(RGB)) - originalR
4. compG = (Max(RGB) + Min(RGB)) - originalG
5. compB = (Max(RGB) + Min(RGB)) - originalB
6. complementary color = compR, compG, compB

For example, complementary color for (50, 100, 200) is (200+50-50, 200+50-100, 200+50-200) = (200, 150, 50).

Sample code is:

Code: Select all

[Rainmeter]
Update=5000

[GenerateColorR]
Measure=Calc
Formula=Random
UpdateRandom=1
Lowbound=0
HighBound=255

[GenerateColorG]
Measure=Calc
Formula=Random
UpdateRandom=1
Lowbound=0
HighBound=255

[GenerateColorB]
Measure=Calc
Formula=Random
UpdateRandom=1
Lowbound=0
HighBound=255

[GenerateColorRGB]
Measure=String
String="[GenerateColorR],[GenerateColorG],[GenerateColorB]"
DynamicVariables=1

[GenerateColorMaxRGB]
Measure=Calc
Formula=Max(Max([GenerateColorR],[GenerateColorG]),[GenerateColorB])
DynamicVariables=1

[GenerateColorMinRGB]
Measure=Calc
Formula=Min(Min([GenerateColorR],[GenerateColorG]),[GenerateColorB])
DynamicVariables=1

[ComplColorR]
Measure=Calc
Formula=([GenerateColorMaxRGB]+[GenerateColorMinRGB]) - [GenerateColorR]
DynamicVariables=1

[ComplColorG]
Measure=Calc
Formula=([GenerateColorMaxRGB]+[GenerateColorMinRGB]) - [GenerateColorG]
DynamicVariables=1

[ComplColorB]
Measure=Calc
Formula=([GenerateColorMaxRGB]+[GenerateColorMinRGB]) - [GenerateColorB]
DynamicVariables=1

[ComplColorRGB]
Measure=String
String="[ComplColorR],[ComplColorG],[ComplColorB]"
DynamicVariables=1

[SquareOriginal]
Meter=Shape
Shape=Rectangle 0,0,75,100,5 | Fill Color [GenerateColorRGB]
DynamicVariables=1

[SquareCompl]
Meter=Shape
Shape=Rectangle 80,0,75,100,5 | Fill Color [ComplColorRGB]
DynamicVariables=1
If color code is provided as R,G,B expression, RegExpSubstitute "^(.*),(.*),(.*)$":"\1" may help to get separate R, G, and B values.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Complementary color

Post by balala »

Two questions:
  • Do you have any question about this?
  • Where the complementary colors are used?
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Complementary color

Post by mak_kawa »

Hi balala

Q1: Ah...no. I have no question about this matter. If this forum is a Q&A forum, sorry for this post.

Q2: Left rectangle has fill color of randomly generated RGB. And right one has complementary fill color for the left one.

I am afraid that I am really a turkey...
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Complementary color

Post by balala »

mak_kawa wrote:Q1: Ah...no. I have no question about this matter. If this forum is a Q&A forum, sorry for this post.
Don't apologize at all. I just thought maybe there is any question.
mak_kawa wrote:Q2: Left rectangle has fill color of randomly generated RGB. And right one has complementary fill color for the left one.
Right, I understood this. Question is where a complementary color is used in practice? What's its meaning?
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Complementary color

Post by mak_kawa »

Hi balala

I misunderstood your latter question. The answer is... ah, it is a very long story for my English writing skill. :-)

I use the complementary color in my clock skin.

This skin includes many clockface images with various colors/tints. The images are randomly changed. The problem is that what color of clock hands I should specify? When a clockface image is dark-colored, it is better that the color of hands is light-colored for its visibility. In the beginning of making the clock skin, I prapared and adjusted the color of hands manually, and change them with IfCondition sentences. But it is really bothersome as the number of clockface images increase.

So, I have decided to use Chameleon plugin to get automatically "fore/background" colors compared to the average(?) color of the clockface image. But sometimes it does not provide enough visibility of clock hands. Therefore, I made complementary color for the fore/background colors. Also I made "counter color" (= 255 - R,G,B) for them. These colors for clock hands are changed by mouse click of the clockface so as to be well-visible.
Image2.jpg
Now I am thinking that I am struggling with useless objective...:-) But I think that the method of calculating complementary color may be usefull for some one with some purpose in Rainmeter skin making, I hope. This is the reason of my post.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Complementary color

Post by jsmorley »

balala wrote: Right, I understood this. Question is where a complementary color is used in practice? What's its meaning?
https://en.wikipedia.org/wiki/Complementary_colors

The blue and the orange in our logo here in the forums are complimentary colors.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Complementary color

Post by balala »

jsmorley wrote:https://en.wikipedia.org/wiki/Complementary_colors

The blue and the orange in our logo here in the forums are complimentary colors.
I see now. The purpose is a better visibility, given by the contrast of those two colors.
Good point...
mak_kawa wrote:Now I know how to make "complementary color" for given RGB color. Calculation method of the complementary color is as follows. This method is said to be after "Adobe Illustrator", but exact source is unknown for me.
I have one more remark about the initial code mak_kawa: the posted Calc measures (Eg [GenerateColorMaxRGB] or [ComplColorR]) don't require to use dynamic variables. In the Formula options of those measures you don't have to include the names of the measures into brackets and consequently, you don't have to add the DynamicVariables=1 option. Eg you can remove the brackets into the posted formula of [GenerateColorMaxRGB] measure (initially it was Formula=Max(Max([color=#FF0000][[/color]GenerateColorR[color=#FF0000]][/color], [color=#FF0000][[/color]GenerateColorG[color=#FF0000]][/color]),[color=#FF0000][[/color]GenerateColorB[color=#FF0000]][/color])), getting this: Formula=Max(Max(GenerateColorR,GenerateColorG),GenerateColorB). If you remove them, you also can remove the DynamicVariables=1 option of the same measure.
Obviously you can do the same changes on all those Calc measures ([GenerateColorMaxRGB], [GenerateColorMinRGB], [ComplColorR], [ComplColorG] and [ComplColorB]). None of them need using the dynamic variables.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Complementary color

Post by mak_kawa »

Hi balala

Thank you for detailed guidance about brackets around section variables. :)
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Complementary color

Post by jsmorley »

There are two places where you don't have to, and probably don't want to, use [brackets] around measures names.

What they have in common is that they are places where the ONLY string allowed is a measure name, where it is unambiguous that what you mean is the value of a measure.

1) In the Formula option of a Calc measure. No non-numeric value can ever be used in Formula, so it is safe for Rainmeter to assume that any text is a measure name.

2) In the test of an IfCondtion. Again, IfConditions are strictly numeric, so any text is assumed to be a measure name.

In addition to saving a couple of characters in your code, there are other good reasons not to use [brackets] in these cases.

If you use a measure name as a [SectionVariable], with the [brackets] you must use DynamicVariables=1 on the measure or meter where you use it.

When used without the [brackets] in Formula or IfCondition, the actual "number value" of the measure is retrieved. When a [SectionVariable] is used, it will use the "string value" of the measure. This doesn't matter in many, even most cases, as the number and string values will be the same, but there are times when a measure will return different number and string values. In that case, you would use [MeasureName] to get the string value, and [MeasureName:] to get the number value.

Note that in 1) above, this is specifically the Formula option in a Calc measure, not to be confused with "formulas" in general. If you use a formula like X=(SomeMeasure * 2), that is an error. It must be X=([SomeMeasure] * 2)and must be used with DynamicVariables=1.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Complementary color

Post by balala »

mak_kawa wrote:Thank you for detailed guidance about brackets around section variables. :)
You're welcome. But be sure you've read jsmorley's above detailed description about this question. He explains well why and where the brackets must be used.
Post Reply