void SetColor(PointF mousepoint) { if (WheelRectangle.Contains(mousepoint) == false) { return; } PointF center = Util.Center(ColorWheelRectangle); double radius = Radius(ColorWheelRectangle); double dx = Math.Abs(mousepoint.X - center.X); double dy = Math.Abs(mousepoint.Y - center.Y); double angle = Math.Atan(dy / dx) / Math.PI * 180; double dist = Math.Pow((Math.Pow(dx, 2) + (Math.Pow(dy, 2))), 0.5); double saturation = dist / radius; //if (dist > radius + 5) // give 5 pixels slack // return; if (dist < 6) { saturation = 0; // snap to center } if (mousepoint.X < center.X) { angle = 180 - angle; } if (mousepoint.Y > center.Y) { angle = 360 - angle; } SelectedHSLColor = new HSLColor(angle, saturation, SelectedHSLColor.Lightness); }
private void SetColour(PointF mousePoint) { if (WheelRectangle.Contains(mousePoint) == false) { return; } PointF centre = Utilities.Centre(ColourWheelRectangle); double radius = Radius(ColourWheelRectangle), dX = Math.Abs(mousePoint.X - centre.X), dY = Math.Abs(mousePoint.Y - centre.Y), angle = Math.Atan(dX / dY) / Math.PI * 180, dist = Math.Pow((Math.Pow(dX, 2) + (Math.Pow(dY, 2))), 0.5), saturation = dist / radius; if (dist < 6) { saturation = 0; } if (mousePoint.X < centre.X) { angle = 180 - angle; } if (mousePoint.Y > centre.Y) { angle = 360 - angle; } SelectedHSLColour = new HSLColour(angle, saturation, SelectedHSLColour.Luminosity); }