So I'm trying to create a smooth transition between Color3
values, in a rainbow-like effect. I've come up this conclusion:
local function TweenColor(gui,new,prop,time) local v = gui[prop] time = time * 30 local saved = { r=new.r-v.r; g=new.g-v.g; b=new.b-v.b; } for i = 1,time do gui[prop] = Color3.new( gui[prop].r+saved.r/time, gui[prop].g+saved.g/time, gui[prop].b+saved.b/time ) wait() end end
This will tween color A, to color B very smoothly. However, I still have yet to figure out a compact way to make a rainbow effect
and have the function tween through all it's colors
.
If anyone knows a good way to accomplish this, I'd very much appreciate it. Thanks.
ProfessorSev's comment isn't far off. For the effect you're looking for, you could cycle the hue value and convert to RGB, as follows:
local hue = 0; -- this will cycle from 0-359 local SAT = 1; -- satutation; constant local LUM = 1; -- luminance; constant local SPEED = 1; -- hue degree/frame function hsvToRgb(h, s, v) -- from https://github.com/EmmanuelOga/columns/blob/master/utils/color.lua - essentially ramps different values depending on which sixth 'h' is in local r, g, b local i = math.floor(h * 6); local f = h * 6 - i; local p = v * (1 - s); local q = v * (1 - f * s); local t = v * (1 - (1 - f) * s); i = i % 6 if i == 0 then r, g, b = v, t, p elseif i == 1 then r, g, b = q, v, p elseif i == 2 then r, g, b = p, v, t elseif i == 3 then r, g, b = p, q, v elseif i == 4 then r, g, b = t, p, v elseif i == 5 then r, g, b = v, p, q end return r, g, b end -- the rainbow effect: while (true) do color = hsvToRgb(hue/360, SAT, LUM); hue = (hue+SPEED)%360; wait() end
That could be severely simplified, but the main loop is basically the logic.