generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: I am in need of assistance with some linear interpolation.

Previous Thread :: Next Thread 
BogyMac is not online. BogyMac
Joined: 04 Nov 2011
Total Posts: 823
27 Apr 2015 10:59 PM
I have created a function here to interpolate one Color3 value to another :

function InterpColor(sr,sg,sb,er,eg,eb,length,pos)
--------local cr = (((sr + er) / length) * pos)
--------local cg = (((sg + eg) / length) * pos)
--------local cb = (((sb + eb) / length) * pos)

--------cr = cr / 255
--------cg = cg / 255
--------cb = cb / 255

--------return(Color3.new(cr,cg,cb))
end

It works, except that 1) it always starts at the color 0,0,0, and 2) the length is always incorrect. There are no errors in output, and the inputted variables are all fine. What am I doing wrong here?

Thanks for any help,
-Bogy
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
27 Apr 2015 11:03 PM
function interpolate(a,b,c)
return a*(1-c) + b*c
end

function rgbinterpolate(a,b,c)
return Color3.new(interpolate(a.r,b.r,c),interpolate(a.g,b.g,c),interpolate(a.b,b.b,c))
end

rgbinterpolate(Color3.new(.5, 1, 0), Color3.new(.75, 0.2, 0.05), 0.5)
Report Abuse
jewelycat is not online. jewelycat
Joined: 10 Sep 2008
Total Posts: 17345
27 Apr 2015 11:03 PM
Idk what all those variables are for, but

function interpColor(color1, color2, t)
return Color3.new(color1.r+(color2.r-color1.r)*t, color1.g+(color2.g-color1.g)*t, color1.b+(color2.b-color1.b)*t)
end
Report Abuse
BogyMac is not online. BogyMac
Joined: 04 Nov 2011
Total Posts: 823
27 Apr 2015 11:25 PM
So basically, I'm trying to fade game.Lighting.OutdoorAmbience from its current color to a different color.

@jewelycat, the only difference between my script and yours, is yours is much more compact than mine. I am still experiencing the same problem of the color beginning at 0,0,0. Here is my script so far :
-----------------------------------------------------------------
local MTint = {39, 42, 84}

local MorningRange = {330,420} -- 5:30 AM --> 7:00 AM

wait(1)

local l = game.Lighting

function InterpColor(color1, color2, t)
return Color3.new((color1.r+(color2.r-color1.r)*t)/255, (color1.g+(color2.g-color1.g)*t)/255, (color1.b+(color2.b-color1.b)*t)/255)
end

while true do
--------local ctime = l:GetMinutesAfterMidnight()
--------l:SetMinutesAfterMidnight(ctime + 0.1)

--------local MD = (MorningRange[2] - MorningRange[1])
--------local CDM = (ctime - MorningRange[1])

--------if CDM > 0 and CDM < MD then
----------------colorInterp = InterpColor(l.OutdoorAmbient,Color3.new(MTint[1],MTint[2],MTint[3]),CDM / MD)
----------------print(colorInterp)
----------------l.OutdoorAmbient = colorInterp
--------end
--------wait(0.1)
end
Report Abuse
jewelycat is not online. jewelycat
Joined: 10 Sep 2008
Total Posts: 17345
27 Apr 2015 11:31 PM
Don't divide by 255, the r,g,b properties are already in the range from 0 to 1.
Report Abuse
jewelycat is not online. jewelycat
Joined: 10 Sep 2008
Total Posts: 17345
27 Apr 2015 11:35 PM
Also, you're getting a new value for your initial color every time the loop is run because you're reading OutdoorAmbient right off of Lighting. If you want a linear transition, you should set an initial color to a variable and use that instead.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image