Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Calculating the darker or lighter version of a color

    Help
    3
    9
    422
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ITzTravelInTime
      ITzTravelInTime F last edited by

      Hi, in my text based game i need to calculate the darker and lighter version of a color stored into a variable, so how the colour representation works? and how can i do this calculation?

      1 Reply Last reply Reply Quote 1
      • ITzTravelInTime
        ITzTravelInTime F last edited by

        For the actual calculation i just need to get the RGB values for the color and increase them using the same constant value, but the problem is getting those values, settimg them is quite straight forward as i saw in the documentation

        1 Reply Last reply Reply Quote 1
        • Eearslya
          Eearslya Donator last edited by

          Colors are just stored as vector objects. So it's fairly easy to get the values simply by using r, g, b, and a.

          myColor = white
          red = myColor.r
          

          The individual r/g/b/a colors are stored as values between 0 and 1, so to get the actual RGB value, you'd need to multiply by 255. For example, white.r is 1.000000. So, multiplied by 255 would be 255, the expected value for white.

          1 Reply Last reply Reply Quote 1
          • ITzTravelInTime
            ITzTravelInTime F last edited by

            thank you very mutch, it will help with parts in which you can sneak under things.

            1 Reply Last reply Reply Quote 0
            • Jaywalker
              Jaywalker Donator last edited by Jaywalker

              I actually just wrote a function that turns a HSL (hue, saturation, lightness) to RGB

              function HSL2RGB(h, s, l, a)
              float v
              float r = l
              float g = l
              float b = l
              if l <= 0.5 then 
                  v = l * (1.0 + s)
              else
                  v = l + s - (l * s)
              endif
              if v > 0 then
                  float m
                  float sv
                  int sextant
                  float frct
                  float vsf
                  float mid1
                  float mid2
                  
                  m = l + l - v
                  sv = (v - m) / v
                  h = h * 6.0
                  sextant = floor(h)
                  frct = h - sextant
                  vsf = v * sv * frct
                  mid1 = m + vsf
                  mid2 = v - vsf
                  if sextant == 0 then
                      r = v
                      g = mid1
                      b = m
                  else if sextant == 1 then
                      r = mid2
                      g = v
                      b = m
                  else if sextant == 2 then
                      r = m
                      g = v
                      b = mid1
                  else if sextant == 3 then
                      r = m
                      g = mid2
                      b = v
                  else if sextant == 4 then
                      r = mid1
                      g = m
                      b = v
                  else if sextant == 5 then
                      r = v
                      g = m
                      b = mid2
                  else
                      r = v
                      g = m
                      b = mid2
                  endif endif endif endif endif endif
              endif
              print("R: " + r + " G: " + g + " B: " + b + " A: " + a + " V: " + v + "  " + " H: " + h + "\n" )
              vector color = {r, g, b, a}
              return color
              

              so if you have something that is red it would look like HSL2RGB(0, 1, 0.5, 1)
              The l parameter is used for how light/dark that color is
              You can check those values here: http://hslpicker.com/#f00

              1 Reply Last reply Reply Quote 3
              • Jaywalker
                Jaywalker Donator last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • Jaywalker
                  Jaywalker Donator last edited by

                  @ITzTravelInTime does that work for you?

                  ITzTravelInTime 1 Reply Last reply Reply Quote 0
                  • ITzTravelInTime
                    ITzTravelInTime F @Jaywalker last edited by

                    @Jaywalker I just used a simpler algorith i found online, i just needed the RGB components

                    1 Reply Last reply Reply Quote 0
                    • Jaywalker
                      Jaywalker Donator last edited by

                      Okay good :)

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post