how to determine the opposite of hex color values?

  • reaper
  • Proficient
  • Proficient
  • User avatar
  • Posts: 435
  • Loc: europe

Post 3+ Months Ago

How can i determine the opposite value of a hex color code like EEEEEE ?

For EEFF99 it would be 99FFEE offcourse but how about the value from above?

And how can i easily view and compare a hex color to it's opposite?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

Well, that wouldn't necessarily be the "opposite".

The opposite of #EEFF99 would be #110066 (#FFFFFF - #EEFF99).

What you're doing is reversing it.

With what you did to #EEFF99, using the same methodology, the opposite of #FFFFFF would be #FFFFFF (when it's actually #000000).

Of course, a colour (well, grey) like #808080 produces #808080 regardless of which method you used.

Reversed it's still #808080, and subtracted from #FFFFFF it's still #808080.

You could write a PHP script to work these out.

Simply remove the # from the beginning, then subtract the colour from FFFFFF.

Windows calculator (in hex mode, through scientific view) will allow you to do this too, if you want something you can just tap in manually.
  • reaper
  • Proficient
  • Proficient
  • User avatar
  • Posts: 435
  • Loc: europe

Post 3+ Months Ago

Quote:
Reversed it's still #808080, and subtracted from #FFFFFF it's still #808080.


Through windows calculator in scientific view my results was when i substracted 808080 from FFFFFF i got the result 7F7F7F :shock:

So what am i doing wrong here?


Quote:
The opposite of #EEFF99 would be #110066


May i ask how you got this result? did you use the windows calculator?
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

You aren't doing anything wrong. The middle of the spectrum is actually 7FFFFF

Try subtracting that, and your result will be 7FFFFF
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

well, #808080 is 128,128,128 in decimal (half of 256).

But I neglected to take into account the fact that PCs start counting at 0, heh.

So, 127,127,127 would be half of 255,255,255.

127,127,127 is #7F7F7F.

7F == 127
80 == 128
FF == 255

ATNO : FFFFFF - 7FFFFF == 800000 ;)
  • Belk Media Group
  • Graphic Monk
  • Professor
  • User avatar
  • Posts: 778
  • Loc: In the heart of California, Fresno.

Post 3+ Months Ago

WTF? I guess I am old. As an old school art major, we just used a color wheel, starting with the primary colors; red, blue, and yellow. If you don't know how to make one the following links should help a lot, especially the first one. The second one is a webpage tutorial on color theory.

http://www.ficml.org/jemimap/style/color/wheel.html
http://www.colormatters.com/colortheory.html
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Axe wrote:

ATNO : FFFFFF - 7FFFFF == 800000 ;)


Comes down to how it's calculated.
2+2 doesn't always equal 4
  • LAbrego
  • brego from LA
  • Web Master
  • User avatar
  • Posts: 2852

Post 3+ Months Ago

Never forget: 2 + 2 = 5 for extremely large values of 2. :D
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

ATNO/TW wrote:
Axe wrote:

ATNO : FFFFFF - 7FFFFF == 800000 ;)


Comes down to how it's calculated.
2+2 doesn't always equal 4


Right, but here it's not one big single number. It's three pairs of 0-255. So you'd have to half each of the pairs.
  • reaper
  • Proficient
  • Proficient
  • User avatar
  • Posts: 435
  • Loc: europe

Post 3+ Months Ago

Ok ok, this is getting complicated guys, especially when statements being made such as
Quote:
2+2 doesn't always equal 4
then you really got me lost in the forest of obliviousness :shock:

And please don't try to explain me how 2+2 doesn't always adds up to 4 because you guys are scaring the sh**s out of me :lol: talk about getting complicated :)


Please guys, a simple way to dertermine the opposite color of a hex value?
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

lmao!!!

Simple way == convert it to three decimal numbers between 0-255.

Subtract each of those numbers from 255, and convert your answer back to three pairs of hex numbers (Red, Green and Blue).
  • reaper
  • Proficient
  • Proficient
  • User avatar
  • Posts: 435
  • Loc: europe

Post 3+ Months Ago

Quote:
Simple way == convert it to three decimal numbers between 0-255.

Subtract each of those numbers from 255, and convert your answer back to three pairs of hex numbers (Red, Green and Blue).



:lol: You call that simple

Come on man, you're sh*tting me right?
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

Nope, you can make up a PHP function to do it real easy.

Use substr() to split it up into 3 separate variables, do the math, then join 'em back up.

PHP Code: [ Select ]
<?php
 
 
 
