Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Tweening Color3 values in sequence?

Asked by 9 years ago

So I'm trying to create a smooth transition between Color3 values, in a rainbow-like effect. I've come up this conclusion:

01local 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] = Color3.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
17end

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.

0
well a rainbow starts at red and goes to blue so start increasing red then increasing green and decreasing red and then the same with blue maybe ProfessorSev 220 — 9y

1 answer

Log in to vote
4
Answered by 9 years ago

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:

01local hue = 0; -- this will cycle from 0-359
02local SAT = 1; -- satutation; constant
03local LUM = 1; -- luminance; constant
04 
05local SPEED = 1; -- hue degree/frame
06 
07function 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 
View all 35 lines...

That could be severely simplified, but the main loop is basically the logic.

Ad

Answer this question