##Lerp
You can use the lerp function on Color3 datatypes. "Lerp" is short for "Linear Interpolation", and takes in 2 arguments:
Color3 end goal: What you're trying to get to
Number alpha: Number between 0 and 1, acting as a percentage between start and end
##Usage
Since you're looking for a smooth transition, you should use a numerical for loop. Syntax looks like this:
for [var] = [start],[finish],[(optional) increment] do
[code]
end
Use your color goal as the first argument in the Lerp function, and then your [var] divided by your [finish] to indicate a gradual climb.
##Code
local part = workspace.Part
local color = Color3.new(0,0,0)
local smooth = 20
for i = 1,smooth do
local c = part.BrickColor.Color:lerp(color,i/smooth);
print(BrickColor.new(c.r,c.g,c.b));
part.BrickColor = BrickColor.new(c.r,c.g,c.b)
wait(.05)
end
Note: BrickColors and Color3s do not translate perfectly. You may notice some odd colors pop up but for the most part, the transition is normal.
1 comment
Color3 or Brick Color?