Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 4 of 4
Thread: please write me a code

10242006, 07:27 PM #1
 Join Date
 Oct 2006
 Posts
 3
 Thanks
 0
 Thanked 0 Times in 0 Posts
please write me a code
Hi.
I have a tutorial how to convert rgb to hsl. Could anyone write it in Javascript for me?
RGB  HSL
1. Convert the RBG values to the range 01
Example: from the video colors page, colorbar red has R=83%, B=7%, G=7%, or in this scale, R=.83, B=.07, G=.07
2. Find min and max values of R, B, G
In the example, maxcolor = .83, mincolor=.07
3. L = (maxcolor + mincolor)/2
For the example, L = (.83+.07)/2 = .45
4. If the max and min colors are the same (ie the color is some kind of grey), S is defined to be 0, and H is undefined but in programs usually written as 0
5. Otherwise, test L.
If L < 0.5, S=(maxcolormincolor)/(maxcolor+mincolor)
If L >=0.5, S=(maxcolormincolor)/(2.0maxcolormincolor)
For the example, L=0.45 so S=(.83.07)/(.83+.07) = .84
6. If R=maxcolor, H = (GB)/(maxcolormincolor)
If G=maxcolor, H = 2.0 + (BR)/(maxcolormincolor)
If B=maxcolor, H = 4.0 + (RG)/(maxcolormincolor)
For the example, R=maxcolor so H = (.07.07)/(.83.07) = 0
7. To use the scaling shown in the video color page, convert L and S back to percentages, and H into an angle in degrees (ie scale it from 0360). From the computation in step 6, H will range from 06. RGB space is a cube, and HSL space is a double hexacone, where L is the principal diagonal of the RGB cube. Thus corners of the RGB cube; red, yellow, green, cyan, blue, and magenta, become the vertices of the HSL hexagon. Then the value 06 for H tells you which section of the hexgon you are in. H is most commonly given as in degrees, so to convert
H = H*60.0
If H is negative, add 360 to complete the conversion.

10242006, 07:52 PM #2
 Join Date
 Jun 2002
 Location
 London, England
 Posts
 19,455
 Thanks
 217
 Thanked 2,699 Times in 2,675 Posts
Sorry, we are not here to do your homework for you. See the rules:
1.5) No homework assignments  Do not post your entire homework assignment and request that other members do it for you. This is considered cheating, and your thread may even be used by your school to prove your guilt. Now, you may ask for advice or help on a specific aspect of your assignment that you're having trouble with. Use common sense as far as what's acceptable in terms of soliciting help with homework assignments.

10242006, 09:03 PM #3
 Join Date
 Mar 2006
 Posts
 730
 Thanks
 36
 Thanked 132 Times in 123 Posts
You need to change your major from programming to management...

10272006, 09:35 PM #4
 Join Date
 May 2003
 Posts
 15
 Thanks
 0
 Thanked 0 Times in 0 Posts
Sure:
<a href="javascript:onClick=alert('I will do my own homework.')">Write Code</a>