Results 1 to 7 of 7

Thread: Color to Hue and Saturation.

  1. #1
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default Color to Hue and Saturation.

    Anyone know how to get the Hue and Saturation from a color without using simba?

  2. #2
    Join Date
    Feb 2012
    Location
    Discord
    Posts
    3,114
    Mentioned
    37 Post(s)
    Quoted
    538 Post(s)

    Default

    [5:53:48 PM] Olly: Kasi its called a brain sir
    [5:53:56 PM] Olly: i can work out the hue/mod just by looking at a colour
    [5:54:12 PM] Kasi Reddy: genius, tell me how to do it?
    [5:55:23 PM] Olly: by going to school, the blue of your skype name has a hue of 0.02 and a sat mod of 1.14
    [5:55:43 PM] Steven: meh
    [5:55:48 PM] Steven: i dont think i could ever do that
    [5:55:56 PM] Steven: mainly cause im colour blind

    ^skype chat :P
    anyway tried googling it? are you able to use other programs to do this?

  3. #3
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

  4. #4
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by The Killer View Post
    anyway tried googling it? are you able to use other programs to do this?
    Nope

    Already had a look at it, was quite confusing :S

  5. #5
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by Kasi View Post
    Nope



    Already had a look at it, was quite confusing :S
    Well that is the formula, here it is in simba's source: https://github.com/MerlijnWajer/Simb..._conv.pas#L205

    As you can see, the integer color is first converted to rgb then to hsl.

  6. #6
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by mormonman View Post
    Well that is the formula, here it is in simba's source: https://github.com/MerlijnWajer/Simb..._conv.pas#L205

    As you can see, the integer color is first converted to rgb then to hsl.
    :P Thanks repped. tried looking before but couldnt find.

  7. #7
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I explained it before. But okay, let's do it again cause I am in a good mood ^^

    First you take a color, in this example (red: 222, blue: 124, green:180)

    We have to convert those components to a percentage. So a number between the 0 and the 1.

    redP = 222 / 255;
    blueP = 124 / 255;
    greenP = 180 / 255;


    The we have to get the highest and lowest component. In this case:

    lowComp = blueP
    highComp = redP


    L(lightness) can already be calculated.

    L = 0.5 * (highComp + lowComp)

    In this case L will be:

    L = 0.5 * ((222 / 255) + (124 / 255)) = 0.72156862745098039215686274509804

    We then proceed to calculate the difference between the highest and the lowest component.

    Diff = highComp - lowComp

    In this case that will be:

    Diff = (222 / 255) - (124 / 255) = 0,48627450980392156862745098039216

    if L(ligtness) is less then 0.5, the sat component can be calculated as:

    sat = Diff / (highComp + lowComp)

    if the color is darker, and thus L > 0.5, the sat component can be calculated as:

    sat = Diff / (2 - highComp - lowComp);

    In this case the color is darker, so we use the second formula.

    sat = Diff / (2 - (222 / 255) - (124 / 255)) = 0,84722222...2

    Jeej!!! Now the only thing to calculate is hue. This is also the hardest one, but let's see. The formula we use depends on which color is highComp.

    If highComp is redP then:

    hue = ((greenP - blueP ) / Diff) / 6

    If highComp is greenP then:

    hue = (2 + (blueP - redP ) / Diff) / 6

    If highComp is blueP then:

    hue = (4 + (redP - greenP ) / Diff) / 6

    In this case the highComp is redP. So we use the first formule:

    hue = (((180 / 255) - (124 / 255)) / Diff) / 6) = 0,07650273224043715846994535519126

    The simba function(RGBToHSL):
    Simba Code:
    program new;
    var
      h, s, l: Extended;
      R,  G,  B,   D,  Cmax, Cmin: Extended;

    begin
      R := 244 / 255;
      G := 180 / 255;
      B := 124 / 255;
      CMin := R;
      if G < Cmin then Cmin := G;
      if B  < Cmin then Cmin := B;
      CMax := R;
      if G > Cmax then Cmax := G;
      if B  > Cmax then Cmax := B;
      L := 0.5 * (Cmax + Cmin);
      if Cmax = Cmin then
      begin
        H := 0;
        S := 0;
      end else
      begin
        D := Cmax - Cmin;
        if L < 0.5 then
          S := D / (Cmax + Cmin)
        else
          S := D / (2 - Cmax - Cmin);
        if R = Cmax then
          H := (G - B) / D
        else
          if G = Cmax then
            H  := 2 + (B - R) / D
          else
            H := 4 +  (R - G) / D;
        H := H / 6;
        if H < 0 then
          H := H + 1;
      end;
      writeln(h);
      writeln(s);
      writeln(l);
    end.

    edit:

    ninja'd. Reminder to myself, don't spend to much time replying.
    Working on: Tithe Farmer

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •