Complementary Color Calculator Free tool | Plus Source Code

As a web designer, I always found myself lurking to find complementary color for a given color code.

I came across a complicated PHP script that claims to calculate the complementary color using
hue, saturation and lightness parameters – but found several errors with its output.

So i decided to write my own code. The code is simple and has nothing to do hue, saturation and lightness.
I simple uses the hexadecimal color code to derive the color codes and it is accurate.

So without much ado, here is the conversion tool.



Complementary Color Calculator

#

R: G: B:
H: S: V:



Input Color Code: #82627A
Complementary Color Code: #

Update:
While this code works great and gives the complementary color, this is an old code.
I have made a much more detailed color calculator to replace this code.
Check it out at:
http://knowpapa.com/color-combo/

 
I have tested this using random samples and this conforms with photoshop results.
However if you come across a bug or some discrepancy, please post it here as a comment.

And should you need the actual code behind this, here it goes

sorry you entered an invalid color code, 
please check your color code

'; $hexcode = mysql_real_escape_string($hexcode); $hexcode = htmlentities($hexcode); $complementarycolor = "Tit for Tat ! invalid color yields invalid results. Check your color code"; } // do all the routine form sanitization and validation // i have excluded my actual validation code for security reasons but it should work even without validation. else { //NOW the actual conversion begins // $hexcode is the six digit hex colour code we want to convert // $hexcode is the six digit hex colour code we want to convert $redhex1 = substr($hexcode,0,1); $redhex2 = substr($hexcode,1,1); $greenhex1 = substr($hexcode,2,1); $greenhex2 = substr($hexcode,3,1); $bluehex1 = substr($hexcode,4,1); $bluehex2 = substr($hexcode,5,1); $var_r1 = dechex((15-(hexdec($redhex1)))) ; $var_r2 = dechex((15- (hexdec($redhex2)))) ; $var_g1 = dechex((15-(hexdec($greenhex1)))) ; $var_g2 = dechex((15-(hexdec($greenhex2)))) ; $var_b1 = dechex((15-(hexdec($bluehex1)))); $var_b2 = dechex((15-(hexdec($bluehex2)))); $complementarycolor = $var_r1.$var_r2.$var_g1.$var_g2.$var_b1.$var_b2; } } ?>
  • #

One comment on “Complementary Color Calculator Free tool | Plus Source Code

Comments are closed.