Hello, I'm trying to make "rainbow" text with 3D2D with DrawTranslucent, what i'm trying to do is for r, g, and b, I want to make a "rainbowish" effect, for example
[code]
r = math.Clamp(r + 1, 0, 255) -- But if r gets to 255, it'll stay there, I want it so when it gets to 255, it will start subtracting, ex
r = math.Clamp(r - 1, 0, 255) -- Does same as above but oppsite :l
[/code]
How would I do this?
In your particular situation I'd recommend [b][url=http://wiki.garrysmod.com/page/Global/HSVToColor]HSVToColor[/url][/b].
You'll want a saturation and value of 1, and a hue that varies between 0 and 360 degrees (it's an angle).
A hue around 0° or 360° gives a red color, as you increase it, it will turn green at 120°, and then to blue at 240° before looping back to red at 360°. So if you want a full rainbow, you simply need a hue that constantly increases and goes back to 0 whenever it goes over 360.
This might come in handy:
[img]http://dba.med.sc.edu/price/irf/Adobe_tg/models/images/hsl_top.JPG[/img]
That's very useful, but what I mean was, for example, I have a value that's for the frac of the lerp (first argument in lerp), and I have the start set to 0 and end set to 255, which will work for color, I want the value to decrease every frame until it's zero then when it's zero, increase all the way to 255, then decrease back to 0, keeps going on and on, kind of like a breathing effect.
Do you mean you want to go ROYGBV->VBGYOR instead of ROYGBV->ROYGBV?
[editline]8th December 2013[/editline]
in either case you need HSVToColor
[QUOTE=sackcreator54;43116619]That's very useful, but what I mean was, for example, I have a value that's for the frac of the lerp (first argument in lerp), and I have the start set to 0 and end set to 255, which will work for color, I want the value to decrease every frame until it's zero then when it's zero, increase all the way to 255, then decrease back to 0, keeps going on and on, kind of like a breathing effect.[/QUOTE]
Say HSV would be an ideal solution for a proper rainbow, but if you just want your colours to pulse, this will get you started.
[lua]local RedVal = math.random(1,254) --Start at a random value
local GreenVal = math.random(1,254)
local BlueVal = math.random(1,254)
local RedDir = tobool(math.random(0,1)) and 1 or -1 --1 for increasing, -1 for decreasing
local GreenDir = tobool(math.random(0,1)) and 1 or -1
local BlueDir = tobool(math.random(0,1)) and 1 or -1
local ColorSpeed = 5 --how much each color changes per step
local function StepColor() --call StepColor to change the color
RedVal = RedVal + RedDir * ColorSpeed
GreenVal = GreenVal + GreenDir * ColorSpeed
BlueVal = BlueVal + BlueDir * ColorSpeed
if RedVal<0 then --if red reaches 0
RedVal=0
RedDir=1 --start increasing
elseif RedVal>255 then --if red reaches 255
RedVal=255
RedDir=-1 --start decreasing
end
if GreenVal<0 then
GreenVal=0
GreenDir=1
elseif GreenVal>255 then
GreenVal=255
GreenDir=-1
end
if BlueVal<0 then
BlueVal=0
BlueDir=1
elseif BlueVal>255 then
BlueVal=255
BlueDir=-1
end
end
local GetColor() --call GetColor to get the color
return Color(RedVal,GreenVal,BlueVal)
end[/lua]
Essentially you keep track of which direction the colour is progressing in and when it reaches the min/max, change direction.
Sorry, you need to Log In to post a reply to this thread.