function invert_colour($start_colour) {
 
  $colour_red = hexdec(substr($start_colour, 1, 2));
 
  $colour_green = hexdec(substr($start_colour, 3, 2));
 
  $colour_blue = hexdec(substr($start_colour, 5, 2));
 
 
 
  $new_red = dechex(255 - $colour_red);
 
  $new_green = dechex(255  - $colour_green);
 
  $new_blue = dechex(255 - $colour_blue);
 
 
 
  if (strlen($new_red) == 1) {$new_red .= '0';}
 
  if (strlen($new_green) == 1) {$new_green .= '0';}
 
  if (strlen($new_blue) == 1) {$new_blue .= '0';}
 
 
 
  $new_colour = '#'.$new_red.$new_green.$new_blue;
 
 
 
  return $new_colour;
 
}
 
 
 
echo '<table border="0" cellpadding="1" cellspacing="2" width="200">';
 
 
 
$start_colour = '#ffa040';
 
echo '<tr><td align="center" bgcolor="'.$start_colour.'"><b><font color="'.invert_colour($start_colour).'">'.$start_colour.'</font></b></td></tr>';
 
echo '<tr><td align="center" bgcolor="'.invert_colour($start_colour).'"><b><font color="'.$start_colour.'">'.invert_colour($start_colour).'</font></b></td></tr>';
 
 
 
$start_colour = '#eeff99';
 
echo '<tr><td align="center" bgcolor="'.$start_colour.'"><b><font color="'.invert_colour($start_colour).'">'.$start_colour.'</font></b></td></tr>';
 
echo '<tr><td align="center" bgcolor="'.invert_colour($start_colour).'"><b><font color="'.$start_colour.'">'.invert_colour($start_colour).'</font></b></td></tr>';
 
 
 
$start_colour = '#ff00ff';
 
echo '<tr><td align="center" bgcolor="'.$start_colour.'"><b><font color="'.invert_colour($start_colour).'">'.$start_colour.'</font></b></td></tr>';
 
echo '<tr><td align="center" bgcolor="'.invert_colour($start_colour).'"><b><font color="'.$start_colour.'">'.invert_colour($start_colour).'</font></b></td></tr>';
 
 
 
echo '</table>';
 
 
 
?>
 
 
  1. <?php
  2.  
  3.  
  4.  
  5. function invert_colour($start_colour) {
  6.  
  7.   $colour_red = hexdec(substr($start_colour, 1, 2));
  8.  
  9.   $colour_green = hexdec(substr($start_colour, 3, 2));
  10.  
  11.   $colour_blue = hexdec(substr($start_colour, 5, 2));
  12.  
  13.  
  14.  
  15.   $new_red = dechex(255 - $colour_red);
  16.  
  17.   $new_green = dechex(255  - $colour_green);
  18.  
  19.   $new_blue = dechex(255 - $colour_blue);
  20.  
  21.  
  22.  
  23.   if (strlen($new_red) == 1) {$new_red .= '0';}
  24.  
  25.   if (strlen($new_green) == 1) {$new_green .= '0';}
  26.  
  27.   if (strlen($new_blue) == 1) {$new_blue .= '0';}
  28.  
  29.  
  30.  
  31.   $new_colour = '#'.$new_red.$new_green.$new_blue;
  32.  
  33.  
  34.  
  35.   return $new_colour;
  36.  
  37. }
  38.  
  39.  
  40.  
  41. echo '<table border="0" cellpadding="1" cellspacing="2" width="200">';
  42.  
  43.  
  44.  
  45. $start_colour = '#ffa040';
  46.  
  47. echo '<tr><td align="center" bgcolor="'.$start_colour.'"><b><font color="'.invert_colour($start_colour).'">'.$start_colour.'</font></b></td></tr>';
  48.  
  49. echo '<tr><td align="center" bgcolor="'.invert_colour($start_colour).'"><b><font color="'.$start_colour.'">'.invert_colour($start_colour).'</font></b></td></tr>';
  50.  
  51.  
  52.  
  53. $start_colour = '#eeff99';
  54.  
  55. echo '<tr><td align="center" bgcolor="'.$start_colour.'"><b><font color="'.invert_colour($start_colour).'">'.$start_colour.'</font></b></td></tr>';
  56.  
  57. echo '<tr><td align="center" bgcolor="'.invert_colour($start_colour).'"><b><font color="'.$start_colour.'">'.invert_colour($start_colour).'</font></b></td></tr>';
  58.  
  59.  
  60.  
  61. $start_colour = '#ff00ff';
  62.  
  63. echo '<tr><td align="center" bgcolor="'.$start_colour.'"><b><font color="'.invert_colour($start_colour).'">'.$start_colour.'</font></b></td></tr>';
  64.  
  65. echo '<tr><td align="center" bgcolor="'.invert_colour($start_colour).'"><b><font color="'.$start_colour.'">'.invert_colour($start_colour).'</font></b></td></tr>';
  66.  
  67.  
  68.  
  69. echo '</table>';
  70.  
  71.  
  72.  
  73. ?>
  74.  
  75.  


