vendredi 4 mai 2018

If statement not changing value of a variable Javascript

I am trying to create some variables to use for HSL colors in Three.js. I want to make sure they are not too dark or too light, so I created some if statements to check/change the variable if the numbers are out of my range.

I don't want the value to be below 0.1 or above 0.9. But it doesn't appear to be changing the variables and I can't figure out why.

color1h = (data[0] / 359);
color1s = (data[1] / 255);
color1l = (data[2] / 255);

if (color1s < 0.1){color1s += 0.1;}
if (color1s > 0.9){color1s -= 0.1;}
if (color1l < 0.1){color1s += 0.1;}
if (color1l > 0.9){color1s -= 0.1;}
console.log(color1h, color1s, color1l);

Aucun commentaire:

Enregistrer un commentaire