tag:blogger.com,1999:blog-17722541.post1737089480957997022..comments2023-10-30T12:41:52.941+01:00Comments on don't code today what you can't debug tomorrow: Converting between HSL and HSVAriya Hidayathttp://www.blogger.com/profile/03121582140059106015noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-17722541.post-9611133815978607462011-02-13T19:17:29.697+01:002011-02-13T19:17:29.697+01:00thanks for sharing,
I use it in Quartz Composer (...thanks for sharing,<br /><br />I use it in Quartz Composer (OSX) to convert from HSV (sent from a Cocoa App) to HSL.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-17722541.post-11158165300058654382010-10-24T22:40:30.430+02:002010-10-24T22:40:30.430+02:00Thanks for the code, it works beautifully. It'...Thanks for the code, it works beautifully. It's great for doing fades from white or black to a particular color.<br /><br />Anonymous: there's really no excuse for being a jerk. At the very least, you could have posted your correction.Alanhttps://www.blogger.com/profile/06890334386433381366noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-71080610824553157782010-03-12T07:15:49.202+01:002010-03-12T07:15:49.202+01:00Sorry for my blunt reaction, I was kind of on a ti...Sorry for my blunt reaction, I was kind of on a tight schedule working on an important project. In quick need for such a piece of code, I incorrectly assumed that your code was working correctly. Unfortunately I ended up studying the wiki article and writing up basically the same code you did, with an additional omission of the zero division occurence. What I meant to say is that you should update the code to cope with the division by zero, because based on the title and description above the code and the fact that you bothered to put it online, one would generally assume that it's a fully working piece of code (which it almost is).<br />And something trivial can still be quite labourous, so why reinvent the wheel. Would you rather use a pen instead of a Xerox-machine when copying a page from the phonebook? :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-17722541.post-62669460774711720312010-03-04T03:41:52.378+01:002010-03-04T03:41:52.378+01:00@Anonymous: Can't you read? Which part of &quo...@Anonymous: Can't you read? Which part of "Error checking is left as an exercise to the reader" is not clear to you? And if this code is so trivial, why did you copy+paste blindly instead of solving it yourself?Ariya Hidayathttps://www.blogger.com/profile/03121582140059106015noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-46541341382399380582010-03-04T03:37:33.528+01:002010-03-04T03:37:33.528+01:00'...no point wasting minutes for something tha...'...no point wasting minutes for something that (should be trivial).'<br />I totally agree with you. And also: <br /><i><br />if (trivial_problem && buggy_code) bad_programmer = true;<br />if (bad_programmer)<br />debug();<br /></i><br />I copy pasted your code and got an error (or does your machine divide by zero?). I had to waste time. Please stop posting crap that somehow show's up high in Google.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-17722541.post-33014205205592731822009-04-21T19:52:00.000+02:002009-04-21T19:52:00.000+02:00@Lea: no, it is not wrong. Hint: read the code mor...@Lea: no, it is not wrong. Hint: read the code more carefully :-)Ariya Hidayathttps://www.blogger.com/profile/03121582140059106015noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-3166994332365143042009-03-26T19:07:00.000+01:002009-03-26T19:07:00.000+01:00The second one doesn't seem to be correct: HSL's s...The second one doesn't seem to be correct: HSL's saturation doesn't influence the result at all (since it gets overwriten)...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-17722541.post-50121417602354889982008-08-07T14:38:00.000+02:002008-08-07T14:38:00.000+02:00Note that two special cases need to be handled to ...Note that two special cases need to be handled to avoid a division by zero error: when the V or L values are 0.Stephen Morleyhttps://www.blogger.com/profile/11310746618647134583noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-13689795778629278972008-08-04T16:42:00.000+02:002008-08-04T16:42:00.000+02:00I've used these algorithms (in their less symmetri...I've used these algorithms (in their less symmetrical form) in my JavaScript Colour functions:<BR/><BR/>http://www.safalra.com/web-design/javascript/colour-handling-and-processing/<BR/><BR/>Thanks so much for providing these algorithms - they reduced the hassle of writing the code.Stephen Morleyhttps://www.blogger.com/profile/11310746618647134583noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-59110901434956056332008-07-31T00:39:00.000+02:002008-07-31T00:39:00.000+02:00@Safalra: ll doubling is not necessary, but it kee...@Safalra: ll doubling is not necessary, but it keeps the symmetry (with the first function).Ariya Hidayathttps://www.blogger.com/profile/03121582140059106015noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-66327277720985719332008-07-29T17:33:00.000+02:002008-07-29T17:33:00.000+02:00There seems to be little point in doubling ll in t...There seems to be little point in doubling ll in the second algorithm. This functions identically and is simpler:<BR/><BR/>*h = hh;<BR/>ss *= (ll <= 0.5) ? ll : 1 - ll;<BR/>*v = ll + ss;<BR/>*s = 2 * ss / (ll + ss);Stephen Morleyhttps://www.blogger.com/profile/11310746618647134583noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-84246522600372974302008-07-29T16:32:00.000+02:002008-07-29T16:32:00.000+02:00Thank you so much for this algorithm. It's amazing...Thank you so much for this algorithm. It's amazing that the information doesn't seem to be anywhere else on the internet - just dozens of pages saying to convert to RGB and then convert back.Stephen Morleyhttps://www.blogger.com/profile/11310746618647134583noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-58472875086120962612008-07-03T01:48:00.000+02:002008-07-03T01:48:00.000+02:00The trailing zero is actually redundant, C/C++ als...The trailing zero is actually redundant, C/C++ also accepts just 1. and 2. without the zero.Kevin Koflerhttps://www.blogger.com/profile/00136078113749660013noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-72734273657617885172008-07-03T01:33:00.000+02:002008-07-03T01:33:00.000+02:00@Gunni: it's a floating point operation, so the re...@Gunni: it's a floating point operation, so the result should stay floating point (otherwise, something weird with the compiler)Ariya Hidayathttps://www.blogger.com/profile/03121582140059106015noreply@blogger.comtag:blogger.com,1999:blog-17722541.post-45325169110548697152008-07-02T14:14:00.000+02:002008-07-02T14:14:00.000+02:00MAybe you should use 2.0 instead of 2 (and similar...MAybe you should use 2.0 instead of 2 (and similar with other literals)<BR/>IIRC otherwise the literal can be taken as an integer, and then the result will be an integer, too. Maybe it does work here, but later on, maybe this will result in an difficult to find error.<BR/><BR/>GunniAnonymousnoreply@blogger.com