Making a color flow between, blue, yellow, green...
4 replies, posted
I wanted to try a cool effect, and I've tried different ways to make it happen, but they all just seems to fail.
I am basically trying to make a player's player model change it's color all the time. Like flowing from blue, to green, to yellow and son on... nicely. One of the ways i tried was to make a curtime() that counted on the different colors, but I didn't really make it work...
Any ideas on how I could do this?
Well since the color is split into Red, Green and Blue, with each being a value from 0 to 255, you could cycle through them like this:
[lua]function GetRainbowColour( num )
local i = num % 256 // the always a number from 0 to 255
local h = math.floor( num / 256 ) % 6 // always between 0 and 5
local r = 0
local g = 0
local b = 0
if h == 0 then
r = 255
g = i
b = 0
elseif h == 1 then
r = 255 - i
g = 255
b = 0
elseif h == 2 then
r = 0
g = 255
b = i
elseif h == 3 then
r = 0
g = 255 - i
b = 255
elseif h == 4 then
r = i
g = 0
b = 255
else
r = 255
g = 0
b = 255 - i
end
return Color( r, g, b, 255 )
end[/lua]
Thanks
This one doesn't require you to give it anything. I'm not entirely sure what he's doing in his.
[lua]--[[
~ Rainbow Maker ~
~ Lexi ~
--]]
local r,g,b,m = 255,0,0,1
local i = 5
hook.Add("Think", "Rainbow Maker", function()
if m == 1 then
g = g + i
if g == 255 then m = 2 end
elseif m == 2 then
r = r - i
if r == 0 then m = 3 end
elseif m == 3 then
b = b + i
if b == 255 then m = 4 end
elseif m == 4 then
g = g - i
if g == 0 then m = 5 end
elseif m == 5 then
r = r + i
if r == 255 then m = 6 end
elseif m == 6 then
b = b - i
if b == 0 then m = 1 end
end
end)
function GetRainbow()
return r,g,b
end
hook.Add("HUDPaint", "Rainbow Test", function()
local x,y,z = GetRainbow()
surface.SetDrawColor(x,y,z,255)
print(x,y,z)
surface.DrawRect(ScrW()/4,ScrW()/4,ScrW()/2,ScrH()/2)
end)
[/lua]
-snip-
Sorry, you need to Log In to post a reply to this thread.