There ya go. It could probably be optimized quite a bit, but you don't wanna know how hungover I am right now, heh.

You could make a form to submit the colours to a script, rather than having to edit the file each time.
  • blink182av
  • Guru
  • Guru
  • blink182av
  • Posts: 1258
  • Loc: New York

Post 3+ Months Ago

2.0+2.0=4.0 :)
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

Yeah, but 8+8 doesn't always = 16. Sometimes 8+8 == 10 ;)
  • blink182av
  • Guru
  • Guru
  • blink182av
  • Posts: 1258
  • Loc: New York

Post 3+ Months Ago

-decimal? Lol?
  • reaper
  • Proficient
  • Proficient
  • User avatar
  • Posts: 435
  • Loc: europe

Post 3+ Months Ago

Ok guys i thought i didn't need it afterall but it shows i still need to know how this is done but i can't understand s&*t from this.

Isn't there a single piece of software that can spit out the opposite value for me when i enter a certain value?
  • xamix
  • Graduate
  • Graduate
  • xamix
  • Posts: 154

Post 3+ Months Ago

http://www.artofwebdesign.co.uk/index.php?pg=rgbtohsl
http://www.artofwebdesign.co.uk/index.php?pg=hsltorgb
http://www.artofwebdesign.co.uk/colourcalculator.php


http://www.geocities.com/seedytheteck/c ... osite.html
  • reaper
  • Proficient
  • Proficient
  • User avatar
  • Posts: 435
  • Loc: europe

Post 3+ Months Ago

THANKS! Xamix that looks very helpfull.
  • uberblue
  • Born
  • Born
  • uberblue
  • Posts: 1

Post 3+ Months Ago

