private void CheckMouse(MouseEventArgs e) { if ((MouseButtons & MouseButtons.Left) != 0) { if (!clickNothing) { if (clickCircle) { _currentHue = (short)WrapDegree((int)AngleFromPoints(e.Location)); rotatePoint = true; OnHSVChanged(EventArgs.Empty); setPoint(); } } if (!drawPoint) { drawPoint = clickTriangle; } if (clickTriangle) { PointF pt = ClipPoint(e.Location, _currentHue); rotatePoint = false; initRot = _currentHue; CurrentHSV = ColorHSVForLocation(pt.X, pt.Y, _currentHue); } } }
public static Color Negative(ColorManager.HSVColor c) //haha this isnt even negative LOL { Color rgb = ColorManager.HSVtoRGB(c); if (Intensity(rgb.R, rgb.G, rgb.B) > 0.5f) { return(Color.Black); } else { return(Color.White); } }
public static Bitmap ColorWheel(int size, int width, int multisampling) { if (width < 1 || size < 1) { return(null); } int m = multisampling; size = size * m; width = width * m; using (var b = new Bitmap(size, size)) { using (Graphics g = Graphics.FromImage(b)) { g.Clear(Color.Transparent); var rect = new Rectangle(0, 0, size - m, size - m); using (var wheel_path = new GraphicsPath()) { wheel_path.AddEllipse(rect); wheel_path.Flatten(); int num_pts = (wheel_path.PointCount - 1); var surround_colors = new Color[wheel_path.PointCount]; for (int i = 0; i < wheel_path.PointCount; i++) { surround_colors[i] = new ColorManager.HSVColor((short)((double)i / num_pts * 360), 100, 100).ToColor(); } using (var brush = new PathGradientBrush(wheel_path)) { brush.CenterColor = SystemColors.Window; brush.SurroundColors = surround_colors; brush.FocusScales = new PointF(100.0f, 100.0f); g.FillEllipse(brush, rect); } using (var brush = new SolidBrush(Color.White)) g.FillEllipse(brush, new Rectangle(width, width, size - width * 2, size - width * 2)); //replace all the white with color.transparent :) b.MakeTransparent(Color.White); } } return(ColorPickUtil.ResizeImage(b, size / m)); } }
public PointF LocationForColorHSV(ColorManager.HSVColor hsv) { /*PointF[] polygon = Triangle(0); * float x = (float)((((float)hsv.S / 100.0f) * (polygon[0].X - polygon[1].X)) + polygon[1].X); * //if (x > polygon[0].X) * // x = polygon[0].X; * * PointF p = ColorPickUtil.RotatePoint(polygon[0], new PointF(Width / 2, Height / 2), ColorPickUtil.DegreeToRadian(30)); * * float y = (float)(((float)hsv.V / 100.0f) * (Triangle(30)[1].Y + thickness)); * //if (y > Triangle(30)[1].Y) * // y = Triangle(30)[1].Y; * * float height = (polygon[1].Y - polygon[2].Y - thickness); * p.Y = y + (height / 2); * * p = ColorPickUtil.RotatePoint(p, new PointF(Width/2, Height/2), ColorPickUtil.DegreeToRadian(-30)); * * return new PointF(x, p.Y);*/ PointF[] InnerPoints = Triangle(0); double h = hsv.H; double s = hsv.S / 100.0; double v = hsv.V / 100.0; PointF vH = InnerPoints[0]; PointF vS = InnerPoints[1]; PointF vV = InnerPoints[2]; // saturation first, then value // this design matches with the picture from wiki var vStoH = new PointF((vH.X - vS.X) * (float)s, (vH.Y - vS.Y) * (float)s); var vS2 = new PointF(vS.X + vStoH.X, vS.Y + vStoH.Y); var vVtovS2 = new PointF((vS2.X - vV.X) * (float)v, (vS2.Y - vV.Y) * (float)v); var final = new PointF(vV.X + vVtovS2.X, vV.Y + vVtovS2.Y); return(ColorPickUtil.RotatePoint(final, new PointF(Width / 2.0f, Width / 2.0f), ColorPickUtil.DegreeToRadian(_currentHue))); }