So I'm trying to create a smooth transition between Color3
values, in a rainbow-like effect. I've come up this conclusion:
01 | local function TweenColor(gui,new,prop,time) |
02 | local v = gui [ prop ] |
03 | time = time * 30 |
04 | local saved = { |
05 | r = new.r-v.r; |
06 | g = new.g-v.g; |
07 | b = new.b-v.b; |
08 | } |
09 | for i = 1 ,time do |
10 | gui [ prop ] = Color 3. new( |
11 | gui [ prop ] .r+saved.r/time, |
12 | gui [ prop ] .g+saved.g/time, |
13 | gui [ prop ] .b+saved.b/time |
14 | ) |
15 | wait() |
16 | end |
17 | 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:
01 | local hue = 0 ; -- this will cycle from 0-359 |
02 | local SAT = 1 ; -- satutation; constant |
03 | local LUM = 1 ; -- luminance; constant |
04 |
05 | local SPEED = 1 ; -- hue degree/frame |
06 |
07 | 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 |
08 | local r, g, b |
09 |
10 | local i = math.floor(h * 6 ); |
11 | local f = h * 6 - i; |
12 | local p = v * ( 1 - s); |
13 | local q = v * ( 1 - f * s); |
14 | local t = v * ( 1 - ( 1 - f) * s); |
15 |
That could be severely simplified, but the main loop is basically the logic.