1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

B Color shading

  1. Dec 15, 2017 #1
    I have a long thin shape (rope, bar). The color of the shape changes smoothly from red (RGB=255 0 0) at one end to yellow (RGB=255 255 0) at the other. I need an equation that will allow me to adjust the G value from 0 to 255 in a way that I can choose where on the shape it has the value 127.5 (equal parts red and yellow, RGB = 255 128 0), if the 127.5 is rounded.

    The linear equation y = 255x + 0 places that point at the midpoint (0.5) of the shape. The rounded values at 0.1 intervals are:
    Color shading.jpg

    I would like an equation that will enable me to place the G=127.5 value anywhere on that shape from 0.0 to 1.0. I'm not sure if a quadratic equation is the best choice or some type of exponential. For the quadratic, I would have three points ((0.0), (k,127.5), (1,255)) and could solve 3 equations in 3 unknowns.

    Is there a better way?

  2. jcsd
  3. Dec 15, 2017 #2


    User Avatar
    2017 Award

    Staff: Mentor

    In general a quadratic equation will go to negative values if your midpoint is too close to the 255 side, and above 255 if it is tooclose to the right side. You could use two linear relations left and right of it, or use a spline.

    An exponential distribution with an offset (##a+e^{bx+c}##) would work as well.
  4. Dec 15, 2017 #3
    Yeah, after some testing, I discovered that the quadratic is not a good choice.

    I'm not sure what you mean by two linear relations, but a spline might be a good choice. I didn't think of that. Thanks.

    Another good suggestion. Thanks.
  5. Dec 15, 2017 #4


    User Avatar
    2017 Award

    Staff: Mentor

    G(x)=c*x up to the fixed point in the middle, and G(x)=a+b*x from there to the end (where a+b=255 to satisfy G(1)=255).
  6. Dec 16, 2017 #5
    Got it, thanks.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Threads for Color shading Date
Generating 1/f^b colored time series Mar 3, 2015
Color Permutations In Row Of 6 Red, 3 Blue, 3 Green Flower Pots ? Sep 24, 2014
4-color theorem Oct 25, 2011
Color convergence Oct 15, 2011