lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 31 Jul 2015 07:12 PM |
--RGB to HSL converter local color={ R=24; G=98; B=118; } local fl=math.floor function convertRGB(color3) local r,g,b=color3.R/255,color3.G/255,color3.B/255 local min,max=math.min(r,g,b),math.max(r,g,b) local L,H,S=(min+max)/2 if min==max then S=0;H=0 elseif min~=max and L<.5 then S=(max-min)/(max+min) elseif min~=max and L>=.5 then S=(max-min)/(2-max-min) end if max==r then H=(g-b)/(max-min) elseif max==g then H=2+(b-r)/(max-min) elseif max==b then H=4+(r-g)/(max-min) end H=H*60 if H<0 then H=H+360 end return fl(H+.5),fl((S*100)+.5),fl((L*100)+.5) end
print(convertRGB(color))
------------——–––---------------------•------- I wrote this on mobile, and tested it on touchLua. Is the math behind this correct? And could someone test it for me? I wanted to have color 'Interpolation', and someone said to convert it to HSL, interpolate here, then convert back to RGB. |
|
|
| Report Abuse |
|
|
Funse
|
  |
| Joined: 11 Jun 2012 |
| Total Posts: 7887 |
|
|
| 31 Jul 2015 07:17 PM |
"I wanted to have color 'Interpolation', and someone said to convert it to HSL"
... |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
| |
|
|
| 31 Jul 2015 07:20 PM |
@Funse Do you have a point? If your point is that OP is wrong, then you're wrong. Sure, you can easily interpolate using RGB, but it will be all weird. Read the following if you don't understand:
stackoverflow. com/questions/13488957/interpolate-from-one-color-to-another |
|
|
| Report Abuse |
|
|
Everment
|
  |
| Joined: 08 Oct 2009 |
| Total Posts: 6020 |
|
|
| 31 Jul 2015 07:20 PM |
| Why not interpolate using RGB? It works fine last I tested it. |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 31 Jul 2015 07:20 PM |
http://www.roblox.com/Forum/ShowPost.aspx?PostID=169424247
theres the thread |
|
|
| Report Abuse |
|
|
Everment
|
  |
| Joined: 08 Oct 2009 |
| Total Posts: 6020 |
|
|
| 31 Jul 2015 07:24 PM |
According to http://www.gamedev.net/topic/537295-how-do-i-interpolate-colors/#entry4469203
"Linear interpolation of each RGB component is the most straightforward, and the results are often acceptable.
If you need a 'better' interpolation, you can convert the RGB colour to HSV, interpolate the HSV, and convert back to RGB for display."
So, it depends, have you tried RGB to see how it looks? If you don't like how RGB worked, used HSV. |
|
|
| Report Abuse |
|
|
Funse
|
  |
| Joined: 11 Jun 2012 |
| Total Posts: 7887 |
|
|
| 31 Jul 2015 07:25 PM |
Wouldn't this work though? It isn't choppy.
function changeColor(oldColor,newColor,loops) for i = 0,loops do local red = oldColor.r + (((newColor.r - oldColor.r)/loops) * i) local green = oldColor.g + (((newColor.g - oldColor.g)/loops) * i) local blue = oldColor.b + (((newColor.b - oldColor.b)/loops) * i) local finalColor = Color3.new(red,green,blue) print(finalColor) wait() end end |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 31 Jul 2015 07:28 PM |
My bad guys. I didn't really specify a question. My question is how exactly would I interpolate HSL? I also need to write a function that converts back to RGB. |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 31 Jul 2015 07:29 PM |
| Also, wouldnt that cycle through one shade? I want it to cycle through the entire rainbow |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 07:29 PM |
Then just change the hue
like this:
for i = 1, 360 do hue = i end |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 31 Jul 2015 07:35 PM |
| I feel stupid now. Did not think it would be this simple. Anyways, thanks! |
|
|
| Report Abuse |
|
|
| |
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 31 Jul 2015 07:47 PM |
XD http://www.roblox.com/ColorModule-item?id=250760024 |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 31 Jul 2015 07:52 PM |
| ^Would be a lot more useful if I actually had a PC. My laptop broke, so it really doesnt bother me that there was an easier way. |
|
|
| Report Abuse |
|
|