How to find contrasting color

Hi guys been a while.

Anyways i have an object with a random fill color.

local square = display.newRect(40,40,40,40) square:setFillColor(math.random(),math.random(),math.random())

Then I have this other object:

local rectangle = display.newRect(80,80,40,40) --rectangle:setFillColor(?,?,?)

I want the fill color of this object to contrast with the first object.

In other words, I want the fillcolor to be complimentary to the other color.

I do have this one method, but its inefficient and too much code. 

Do you guys have any suggestions of what code i should do.

Is there any Plugin for this or any contributed code some where?

First, I don’t think you’re using the exactly the right terms, but I’m not a artist so, take that into account.

Second, You can find this answer online, but if you don’t want to hunt, SSK2 provides a suite of color related methods here:

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/colors/

You can implement colors both as RGB and HSL with SSK2.colors.

Using your example above, you can do this with  SSK2.colors.

-- Split Complimentary (Two Colors) (Default split is 30 degrees on either side of color) local square1 = display.newRect(40,40,40,40) local color1 = { math.random(),math.random(),math.random() } square1:setFillColor(unpack(color1)) local square2 = display.newRect(100,40,40,40) local square3 = display.newRect(160,40,40,40) local color2, color3 = ssk.colors.rgbSplitComplementary(color1) square2:setFillColor(unpack(color2)) square3:setFillColor(unpack(color3)) -- Opposing Color (180 degrees) local square1 = display.newRect(40,100,40,40) square1:setFillColor(unpack(color1)) local square2 = display.newRect(100,100,40,40) local color2 = ssk.colors.rgbOffset(color1,180) square2:setFillColor(unpack(color2))

Example output: colors.png

Please note.  The docs here have a bug: 

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/colors/#rgb-functions-sskcolors

I think I updated the interfaces and forgot to update the docs.

So if you try this kind of call:

local rgba = {1,1,0,0.5} rgbSplitComplementary( rgba[1], rgba[2], rgba[3], rgba[4], 30) -- OLD INTERFACE

and it doesn’t work.  Try passing a table instead:

local rgba = {1,1,0,0.5} rgbSplitComplementary( rgba, 30 ) -- CURRENT INTERFACE

Hi,

If by complimentary color you mean the opposite color on a color wheel, i’d convert your RGB value to HSL, then add 180 to hue on a looping scale from 0 to 359, the convert the new HSL valule back to RGB.

Conversion logic is available online somewhere but frankly, thats something corona sdk need to create an api for.

HSL makes much more sense when manipulating colors.

I did this for my radiance program so I know it works.

First, I don’t think you’re using the exactly the right terms, but I’m not a artist so, take that into account.

Second, You can find this answer online, but if you don’t want to hunt, SSK2 provides a suite of color related methods here:

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/colors/

You can implement colors both as RGB and HSL with SSK2.colors.

Using your example above, you can do this with  SSK2.colors.

-- Split Complimentary (Two Colors) (Default split is 30 degrees on either side of color) local square1 = display.newRect(40,40,40,40) local color1 = { math.random(),math.random(),math.random() } square1:setFillColor(unpack(color1)) local square2 = display.newRect(100,40,40,40) local square3 = display.newRect(160,40,40,40) local color2, color3 = ssk.colors.rgbSplitComplementary(color1) square2:setFillColor(unpack(color2)) square3:setFillColor(unpack(color3)) -- Opposing Color (180 degrees) local square1 = display.newRect(40,100,40,40) square1:setFillColor(unpack(color1)) local square2 = display.newRect(100,100,40,40) local color2 = ssk.colors.rgbOffset(color1,180) square2:setFillColor(unpack(color2))

Example output: colors.png

Please note.  The docs here have a bug: 

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/colors/#rgb-functions-sskcolors

I think I updated the interfaces and forgot to update the docs.

So if you try this kind of call:

local rgba = {1,1,0,0.5} rgbSplitComplementary( rgba[1], rgba[2], rgba[3], rgba[4], 30) -- OLD INTERFACE

and it doesn’t work.  Try passing a table instead:

local rgba = {1,1,0,0.5} rgbSplitComplementary( rgba, 30 ) -- CURRENT INTERFACE

Hi,

If by complimentary color you mean the opposite color on a color wheel, i’d convert your RGB value to HSL, then add 180 to hue on a looping scale from 0 to 359, the convert the new HSL valule back to RGB.

Conversion logic is available online somewhere but frankly, thats something corona sdk need to create an api for.

HSL makes much more sense when manipulating colors.

I did this for my radiance program so I know it works.