Color computation

Discussion in 'Javascript' started by pamelafluente@libero.it, Sep 9, 2006.

  1. Guest

    Hi,

    If I have:

    <div style="background:anyColorHere"> Hi </div>

    where anyColorHere is any hex string that represent a valid color.

    How can I invert that background color "anyColorHere" ? Can you point
    (or suggest) a script
    that does that in a proper way ?

    -P
     
    , Sep 9, 2006
    #1
    1. Advertising

  2. wrote:

    > <div style="background:anyColorHere"> Hi </div>
    > where anyColorHere is any hex string that represent a valid color.
    > How can I invert that background color "anyColorHere" ? Can you point
    > (or suggest) a script that does that in a proper way ?


    <html>
    <head>
    <script type="text/JavaScript">
    function bla(){
    var b = document.getElementsByTagName('body')[0];
    var bg = b.style.backgroundColor;
    alert('present background is '+b.style.backgroundColor)
    alert('present background will be change into inversed RGB color')
    var oldCol = bg.split('(')[1].split(')')[0].split(',');
    var newCol = new Array()
    for(var i=0;i<oldCol.length;i++){
    newCol = 255-Number(oldCol);
    }
    b.style.backgroundColor
    = 'rgb('+newCol[0]+','+newCol[1]+','+newCol[2]+')';
    alert('new background is '+b.style.backgroundColor)
    }
    onload=bla
    </script>
    </head>
    <body style="background-color: rgb(0,204,255)">
    </body>
    </html>

    Soli Deo Gloria:
    http://www.codingforums.com/archive/index.php?t-47335.html

    Hex/RGB converter:
    http://www.google.com/search?q=convert hex rgb javascript

    --
    Bart
     
    Bart Van der Donck, Sep 9, 2006
    #2
    1. Advertising

  3. Evertjan. Guest

    wrote on 09 sep 2006 in comp.lang.javascript:
    > If I have:
    >
    > <div style="background:anyColorHere"> Hi </div>
    >
    > where anyColorHere is any hex string that represent a valid color.
    >
    > How can I invert that background color "anyColorHere" ? Can you point
    > (or suggest) a script that does that in a proper way ?


    try:

    <script type='text/javascript'>
    function invertMe(x){
    var t1 = '0123456789abcdef#'
    var t2 = 'fedcba9876543210#'
    x.style.backgroundColor =
    x.style.backgroundColor.replace( /./gi,
    function (s) {
    return t2.charAt(t1.indexOf(s));
    }
    )
    }
    </script>

    <div style='background-color:#c0c0c0;width:50px;'
    onclick='invertMe(this)'>
    Click me to invert my background</div>
    <br><br>
    <div style='background-color:#fe3456;width:50px;'
    onclick='invertMe(this)'>
    Click me to invert my background</div>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 9, 2006
    #3
  4. Guest

    Re: Color computation - Beautiful !!

    > x.style.backgroundColor.replace( /./gi,
    > function (s) {
    > return t2.charAt(t1.indexOf(s));

    ....

    I replay here to you both, Bart and Evertjan.

    Both solution works fine.

    Bart is relying, as far as I understand, on the fact that
    color is defined as rgb(xx,yy,zz)". Actually I assumed in my
    question an hex string. But it is nice indeed to have this method also.

    The script proposed by Evertjan is a precide reply to my question
    and I feel the logic it implements is quite smart. It has also
    the advantage to shield from then many complexities of a possible
    parsing.
    I like it a lot.

    btw What is this : <div style='background-color:#c0c0c0;width:50px;'
    onclick='invertMe(this)'> Click me to invert my background</div>

    in IE it does displays nothing. Is this code to test some other
    browser?


    -P
     
    , Sep 9, 2006
    #4
  5. Re: Color computation - Beautiful !!

    wrote:

    > [...]
    > Bart is relying, as far as I understand, on the fact that
    > color is defined as rgb(xx,yy,zz)". Actually I assumed in my
    > question an hex string.
    > [...]


    Yes, you'ld need to convert from hex to rgb (and back if necessary).
    That shouldn't be too tough; see hyperlink at the end of my previous
    post.

    --
    Bart
     
    Bart Van der Donck, Sep 9, 2006
    #5
  6. Evertjan. Guest

    Re: Color computation - Beautiful !!

    wrote on 09 sep 2006 in comp.lang.javascript:

    >> x.style.backgroundColor.replace( /./gi,
    >> function (s) {
    >> return t2.charAt(t1.indexOf(s));

    > ...
    >
    > I replay here to you both, Bart and Evertjan.
    >
    > Both solution works fine.
    >
    > Bart is relying, as far as I understand, on the fact that
    > color is defined as rgb(xx,yy,zz)". Actually I assumed in my
    > question an hex string. But it is nice indeed to have this method also.
    >
    > The script proposed by Evertjan is a precide reply to my question
    > and I feel the logic it implements is quite smart. It has also
    > the advantage to shield from then many complexities of a possible
    > parsing.
    > I like it a lot.


    Inverting all seperate hexadecimal characters
    will give a inversion of the total number,
    while the # is replaced by itself.

    Regular expression is IMHO preferrable to JS looping.


    > btw What is this : <div style='background-color:#c0c0c0;width:50px;'
    > onclick='invertMe(this)'> Click me to invert my background</div>


    It seems you have to learn HTML and CSS before you try Javascript.
    invertMe() is the function
    in the <script type='text/javascript'>...</script>

    Did you run my code in a test.html ?

    > in IE it does displays nothing.


    Oh, but it does.
    Did you put my code in a seperate test.html as I expect you to do?
    Or did you put other lines in it? Don't.

    > Is this code to test some other
    > browser?


    No, IE works fine.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 9, 2006
    #6
  7. Guest

    Re: Color computation - Beautiful !!

    > It seems you have to learn HTML and CSS before you try Javascript.
    > invertMe() is the function
    > in the <script type='text/javascript'>...</script>
    >
    > Did you run my code in a test.html ?
    >
    > > in IE it does displays nothing.

    >
    > Oh, but it does.
    > Did you put my code in a seperate test.html as I expect you to do?
    > Or did you put other lines in it? Don't.
    >
    > > Is this code to test some other
    > > browser?

    >
    > No, IE works fine.
    >


    :)) Hi Evertjan ,

    I tried pasting it in my code:


    <html>

    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=windows-1252">
    <title>New Page 1</title>
    </head>

    <body>

    <div style="position: absolute; width: 100px; height: 100px; z-index:
    1; background= #aaccdd" id="layer1">
    &nbsp;</div>

    <script type='text/javascript'>
    function invertMe(x){
    var t1 = '0123456789abcdef#'
    var t2 = 'fedcba9876543210#'
    x.style.backgroundColor =
    x.style.backgroundColor.replace( /./gi,
    function (s) {
    return t2.charAt(t1.indexOf(s));
    }
    )
    }

    </script>

    <div style='background-color:#c0c0c0;width:50px;'
    onclick='invertMe(this)'>
    1. Click me to invert my background</div>
    <br><br>
    <div style='background-color:#fe3456;width:50px;'
    onclick='invertMe(this)'>
    2. Click me to invert my background</div>


    </body>

    </html>


    I had the impression there was a block missing (perhaps was somehow
    covered).

    Is "background" the same as "background-color" I see you use the
    latter. I always used the first. Is this a mistake?

    -P
     
    , Sep 9, 2006
    #7
  8. Evertjan. Guest

    Re: Color computation - Beautiful !!

    wrote on 09 sep 2006 in comp.lang.javascript:

    >> It seems you have to learn HTML and CSS before you try Javascript.
    >> invertMe() is the function
    >> in the <script type='text/javascript'>...</script>
    >>
    >> Did you run my code in a test.html ?
    >>
    >> > in IE it does displays nothing.

    >>
    >> Oh, but it does.
    >> Did you put my code in a seperate test.html as I expect you to do?
    >> Or did you put other lines in it? Don't.
    >>
    >> > Is this code to test some other
    >> > browser?

    >>
    >> No, IE works fine.
    >>

    >
    > :)) Hi Evertjan ,
    >
    > I tried pasting it in my code:


    You should not, until you tested my code for yourself AS IS.
    Only if you agree it "works", proceed.
    Talking about my code "not working" in your application will not be
    usefull before that.

    > <html>
    >
    > <head>
    > <meta http-equiv="Content-Type" content="text/html;
    > charset=windows-1252">
    > <title>New Page 1</title>
    > </head>
    >
    > <body>
    >
    > <div style="position: absolute; width: 100px; height: 100px; z-index:
    > 1; background= #aaccdd" id="layer1">
    > &nbsp;</div>


    Why this? perhaps it covers the following, I did not test that.
    Leave the above div away!

    >
    > <script type='text/javascript'>
    > function invertMe(x){
    > var t1 = '0123456789abcdef#'
    > var t2 = 'fedcba9876543210#'
    > x.style.backgroundColor =
    > x.style.backgroundColor.replace( /./gi,
    > function (s) {
    > return t2.charAt(t1.indexOf(s));
    > }
    > )
    >}
    >
    > </script>


    Scripts like thease should be in the <head> section.

    >
    > <div style='background-color:#c0c0c0;width:50px;'
    > onclick='invertMe(this)'>
    > 1. Click me to invert my background</div>
    > <br><br>
    > <div style='background-color:#fe3456;width:50px;'
    > onclick='invertMe(this)'>
    > 2. Click me to invert my background</div>
    >
    >
    > </body>
    >
    > </html>
    >
    >
    > I had the impression there was a block missing (perhaps was somehow
    > covered).


    sorry?

    >
    > Is "background" the same as "background-color" I see you use the
    > latter. I always used the first. Is this a mistake?


    No. Please read up on CSS, this are CSS basics.

    CSS "background" is the shortcut for different background properties.

    Only use those shortcuts, when you understand CSS completely.



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 9, 2006
    #8
  9. Guest

    Re: Color computation - Beautiful !!

    > You should not, until you tested my code for yourself AS IS.
    > Only if you agree it "works", proceed.


    Ok

    > Talking about my code "not working" in your application will not be
    > usefull before that.


    :) I am always sure the code you provide works. My first though is try
    to find what I am doing in the wrong way.

    > Why this? perhaps it covers the following, I did not test that.
    > Leave the above div away!


    Yes I tried without that. It works just fine.

    > Scripts like thease should be in the <head> section.


    Yes I noticed the scripts are sometimes in the head and sometimes in
    the
    body. But I am not sure what difference it makes. And if there is a
    difference
    would it also apply to referenced JS files like in
    <script language="javascript" src="someFile.js"></script> ?

    > > I had the impression there was a block missing (perhaps was somehow
    > > covered).

    >
    > sorry?


    Yes am talking about my code: The first block (mine) was covering your
    first one. I did not expect that: I though your blocks would have just
    follow my existing block. But assumed wrong...

    > No. Please read up on CSS, this are CSS basics.
    >


    with masters like you guys in this group every other source is just
    useless.
    I have visited several group and this one is the most "simpatico"
    (dont' know the right translation) !!

    Thanks,

    -P
     
    , Sep 9, 2006
    #9
  10. Evertjan. Guest

    Re: Color computation - Beautiful !!

    wrote on 09 sep 2006 in comp.lang.javascript:

    > Yes I noticed the scripts are sometimes in the head and sometimes in
    > the body. But I am not sure what difference it makes.


    For the current browsers, which are very forgiving, it is not necessary I
    believe.

    However part of coding sanity is to make code that is pleasing to the eye
    and logical with indenting etc. Putting all javascriipt that does not
    document.write() in the <head> section is at least one such convention.

    The above simplifies debugging and is joyful per se.

    > And if there is a difference
    > would it also apply to referenced JS files like in
    > <script language="javascript" src="someFile.js"></script> ?


    That is the same, put that in the head too.

    Do not use referenced js until you are confortable with the infile code.
    it is far more bothersome to debug.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 9, 2006
    #10
  11. Evertjan. Guest

    Jim Land wrote on 09 sep 2006 in comp.lang.javascript:

    > Hmmm. Try:
    >
    > <SCRIPT TYPE="text/javascript">
    >
    > function showMe(x){
    > alert('backgroundColor = '+ x.style.backgroundColor);
    > }
    >
    > </SCRIPT>
    >
    > <div style='background-color:#c0c0c0;width:150px;'
    > onclick='showMe(this)'>
    > Click me to show my background color
    > </div>
    >
    > MSIE shows "#c0c0c0"
    >
    > FF shows "rgb(192,192,192)"


    Damn!

    Couldn't we persuade the powers-that-be to provide access to the 3 basic
    colours seperately?

    like:

    this.style.backgroundColor.red
    this.style.backgroundColor.green
    this.style.backgroundColor.blue



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 9, 2006
    #11
  12. Guest


    > >
    > > MSIE shows "#c0c0c0"
    > >
    > > FF shows "rgb(192,192,192)"

    >
    > Damn!


    Right.
    I just tried it: with Firefox your nice function seems to quit working.
    :(

    After all if Firefox converts always to rgb() one could argue that this
    could make more "omogeneous" the programming. The problem is that
    usually we want these things to work with all major browsers...

    So is the best approach to convert all to rgb() or should we test each
    time if is an hex representation or a rgb ?

    -P
     
    , Sep 9, 2006
    #12
  13. Evertjan. Guest

    wrote on 09 sep 2006 in comp.lang.javascript:

    >
    >> >
    >> > MSIE shows "#c0c0c0"
    >> >
    >> > FF shows "rgb(192,192,192)"

    >>
    >> Damn!

    >
    > Right.
    > I just tried it: with Firefox your nice function seems to quit working.
    > :(
    >
    > After all if Firefox converts always to rgb() one could argue that this
    > could make more "omogeneous" the programming. The problem is that
    > usually we want these things to work with all major browsers...
    >
    > So is the best approach to convert all to rgb() or should we test each
    > time if is an hex representation or a rgb ?


    I hate "best" approaches.


    <script type='text/javascript'>
    function invertMe(x){
    var t1 = '0123456789abcdef#'
    var t2 = 'fedcba9876543210#'
    var c = x.style.backgroundColor
    // begin FF patch
    if (/rgb/.test(c)) {
    c = c.replace(/rgb\(|\)/g,'').split(',')
    c = '#'+thex(c[0])+thex(c[1])+thex(c[2])
    }
    // end FF patch
    x.style.backgroundColor =
    c.replace( /./gi,
    function (s) {
    return t2.charAt(t1.indexOf(s));
    }
    )
    }

    function thex(x) {
    x = +x
    return (x>15)?x.toString(16):('0'+x.toString(16))
    }
    </script>

    <div style='background-color:#c0c0c0;width:250px;'
    onclick='invertMe(this)'>
    Click me to invert my background</div>
    <br><br>
    <div style='background-color:#fe3456;width:250px;'
    onclick='invertMe(this)'>
    Click me to invert my background</div>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 9, 2006
    #13
  14. Evertjan. wrote:
    > Jim Land wrote on 09 sep 2006 in comp.lang.javascript:

    <snip>
    >> MSIE shows "#c0c0c0"
    >>
    >> FF shows "rgb(192,192,192)"

    >
    > Damn!
    >
    > Couldn't we persuade the powers-that-be to provide access
    > to the 3 basic colours seperately?
    >
    > like:
    >
    > this.style.backgroundColor.red
    > this.style.backgroundColor.green
    > this.style.backgroundColor.blue


    The "powers-that-be" have defined a - RGBColor - interface which can be
    used to extract separate RGB colors form - style - objects. Eventually
    we may get to the point where browsers consistently implement that
    facility.

    Richard.
     
    Richard Cornford, Sep 9, 2006
    #14
  15. Guest

    Wow!
    I am so fashinated how one can do some complex task
    in just a couple of lines of code in javascript !

    If I had to do it, I would probably used both functions (Bart's and
    yours)
    after checking the first char. Which, if works, is probably less
    elegant ...

    It will probably take me some days to understand exactly
    what's going on there :)

    Fantastic!

    -P

    Evertjan. ha scritto:

    > wrote on 09 sep 2006 in comp.lang.javascript:
    >
    > >
    > >> >
    > >> > MSIE shows "#c0c0c0"
    > >> >
    > >> > FF shows "rgb(192,192,192)"
    > >>
    > >> Damn!

    > >
    > > Right.
    > > I just tried it: with Firefox your nice function seems to quit working.
    > > :(
    > >
    > > After all if Firefox converts always to rgb() one could argue that this
    > > could make more "omogeneous" the programming. The problem is that
    > > usually we want these things to work with all major browsers...
    > >
    > > So is the best approach to convert all to rgb() or should we test each
    > > time if is an hex representation or a rgb ?

    >
    > I hate "best" approaches.
    >
    >
    > <script type='text/javascript'>
    > function invertMe(x){
    > var t1 = '0123456789abcdef#'
    > var t2 = 'fedcba9876543210#'
    > var c = x.style.backgroundColor
    > // begin FF patch
    > if (/rgb/.test(c)) {
    > c = c.replace(/rgb\(|\)/g,'').split(',')
    > c = '#'+thex(c[0])+thex(c[1])+thex(c[2])
    > }
    > // end FF patch
    > x.style.backgroundColor =
    > c.replace( /./gi,
    > function (s) {
    > return t2.charAt(t1.indexOf(s));
    > }
    > )
    > }
    >
    > function thex(x) {
    > x = +x
    > return (x>15)?x.toString(16):('0'+x.toString(16))
    > }
    > </script>
    >
    > <div style='background-color:#c0c0c0;width:250px;'
    > onclick='invertMe(this)'>
    > Click me to invert my background</div>
    > <br><br>
    > <div style='background-color:#fe3456;width:250px;'
    > onclick='invertMe(this)'>
    > Click me to invert my background</div>
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
     
    , Sep 9, 2006
    #15
  16. Guest

    btw
    what is the purpose of that statement:
    x = +x
    is that some kind of conversion or what?

    -P


    ha scritto:

    > Wow!
    > I am so fashinated how one can do some complex task
    > in just a couple of lines of code in javascript !
    >
    > If I had to do it, I would probably used both functions (Bart's and
    > yours)
    > after checking the first char. Which, if works, is probably less
    > elegant ...
    >
    > It will probably take me some days to understand exactly
    > what's going on there :)
    >
    > Fantastic!
    >
    > -P
    >
    > Evertjan. ha scritto:
    >
    > > wrote on 09 sep 2006 in comp.lang.javascript:
    > >
    > > >
    > > >> >
    > > >> > MSIE shows "#c0c0c0"
    > > >> >
    > > >> > FF shows "rgb(192,192,192)"
    > > >>
    > > >> Damn!
    > > >
    > > > Right.
    > > > I just tried it: with Firefox your nice function seems to quit working.
    > > > :(
    > > >
    > > > After all if Firefox converts always to rgb() one could argue that this
    > > > could make more "omogeneous" the programming. The problem is that
    > > > usually we want these things to work with all major browsers...
    > > >
    > > > So is the best approach to convert all to rgb() or should we test each
    > > > time if is an hex representation or a rgb ?

    > >
    > > I hate "best" approaches.
    > >
    > >
    > > <script type='text/javascript'>
    > > function invertMe(x){
    > > var t1 = '0123456789abcdef#'
    > > var t2 = 'fedcba9876543210#'
    > > var c = x.style.backgroundColor
    > > // begin FF patch
    > > if (/rgb/.test(c)) {
    > > c = c.replace(/rgb\(|\)/g,'').split(',')
    > > c = '#'+thex(c[0])+thex(c[1])+thex(c[2])
    > > }
    > > // end FF patch
    > > x.style.backgroundColor =
    > > c.replace( /./gi,
    > > function (s) {
    > > return t2.charAt(t1.indexOf(s));
    > > }
    > > )
    > > }
    > >
    > > function thex(x) {
    > > x = +x
    > > return (x>15)?x.toString(16):('0'+x.toString(16))
    > > }
    > > </script>
    > >
    > > <div style='background-color:#c0c0c0;width:250px;'
    > > onclick='invertMe(this)'>
    > > Click me to invert my background</div>
    > > <br><br>
    > > <div style='background-color:#fe3456;width:250px;'
    > > onclick='invertMe(this)'>
    > > Click me to invert my background</div>
    > >
    > >
    > > --
    > > Evertjan.
    > > The Netherlands.
    > > (Please change the x'es to dots in my emailaddress)
     
    , Sep 9, 2006
    #16
  17. Guest

    Evertjan. напиÑав:
    > function invertMe(x){
    > var t1 = '0123456789abcdef#'
    > var t2 = 'fedcba9876543210#'
    > var c = x.style.backgroundColor
    > // begin FF patch
    > if (/rgb/.test(c)) {
    > c = c.replace(/rgb\(|\)/g,'').split(',')
    > c = '#'+thex(c[0])+thex(c[1])+thex(c[2])
    > }
    > // end FF patch
    > x.style.backgroundColor =
    > c.replace( /./gi,
    > function (s) {
    > return t2.charAt(t1.indexOf(s));
    > }
    > )
    > }
    >
    > function thex(x) {
    > x = +x
    > return (x>15)?x.toString(16):('0'+x.toString(16))
    > }
    > </script>
    >
    > <div style='background-color:#c0c0c0;width:250px;'
    > onclick='invertMe(this)'>
    > Click me to invert my background</div>
    > <br><br>
    > <div style='background-color:#fe3456;width:250px;'
    > onclick='invertMe(this)'>
    > Click me to invert my background</div>


    I believe that inverting color must be simpler.
    Just an idea:

    var hexColor="FFAA55"
    var invertedColor=0xFFFFFF-parseInt(hexColor,16)
    //now we just have to set leading zeroes if needed

    In RGB color+invertedColor=white, isn't it?
    Then invertedColor=white-color
     
    , Sep 9, 2006
    #17
  18. Guest

    напиÑав:
    > Evertjan. напиÑав:
    > > function invertMe(x){
    > > var t1 = '0123456789abcdef#'
    > > var t2 = 'fedcba9876543210#'
    > > var c = x.style.backgroundColor
    > > // begin FF patch
    > > if (/rgb/.test(c)) {
    > > c = c.replace(/rgb\(|\)/g,'').split(',')
    > > c = '#'+thex(c[0])+thex(c[1])+thex(c[2])
    > > }
    > > // end FF patch
    > > x.style.backgroundColor =
    > > c.replace( /./gi,
    > > function (s) {
    > > return t2.charAt(t1.indexOf(s));
    > > }
    > > )
    > > }
    > >
    > > function thex(x) {
    > > x = +x
    > > return (x>15)?x.toString(16):('0'+x.toString(16))
    > > }
    > > </script>
    > >
    > > <div style='background-color:#c0c0c0;width:250px;'
    > > onclick='invertMe(this)'>
    > > Click me to invert my background</div>
    > > <br><br>
    > > <div style='background-color:#fe3456;width:250px;'
    > > onclick='invertMe(this)'>
    > > Click me to invert my background</div>

    >
    > I believe that inverting color must be simpler.
    > Just an idea:
    >
    > var hexColor="FFAA55"
    > var invertedColor=0xFFFFFF-parseInt(hexColor,16)
    > //now we just have to set leading zeroes if needed
    >
    > In RGB color+invertedColor=white, isn't it?
    > Then invertedColor=white-color

    //I forgot: we need to convert it to hex string
    var invertedColor=(0xFFFFFF-parseInt(hexColor,16)).toString(16)
    //now we just have to add leading zeroes if needed
     
    , Sep 9, 2006
    #18
  19. JRS: In article <>
    , dated Sat, 9 Sep 2006 02:41:12 remote, seen in
    news:comp.lang.javascript, posted :

    >How can I invert that background color "anyColorHere" ? Can you point
    >(or suggest) a script
    >that does that in a proper way ?


    You read the initial colour numerically; you invert the number; you
    write the number back.

    BUT : Think carefully about what inversion should mean.

    Consider first just the pure red component, which will be a number in
    the range 0x00 to 0xFF.

    If you want to make light be dark, dark be light, and middling be
    middling, then subtract the number from 0xFF.

    If you want to change any colour to be a substantially different colour,
    then XOR the number with 0x80.


    In each case you might either treat the whole colour as being
    represented by three separate components, and do three small
    arithmetics; or you can treat it as one Hex number and use one large
    arithmetic - XOR with 0x808080 or subtract from 0xFFFFFF.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
    Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
    PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
    My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
     
    Dr John Stockton, Sep 9, 2006
    #19
  20. Evertjan. Guest

    wrote on 09 sep 2006 in comp.lang.javascript:

    > what is the purpose of that statement:
    > x = +x
    > is that some kind of conversion or what?
    >


    [please do not toppost on usenet]

    Conversion of string to number.
    The + here is an unary +.

    These values come as a string
    and comparing strings would give unexpected results.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 9, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    2
    Views:
    2,328
    joris
    Mar 24, 2010
  2. le Cl?
    Replies:
    15
    Views:
    3,156
    Michel
    Apr 11, 2009
  3. Jesper Sahner

    "Symbolic computation"

    Jesper Sahner, Oct 23, 2004, in forum: Java
    Replies:
    3
    Views:
    446
  4. Aaron Fude
    Replies:
    10
    Views:
    574
    Mark Thornton
    Dec 20, 2004
  5. Kamaljeet Saini
    Replies:
    0
    Views:
    445
    Kamaljeet Saini
    Feb 13, 2009
Loading...

Share This Page