Note that there are some explanatory texts on larger screens.

plurals
  1. POA boolean function for finding if a HSL based color is near to another color
    primarykey
    data
    text
    <p>I wanted to write a function which could check if color is close to a background color.</p> <p>For this i make use of the HSL color scheme, let me explain that a bit; HSL colors are defined as Hue Saturation and lightness. In short Hue tells you which color of the rainbow is used and its in the range 0 to 360. And its on the Hue that i would like check.</p> <p>So Saturation how strong the color is, like pure or mixed with grey or Lightness which speaks for itself are not compared. I only want to check for Hue. At first i wrote a Near function like this:</p> <pre><code>Private boolean Near(int background, int mycolor, int difference) { if(math.abs( background - mycolor)&lt;difference){return true;}else{return false} } </code></pre> <p>Later i realized this is wrong. Because HSL is like the image below you see in there the colors are as a circle, so starting at red 0 and it is red again at 360. So a Hue value of 358 and 4 are close together, the above function wouldn't reflect that.</p> <p>(Saturation goes to the center 0..100 lightens 0..100 is like going up or down and Hue is from 0 to 360 degrees around. )</p> <p><img src="https://i.stack.imgur.com/UA7Jx.png" alt="enter image description here"></p> <p>I could rewrite a function with a large if then construction, so that for example if the background where red 5 and the allowed difference is 20 then <code>mycolor</code> would be in range if it is &lt; 5+20 or > (360-(5-20)) .. so making a special construction if the Hue difference would be crossing the 0 or 360 limits.</p> <p>Well that would work, but then i wondered might it be possible to replace such "if then" construction with a modulo calculation in a single line ?, it keeps me wondering still As modulo computations can be used to check within a border and if its over the border of 360 it would be red again close to zero, </p> <p>well i think so, such line might also contain some AND or OR and subtractions or ABS functions..might it be possible to write it in one comparison line ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload