It is currently October 21st, 2021, 6:16 am

ColorSpectrum

Discuss the use of Lua in Script measures.
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

ColorSpectrum

Post by AlC »

Hey Guys,

I wrote the last days a little Lua script for me and maybe someone will find it useful.

INI

Code: Select all

[mColorSpectrum]
 Measure=Script
 ScriptFile=#@#Lua\ColorSpectrum.lua
 Red=0
 Green=255
 Blue=0
 Range=10
 Direction=1
LUA

Code: Select all

function Initialize()
-- ColorSpectrum v1.1
	Rorg = SELF:GetNumberOption('Red')
	Gorg = SELF:GetNumberOption('Green')
	Borg = SELF:GetNumberOption('Blue')

	R = SELF:GetNumberOption('Red')
	G = SELF:GetNumberOption('Green')
	B = SELF:GetNumberOption('Blue')
	Range = SELF:GetNumberOption('Range', 1)
	Direction = SELF:GetNumberOption('Direction', 1)
	c = 0

	if R<=G and R<=B then Low=R -- set Low
		elseif G<=R and G<=B then Low=G
		elseif B<=R and B<=G then Low=B
	end

	if R>=G and R>=B then High=R -- set High
		elseif G>=R and G>=B then High=G
		elseif B>=R and B>=G then High=B
	end
end

function Update()
	c = c+Range

	if Direction == 0 then -- 360 -> 0
			if R==High and G==Low and B<High then B=Borg+c Rorg=High					
				elseif R>Low and G==Low and B==High then R=Rorg-c Gorg=Low
				elseif R==Low and G<High and B==High then G=Gorg+c Borg=High	 			
				elseif R==Low and G==High and B>Low then B=Borg-c Rorg=Low		
				elseif R<High and G==High and B==Low then R=Rorg+c Gorg=High		
				elseif R==High and G>Low and B==Low then G=Gorg-c Borg=Low		
				else print('ColorSpectrum: StartColor is white/grey/black.')
		 	end
		elseif Direction == 1 then -- 0 -> 360
			if R==High and G<High and B==Low then G=Gorg+c Rorg=High
				elseif R>Low and G==High and B==Low then R=Rorg-c Borg=Low
				elseif R==Low and G==High and B<High then B=Borg+c Gorg=High
				elseif R==Low and G>Low and B==High then G=Gorg-c Rorg=Low
				elseif R<High and G==Low and B==High then R=Rorg+c Borg=High
				elseif R==High and G==Low and B>Low then B=Borg-c Gorg=Low
				else print('ColorSpectrum: StartColor is white/grey/black.')
		 	end
	end

	if 	R>High then R=High -- prevent the value to become lower/higher than Low/High
		elseif G>High then G=High
		elseif B>High then B=High
		elseif R<Low then R=Low
		elseif G<Low then G=Low
		elseif B<Low then B=Low
	end

	if R==High and G==Low and B==Low then c=0 -- reset Counter
		elseif R==High and G==Low and B==High then c=0
		elseif R==Low and G==Low and B==High then c=0
		elseif R==Low and G==High and B==High then c=0
		elseif R==Low and G==High and B==Low then c=0
		elseif R==High and G==High and B==Low then c=0
	end
	
	SKIN:Bang('!SetVariable', 'Red', R)
	SKIN:Bang('!SetVariable', 'Green', G)
	SKIN:Bang('!SetVariable', 'Blue', B)
	SKIN:Bang('!SetVariable', 'RGB', R..','..G..','..B)

end
At the script section you can set the startcolor with Red=,Green= and Blue=. From this color the script begins to change the hue of the startcolor. Also you can set the hue change "Direction" (1 is hue change 0->360 /// 0 is hue change 360->0)

And with "Range" you can set the change per script update (If no Range is set, then Range is 1)

The script creates the following Variables:

- Red (The red value of the color)
- Green (The green value of the color)
- Blue (The blue value of the color)
- RGB (The complete color)

Example:
We set the startcolor 29,156,183 and Range=15
The next colors will be ..
29,171,183
29,183,183
29,183,168
Example Skin:
[Rainmeter]
Update=500

[mColorSpectrum]
Measure=Script
ScriptFile=#@#Lua\ColorSpectrum.lua
Red=40
Green=159
Blue=5
Range=5
Direction=1

[Image]
Meter=Image
SolidColor=#Red#,#Green#,#Blue#
;SolidColor=#RGB#
W=100
H=100
DynamicVariables=1

[String]
Meter=String
Y=R
Text="#Red# #Green# #Blue#"
DynamicVariables=1
Script in Action: ChangeLog:
1.1 Added hue change direction
1.0 Script release
Last edited by AlC on September 8th, 2013, 6:41 pm, edited 4 times in total.
Rainmeter - You are only limited by your imagination and creativity.
poiru
Developer
Posts: 2871
Joined: April 17th, 2009, 12:18 pm

Re: ColorSpectrum

Post by poiru »

The following will not work if the config contains spaces.
SKIN:Bang('!SetVariable Red '..R..' #CURRENTCONFIG#')

You should use this:
SKIN:Bang('!SetVariable', 'Red', R, '#CURRENTCONFIG#')

Or simply this:
SKIN:Bang('!SetVariable', 'Red', R)
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: ColorSpectrum

Post by AlC »

Ahh thanks poiru!

Short question: Is there an easier way to do this ?
SKIN:Bang('!SetVariable', 'RGB', R..','..G..','..B)
Rainmeter - You are only limited by your imagination and creativity.
User avatar
iNjUST
Posts: 117
Joined: June 20th, 2012, 12:44 am

Re: ColorSpectrum

Post by iNjUST »

I created something similar with a non-Lua Rainmeter code, based on HSV color rotation instead of raw manipulation of each RGB value.

http://rainmeter.net/forum/viewtopic.php?f=15&t=16055
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: ColorSpectrum

Post by AlC »

iNjUST wrote:I created something similar with a non-Lua Rainmeter code, based on HSV color rotation instead of raw manipulation of each RGB value.
Yep, I knew your code, but it seemed a little bit complicated ;)

I Updated the first post to v1.1, you can now edit the hue change direction.
Rainmeter - You are only limited by your imagination and creativity.