Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 5 additions & 32 deletions src/ControlzEx/Theming/HSLColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public HSLColor(Color color)
this.H = 60 * (((double)(r - g) / delta) + 4);
}

if (this.H < 0)
{
this.H += 360;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to just set it to 0 in this case?
I am no color expert, but i wouldn't expect it to just add 360.
In which cases can it even go below 0?
To be honest i just copied the code without understanding much about HSL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @batzen consider the Hue range to be a circle. If you have negative hue due to the formulas are not using absolute values, you may get negative Hue. In this case you would just go in the opposite direction on the color wheel. Adding 360° will not change the Hue but makr it positve.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @batzen ,
I modified my ColorPicker example where I use HSV-Color. The Hue is calculated the same way as in the HSL struckt.

Without adding +360°:
ColorPicker_01

With adding +360°:*
ColorPicker_02

Hue wheel:
image

I hope this helps for better understanding.

Have a nice Sunday
Tim

// Calculate L
this.L = (1d / 2d * (max + min)) / 255d;

Expand Down Expand Up @@ -158,38 +163,6 @@ private byte GetColorComponent(int n)
double k = (n + H / 30) % 12;

return (byte)Math.Round (255 * (L - a * Math.Max(-1, Math.Min(k - 3, Math.Min(9 - k, 1)))));


//if (t3 < 0)
//{
// t3 += 1.0;
//}

//if (t3 > 1)
//{
// t3 -= 1.0;
//}

//double colorComponent;

//if (6.0 * t3 < 1)
//{
// colorComponent = t2 + (t1 - t2) * 6.0 * t3;
//}
//else if (2.0 * t3 < 1)
//{
// colorComponent = t1;
//}
//else if (3.0 * t3 < 2)
//{
// colorComponent = t2 + (t1 - t2) * (2.0 / 3.0 - t3) * 6.0;
//}
//else
//{
// colorComponent = t2;
//}

//return (byte)Math.Round(255 * colorComponent);
}
}
}