It is currently April 28th, 2024, 8:56 am

fading trough 3 colors... how to do it?

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16183
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: fading trough 3 colors... how to do it?

Post by balala »

brax64 wrote: August 7th, 2020, 11:08 am nothing is useless, really appreciate your effort trying to help!
Agree: nothing is useless, a new approach of the same question is always welcomed.
User avatar
Yincognito
Rainmeter Sage
Posts: 7179
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: fading trough 3 colors... how to do it?

Post by Yincognito »

Brax64, you had nice words for everyone, but I felt balala's version was spot on. However, like in every case I'm involved in I always look for a solution that can work whatever the parameters are. In other words, a transition / code similar to what we all already posted, but that can work irrespective of the number of colors one makes the transition through (2, 3, whatever). Mak_kawa did something there that can be useful in such a case, with his Position variable, but I'm looking at more. I'd like everything to work just from the formulas, no IfConditions involved.

Any ideas? :sly:

EDIT: For example, in balala's code: (#R2#+((#Range#-50)/50)*(#R3#-#R2#)), it is clear that /50 actually means /(<RangeMax>/(<numberofcolors>-1)), that the R, G, B indexes are consecutive based on the <Range> value and how it related to <RangeMax>, and that -50 is also a subtraction of a value based on <Range>/<RangeMax> (or on the current color index, if you like). What I'm looking for is putting these considerations into a formula instead of into IfConditions. Up for the challenge? :D
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: fading trough 3 colors... how to do it?

Post by brax64 »

Yincognito wrote: August 7th, 2020, 11:43 am Brax64, you had nice words for everyone, but I felt balala's version was spot on. However, like in every case I'm involved in I always look for a solution that can work whatever the parameters are. In other words, a transition / code similar to what we all already posted, but that can work irrespective of the number of colors one makes the transition through (2, 3, whatever). Mak_kawa did something there that can be useful in such a case, with his Position variable, but I'm looking at more. I'd like everything to work just from the formulas, no IfConditions involved.

Any ideas? :sly:

EDIT: For example, in balala's code: (#R2#+((#Range#-50)/50)*(#R3#-#R2#)), it is clear that /50 actually means /(<RangeMax>/(<numberofcolors>-1)), that the R, G, B indexes are consecutive based on the <Range> value and how it related to <RangeMax>, and that -50 is also a subtraction of a value based on <Range>/<RangeMax> (or on the current color index, if you like). What I'm looking for is putting these considerations into a formula instead of into IfConditions. Up for the challenge? :D
Let see if I've understood your question first...
You want to end up with a formula that, for any given value of Range, calculate the "n" values for the "n" R (or G or B...) components, where "n" is the number of colors or "triplet" of components if you will.
Am I right?
User avatar
Yincognito
Rainmeter Sage
Posts: 7179
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: fading trough 3 colors... how to do it?

Post by Yincognito »

brax64 wrote: August 7th, 2020, 12:26 pm Let see if I've understood your question first...
You want to end up with a formula that, for any given value of Range, calculate the "n" values for the "n" R (or G or B...) components, where "n" is the number of colors or "triplet" of components if you will.
Am I right?
I want to end up with a formula that calculates the #R#, #G#, #B# values for any given value of Range (currently from 0 to 100), Range maximum (currently 100), AND number of colors (currently 3). In other words, I want to make the transition correctly whatever the values of those 3 variables above may be (e.g. if the Range goes from 0 to 200 or if I add/remove colors that the transition goes through).

Wouldn't be nice to have the meter transition through, say, 5 colors, just by adding the colors in the [Variables] section (and without modifying the code - like modifying the IfConditions in balala's implementation - each time a color is added or removed)? :D
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: fading trough 3 colors... how to do it?

Post by brax64 »

Yincognito wrote: August 7th, 2020, 12:37 pm I want to end up with a formula that calculates the #R#, #G#, #B# values for any given value of Range (currently from 0 to 100), Range maximum (currently 100), AND number of colors (currently 3). In other words, I want to make the transition correctly whatever the values of those 3 variables above may be (e.g. if the Range goes from 0 to 200 or if I add/remove colors that the transition goes through).

