Like for example: Making a rainbow GUI frame
Or making a frame goes from black to white (or any colors possible) smoothly
Like for example: Making a rainbow GUI frame
Or making a frame goes from black to white (or any colors possible) smoothly
There are two ways this can be done. The first would be to use the lerp function in a Color3 and the second would be to use the TweenService which in my opinion is better.
using lerp:-
local runServ = game:GetService('RunService')
local frame = script.Parent
-- new random number generator
local randomGen = Random.new(wait() * 10 + wait() * 10)
local cur = frame.BackgroundColor3
local nextColor3 = Color3.fromRGB(randomGen:NextInteger(0, 255), randomGen:NextInteger(0, 255), randomGen:NextInteger(0, 255))
while true do
-- lerp loop
for i=0, 100 do
frame.BackgroundColor3 = cur:Lerp(nextColor3, i/100)
runServ.Heartbeat:Wait() -- one lerp per frame
end
-- swap color3
cur = nextColor3
nextColor3 = Color3.fromRGB(randomGen:NextInteger(0, 255), randomGen:NextInteger(0, 255), randomGen:NextInteger(0, 255))
end
using tween service:-
local tweenServ = game:GetService('TweenService')
local frame = script.Parent
-- new random
local randomGen = Random.new(wait() * 10 + wait() * 10)
local tweeninfo = TweenInfo.new()-- def settings
local function mkTween()
-- create a new tween and return it
return tweenServ:Create(
frame,
tweeninfo,
{BackgroundColor3 = Color3.fromRGB(randomGen:NextInteger(0, 255), randomGen:NextInteger(0, 255), randomGen:NextInteger(0, 255))}
)
end
while true do
local tween = mkTween()
tween:Play() -- play
tween.Completed:Wait() -- wait for completed
end
I hope this helps.
Heres an example where it smoothly goes from white to red.
-- Inside ur Frame
local start = Color3.new(1,1,1)-- White
local End = Color3.new(1,0,0)--Red
for i = 0,1,0.03 do
wait()
script.Parent.BackgroundColor3 = start:lerp(End,i)
end
i didn't know that Color3 have a lerp() function
Well did it help / work ( was it ur answer )
i would not use wait() since it will make it look laggy.
Can you use game:GetService("RunSerivce").RenderStepped:wait() ?
I would personally work on a per frame basis to help with performance but that should be ok.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
http://wiki.roblox.com/index.php?title=API:ColorSequence