Draw a color wheel with alpha and saturation values in C#

[color wheel]

The example Draw a colorful color wheel in C# shows how to draw a color wheel. This example lets you use scroll bars to change the alpha (opaqueness) and saturation (grayness) values of the colors.

This is actually a pretty easy change. Before it calculates the surround colors used to color the points on the edge of the circle, the program uses the following code to get the alpha and saturation values.

// Get alpha and saturation.
int alpha = hscrAlpha.Value;
int sat = hscrSaturation.Value;

The previous version of the program used the following code to calculate interpolated colors along the circumference of the circle. The code highlighted in blue gives the alpha components for the interpolation’s start and end colors.

InterpolateColors(surround_colors, ref index,
    1 * num_pts, 255, 255, 0, 0, 255, 255, 0, 255);

The new version uses the following code to calculate interpolation colors. The blue and red code highlights the alpha and saturation values, respectively

InterpolateColors(surround_colors, ref index,
    1 * num_pts, alpha, sat, 0, 0, alpha, sat, 0, sat);

The alpha value is simply passed into the InterpolateColors method so all of the colors it generates have the given alpha value.

The saturation value gives the maximum value used by any color’s red, green, or blue component. This removes color from those components and moves the result closer to black. The result is “grayer.” If you set saturation to its minimum value 0, all of the colors become black. The color wheel shows a black circle shading to white at the middle.

If you look closely at the picture, you’ll see that saturation is not at its maximum so the colors don’t reach their greatest possible brightness. For example, the wheel doesn’t show pure red, green, blue, or yellow.

The only other real difference between this program and the previous color wheel program is that this one draws a grid behind the wheel so you can see what happens when alpha is less than 255 so the background shows through.


Download Example   Follow me on Twitter   RSS feed   Donate




This entry was posted in drawing, graphics, image processing and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

One Response to Draw a color wheel with alpha and saturation values in C#

  1. Pingback: Make a selection dialog that uses a color wheel in C#C# Helper

Leave a Reply

Your email address will not be published. Required fields are marked *