Wouldn't be nice to have the meter transition through, say, 5 colors, just by adding the colors in the [Variables] section (and without modifying the code - like modifying the IfConditions in balala's implementation - each time a color is added or removed)? :D
Yep I think I gotcha... I totally agree if we came up with something like that, my only problem is I'm not sure if my math skill is still up to the task :D
I graduate 40 years ago and, even tho is difficult to admit..., my brain is not so "fresh" anymore :oops:
But I'll try anyway , it's an interesting challenge nevertheless :)
User avatar
Yincognito
Rainmeter Sage
Posts: 7179
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: fading trough 3 colors... how to do it?

Post by Yincognito »

brax64 wrote: August 7th, 2020, 12:58 pm Yep I think I gotcha... I totally agree if we came up with something like that, my only problem is I'm not sure if my math skill is still up to the task :D
I graduate 40 years ago and, even tho is difficult to admit..., my brain is not so "fresh" anymore :oops:
But I'll try anyway , it's an interesting challenge nevertheless :)
Yeah, I came up with something (only one additional measure involved, and that's only because Rainmeter can't update variables in the same bang and must first calculate a value before it can be used along a variable or measure in the nested form, aka an "index"), but while it does transition, it doesn't do it between the right colors - must be something that I missed in the process...

EDIT: Ah, yes. Forgot to modify the R to B after pasting, LOL. It now works, but it goes black at "Range"=100 because of the formula. Probably a matter of subtracting 1 from it.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7179
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: fading trough 3 colors... how to do it?

Post by Yincognito »

brax64 wrote: August 7th, 2020, 12:58 pm Yep I think I gotcha... I totally agree if we came up with something like that, my only problem is I'm not sure if my math skill is still up to the task :D
I graduate 40 years ago and, even tho is difficult to admit..., my brain is not so "fresh" anymore :oops:
But I'll try anyway , it's an interesting challenge nevertheless :)
No need to anymore. Here is the code - everything is controlled through the variables in the [Variables] section, no editing of the skin code is required if one adds or removes colors or changes the range (the former Range variable is now known as Value, and the Range in my code is just the max Value), other than adding or removing the colors themselves (you can actually skip removing, just lower the IdMax accordingly):

Code: Select all

[Variables]
; Color 0
R0=255
G0=0
B0=0
A0=255
; Color 1
R1=0
G1=255
B1=0
A1=255
; Color 2
R2=0
G2=0
B2=255
A2=255
; Color 3
R3=255
G3=0
B3=255
A3=255
; Color 4
R4=0
G4=255
B4=255
A4=255
; The maximum of Value
Range=100
; A variable that ranges from 0 to Range
Value=0
; The maximum index of the colors used in the transition
IdMax=4

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

