This is called interpolating (smoothly moving between two options).
We first generate both results, and then figure out how far in time we are between the two. If we're 80% through the transitioning time, we figure out a way to be 80% towards the second color.
The simplest way to interpolate is called linear interpolation. It's called linear since the rate is constant through the transition, so the graph of any of the values is a line.
If we use ROBLOX's Vector3s to store the colors, it becomes a little briefer to do the math, so that's what I'll do.
01 | begin = Vector 3. new(math.random(),math.random(),math.random()) |
02 | finish = Vector 3. new(math.random(),math.random(),math.random()) |
07 | while tick() - startTime < duration do |
08 | local progress = (tick() - startTime) / duration |
11 | local intermediate = finish * progress + ( 1 - progress ) * begin |
13 | local color = Color 3. new(intermediate.x, intermediate.y, intermediate.z) |
To make this loop, we just have to make a new finish
but move finish
into begin
:
1 | begin, finish = finish, Vector 3. new(math.random(),math.random(),math.random()) |
Locked by adark, TofuBytes, and evaera
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?