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: Color3 mixing?

Previous Thread :: Next Thread 
LockFocus is not online. LockFocus
Joined: 31 Aug 2013
Total Posts: 1044
08 Aug 2016 08:04 PM
Would it be possible to 'mix' Color3 Values?

Like yellow ( rgb: 255, 255, 0 ) and green ( rgb: 0, 255, 0) would make light green.
(( Yellow and Green are just an example.. ))
Just asking out of curiosity.
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
08 Aug 2016 08:10 PM
r,g,b = 234, 32, 53
r1,g1,b1 = 42, 23, 123

newcolor = Color3.new(math.min(r+r1, 255), math.min(b+b1, 255), math.min(b+b1,255))
Report Abuse
CeaselessQuokka is not online. CeaselessQuokka
Joined: 03 Jul 2012
Total Posts: 7841
08 Aug 2016 08:15 PM
@Dev, that is not how it works.

http://www.colorcube.com/articles/math/math.htm

That may help.


Matthew: "Scripting for ROBLOX intelligence? There is no intelligence in ROBLOX." Me: "LOL"
Report Abuse
LockFocus is not online. LockFocus
Joined: 31 Aug 2013
Total Posts: 1044
08 Aug 2016 08:15 PM
r,g,b = 255, 255, 0;
r1,g1,b1 = 0, 255, 0;
print(Color3.new(math.min(r+r1, 255), math.min(b+b1, 255), math.min(b+b1,255)))

> 255, 0, 0

Last I checked yellow plus green wasn't red..
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
08 Aug 2016 08:17 PM
you could try this

local r,g,b = 255,255,0
local r2,g2,b2 = 0,255,0
local newColor = Color3.new(((r+r2)/2)/255,((g+g2)/2)/255,((b+b2)/2)/255)
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
08 Aug 2016 08:17 PM
-- Example:
function mixColors(c1, c2)
return Color3.new(math.min(c1.r + c2.r, 255), math.min(c1.g + c2.g, 255), math.min(c1.b + c2.b, 255))
end

mixColors(Color3.new(123,45,34), Color3.new(23,123,54))
Report Abuse
LockFocus is not online. LockFocus
Joined: 31 Aug 2013
Total Posts: 1044
08 Aug 2016 08:21 PM
@Lord
That returns 0.5, 1, 0.

@Dev
That returns 255, 255, 0.
Besides, it's the same thing you just posted but in a function.

Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
08 Aug 2016 08:22 PM
"That returns 0.5,1,0"

it's supposed to

color3 values range from 0-1

silly
Report Abuse
LockFocus is not online. LockFocus
Joined: 31 Aug 2013
Total Posts: 1044
08 Aug 2016 08:23 PM
@Lord

forgive me father, for I have sinned.
I'm an idiot :P
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
08 Aug 2016 08:23 PM
does it do what you want?

i just averaged the rgb values and then divided by 255 to get it to eb from 0-1
Report Abuse
LockFocus is not online. LockFocus
Joined: 31 Aug 2013
Total Posts: 1044
08 Aug 2016 08:25 PM
It does exactly what I want, thank you.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
08 Aug 2016 08:26 PM
"Would it be possible to 'mix' Color3 Values?"
Did you totally copy this post? It sounds almost identical.
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=95543084
Don't do what they said in that post though, there's a better way now.


Report Abuse
LockFocus is not online. LockFocus
Joined: 31 Aug 2013
Total Posts: 1044
08 Aug 2016 08:27 PM
Just a small problem, it returns 127.5 when I convert it to the Color3 value (as in 0 - 255 ), but I can fix that on my own. That's what I get for using yellow and green as examples :P Thank you for helping.
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
08 Aug 2016 08:28 PM
Here now you can still use the 255 format. :P

function mixColors(c1, c2)
local function min(a,b)
return math.min(a + b/2, 255)
end
return Color3.fromRGB(min(c1.r, c2.r), min(c1.g, c2.g), min(c1.b, c2.b))
end

mixColors(Color3.new(255, 0, 0), Color3.new(0, 255, 0))
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
08 Aug 2016 08:31 PM
C1:lerp(C2, 0.5)


Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
08 Aug 2016 08:34 PM
@Jarod

go away noob mine's better
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
08 Aug 2016 08:37 PM
Why lerp when you just want to mix?

Plus why take the easy way out when you can learn how it works instead of just having it done for you. xD
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
08 Aug 2016 08:41 PM
It depends on what he means by mixing. In fact, the OP explicitly stated that your code did not do what he wanted.


Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
08 Aug 2016 08:43 PM
Because I left out the part that gets 50% of it so it returned the wrong colors. xD
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
08 Aug 2016 08:46 PM
Well you can get the exact colour between two using lerp if the alpha is 0.5
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
08 Aug 2016 08:49 PM
That's what my code does though, except mine is simpler and (a+b)/2 will never be more than 255. If it does result in more than 255, it won't matter because the original values need to have been more than 255 anyways.

Benchmarking!
Your code: 22.244
My code: 14.479




Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
08 Aug 2016 08:51 PM
Yeah I didn't read the whole thread just this "Why lerp when you just want to mix?" display of vast intelligence.
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
08 Aug 2016 08:52 PM
mine is clearly superior

more lines = more efficiency

!!!

silly cretins


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
08 Aug 2016 08:53 PM
Takes your potato pc to run a simple math problem 22 secs? xD

Proof Plox?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
08 Aug 2016 08:53 PM
I would benchmark yours too, but I assumed raw Color3 values and I don't want to alter your code for that, and I also don't remember the number of iterations I did.


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