[Value]
Group=ColorGroup
Measure=Calc
Formula=#Value#
;Formula=((Value%#Range#)+1)
OnUpdateAction=[!SetVariable Interval (([#Range]+1)/[#IdMax])][!SetVariable SIndex (Trunc([Value]/(([#Range]+1)/[#IdMax])))][!SetVariable EIndex (Trunc([Value]/(([#Range]+1)/[#IdMax]))+1)]
DynamicVariables=1

[Color]
Group=ColorGroup
Measure=Calc
OnUpdateAction=[!SetVariable R ([#R[#SIndex]]+(([Value]-[#SIndex]*[#Interval])/[#Interval])*([#R[#EIndex]]-[#R[#SIndex]]))][!SetVariable G ([#G[#SIndex]]+(([Value]-[#SIndex]*[#Interval])/[#Interval])*([#G[#EIndex]]-[#G[#SIndex]]))][!SetVariable B ([#B[#SIndex]]+(([Value]-[#SIndex]*[#Interval])/[#Interval])*([#B[#EIndex]]-[#B[#SIndex]]))][!SetVariable A "255"][!UpdateMeter "Image"][!Redraw]
DynamicVariables=1

---Meters---

[Image]
Meter=Image
SolidColor=#R#,#G#,#B#,#A#
X=0
Y=0
W=100
H=50
DynamicVariables=1
MouseScrollDownAction=[!SetVariable Value "(Clamp((#Value#-1),0,#Range#))"][!UpdateMeasureGroup ColorGroup][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
MouseScrollUpAction=[!SetVariable Value "(Clamp((#Value#+1),0,#Range#))"][!UpdateMeasureGroup ColorGroup][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
If you comment the current Update and Formula lines in the [Rainmeter] section and the [Value] measure and uncomment the following lines, you'll have a nice transition animation. With the proper RGB color values and number of colors (and setting the first color to be the same as the last one), the Color Wheel can be replicated easily. I'm starting to think this approach is better than my "old" regex based Color Wheel, since it allows far more flexibility in choosing the colors.

P.S. Credit to balala for his code - I started based on that, since it was more compact than mine (not to mention doing the 3 color transition instead of my rushed post which did it only for 2). :thumbup:

EDIT: Corrected a small inconsistency due to the specific order of measures in the code.
Last edited by Yincognito on August 7th, 2020, 3:06 pm, edited 1 time in total.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: fading trough 3 colors... how to do it?

Post by brax64 »

Yincognito wrote: August 7th, 2020, 2:33 pm No need to anymore. Here is the code - everything is controlled through the variables in the [Variables] section, no editing of the skin code is required if one adds or removes colors or changes the range (the former Range variable is now known as Value, and the Range in my code is just the max Value), other than adding or removing the colors themselves (you can actually skip removing, just lower the IdMax accordingly):

If you comment the current Update and Formula lines in the [Rainmeter] section and the [Value] measure and uncomment the following lines, you'll have a nice transition animation. With the proper RGB color values and number of colors (and setting the first color to be the same as the last one), the Color Wheel can be replicated easily. I'm starting to think this approach is better than my "old" regex based Color Wheel, since it allows far more flexibility in choosing the colors.

P.S. Credit to balala for his code - I started based on that, since it was more compact than mine (not to mention doing the 3 color transition instead of my rushed post which did it only for 2). :thumbup:
Well, I'm speechless... :jawdrop you brought me well behind I was hoping to go with this thread!
your coding and math skills are off the chart...
Thank you very much for your time and efforts!
User avatar
Yincognito
Rainmeter Sage
Posts: 7179
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: fading trough 3 colors... how to do it?

Post by Yincognito »

brax64 wrote: August 7th, 2020, 3:01 pm Well, I'm speechless... :jawdrop you brought me well behind I was hoping to go with this thread!
your coding and math skills are off the chart...
Thank you very much for your time and efforts!
No worries, I like challenges. :D Also, be sure to check the updated code, as I corrected an inconsistency by changing a bit the order of measures (in the previous code, I referred to the following measure from the previous one, which produced a one update delay in updating the color properly when setting a hardcoded value in the [Value]'s Formula option - now it should be fine).

Regarding my math skills, my high school teacher was of a very different opinion, LMAO - but she was an idiot anyway, hahaha!
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: fading trough 3 colors... how to do it?

Post by brax64 »

Yincognito wrote: August 7th, 2020, 3:10 pm No worries, I like challenges. :D Also, be sure to check the updated code, as I corrected an inconsistency by changing a bit the order of measures (in the previous code, I referred to the following measure from the previous one, which produced a one update delay in updating the color properly when setting a hardcoded value in the [Value]'s Formula option - now it should be fine).

Regarding my math skills, my high school teacher was of a very different opinion, LMAO - but she was an idiot anyway, hahaha!
there is a detail that I don't understand, you write a lot of expression like this (([#Range]+1)/[#IdMax]), where is missing the character "#" at the end of the variable name.
The skin is running without errors or warnings so it seems that is not a problem, so does it means that the end # is not needed or in this case is a kind of "operator"?