I was bored/curious so I converted the above php example to Classic ASP. Hopefully this will help somebody. The code isn't the cleanest because I used a translator
(http://www.me-u.com/php-asp/) and the cleaned that up. It was quite a bit of work actually, the translator was rather useless.

Code: [ Select ]
<%

Function HexToDec(strHex)
 dim lngResult
 dim intIndex
 dim strDigit
 dim intDigit
 dim intValue

 lngResult = 0
 for intIndex = len(strHex) to 1 step -1
  strDigit = mid(strHex, intIndex, 1)
  intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
  if intDigit >= 0 then
   intValue = intDigit * (16 ^ (len(strHex)-intIndex))
   lngResult = lngResult + intValue
  else
   lngResult = 0
   intIndex = 0 ' stop the loop
  end if
 next

 HexToDec = lngResult
End Function


Dim start_colour

Function invert_colour(lv_start_colour)
    Dim lv_colour_red, lv_colour_green, lv_colour_blue, lv_new_red, lv_new_green, lv_new_blue, lv_new_colour
    lv_colour_red = HexToDec(Mid(lv_start_colour,1,2))
    lv_colour_green = HexToDec(Mid(lv_start_colour, 3, 2))
    lv_colour_blue = HexToDec(Mid(lv_start_colour, 5, 2))
    lv_new_red = Hex(255 - lv_colour_red)
    lv_new_green = Hex(255  - lv_colour_green)
    lv_new_blue = Hex(255 - lv_colour_blue)
    
    If Len(lv_new_red)=1 then
        lv_new_red = lv_new_red & "0"
    End If
    If Len(lv_new_green) = 1 then
        lv_new_green = lv_new_green & "0"
    End If
    If Len ( lv_new_blue ) = 1 then
        lv_new_blue = lv_new_blue '0'
    End If

    new_colour  = "#" & lv_new_red & lv_new_green & lv_new_blue
    invert_colour = new_colour
End Function


    start_colour  = "#ffa040"
    Response.Write "<table border=""0"" cellpadding=""1"" cellspacing=""2"" width=""200"">"
    Response.Write "<tr><td align=""center"" bgcolor=""" & start_colour & """><b><font color=""" & invert_colour(start_colour) & """>" & start_colour & "</font></b></td></tr>" & vbcrlf & vbcrlf
    Response.Write "<tr><td align=""center"" bgcolor=""" & invert_colour(start_colour) & """><b><font color=""" & start_colour & """>" & invert_colour(start_colour) & "</font></b></td></tr>" & vbcrlf & vbcrlf
    start_colour  = "#eeff99"
    Response.Write "<tr><td align=""center"" bgcolor=""" & start_colour & """><b><font color=""" & invert_colour(start_colour) & """>" & start_colour & "</font></b></td></tr>"& vbcrlf & vbcrlf
    Response.Write "<tr><td align=""center"" bgcolor=""" & invert_colour(start_colour) & """><b><font color=""" & start_colour & """>" & invert_colour(start_colour) & "</font></b></td></tr>" & vbcrlf & vbcrlf
    start_colour  = "#ff00ff"
    Response.Write "<tr><td align=""center"" bgcolor=""" & start_colour & """><b><font color=""" & invert_colour(start_colour) & """>" & start_colour & "</font></b></td></tr>" & vbcrlf & vbcrlf
    Response.Write "<tr><td align=""center"" bgcolor=""" & invert_colour(start_colour) & """><b><font color=""" & start_colour & """>" & invert_colour(start_colour) & "</font></b></td></tr>" & vbcrlf & vbcrlf
    Response.Write "</table>"
    
%>
  1. <%
  2. Function HexToDec(strHex)
  3.  dim lngResult
  4.  dim intIndex
  5.  dim strDigit
  6.  dim intDigit
  7.  dim intValue
  8.  lngResult = 0
  9.  for intIndex = len(strHex) to 1 step -1
  10.   strDigit = mid(strHex, intIndex, 1)
  11.   intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
  12.   if intDigit >= 0 then
  13.    intValue = intDigit * (16 ^ (len(strHex)-intIndex))
  14.    lngResult = lngResult + intValue
  15.   else
  16.    lngResult = 0
  17.    intIndex = 0 ' stop the loop
  18.   end if
  19.  next
  20.  HexToDec = lngResult
  21. End Function
  22. Dim start_colour
  23. Function invert_colour(lv_start_colour)
  24.     Dim lv_colour_red, lv_colour_green, lv_colour_blue, lv_new_red, lv_new_green, lv_new_blue, lv_new_colour
  25.     lv_colour_red = HexToDec(Mid(lv_start_colour,1,2))
  26.     lv_colour_green = HexToDec(Mid(lv_start_colour, 3, 2))
  27.     lv_colour_blue = HexToDec(Mid(lv_start_colour, 5, 2))
  28.     lv_new_red = Hex(255 - lv_colour_red)
  29.     lv_new_green = Hex(255  - lv_colour_green)
  30.     lv_new_blue = Hex(255 - lv_colour_blue)
  31.     
  32.     If Len(lv_new_red)=1 then
  33.         lv_new_red = lv_new_red & "0"
  34.     End If
  35.     If Len(lv_new_green) = 1 then
  36.         lv_new_green = lv_new_green & "0"
  37.     End If
  38.     If Len ( lv_new_blue ) = 1 then
  39.         lv_new_blue = lv_new_blue '0'
  40.     End If
  41.     new_colour  = "#" & lv_new_red & lv_new_green & lv_new_blue
  42.     invert_colour = new_colour
  43. End Function
  44.     start_colour  = "#ffa040"
  45.     Response.Write "<table border=""0"" cellpadding=""1"" cellspacing=""2"" width=""200"">"
  46.     Response.Write "<tr><td align=""center"" bgcolor=""" & start_colour & """><b><font color=""" & invert_colour(start_colour) & """>" & start_colour & "</font></b></td></tr>" & vbcrlf & vbcrlf
  47.     Response.Write "<tr><td align=""center"" bgcolor=""" & invert_colour(start_colour) & """><b><font color=""" & start_colour & """>" & invert_colour(start_colour) & "</font></b></td></tr>" & vbcrlf & vbcrlf
  48.     start_colour  = "#eeff99"
  49.     Response.Write "<tr><td align=""center"" bgcolor=""" & start_colour & """><b><font color=""" & invert_colour(start_colour) & """>" & start_colour & "</font></b></td></tr>"& vbcrlf & vbcrlf
  50.     Response.Write "<tr><td align=""center"" bgcolor=""" & invert_colour(start_colour) & """><b><font color=""" & start_colour & """>" & invert_colour(start_colour) & "</font></b></td></tr>" & vbcrlf & vbcrlf
  51.     start_colour  = "#ff00ff"
  52.     Response.Write "<tr><td align=""center"" bgcolor=""" & start_colour & """><b><font color=""" & invert_colour(start_colour) & """>" & start_colour & "</font></b></td></tr>" & vbcrlf & vbcrlf
  53.     Response.Write "<tr><td align=""center"" bgcolor=""" & invert_colour(start_colour) & """><b><font color=""" & start_colour & """>" & invert_colour(start_colour) & "</font></b></td></tr>" & vbcrlf & vbcrlf
  54.     Response.Write "</table>"
  55.     
  56. %>
  • CXLink
  • Expert
  • Expert
  • User avatar
  • Posts: 685
  • Loc: ATL-GA

Post 3+ Months Ago

blink182av wrote:
2.0+2.0=4.0 :)


Good Job blink I agree with you. Axe threw me under the bus before he posted the php.
My definition of simple php is one maybe two lines not one or two pages. lol
My head hurts I am going to go take a nap.

Post Information

  • Total Posts in this topic: 21 posts
  • Users browsing this forum: No registered users and 19 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.