Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw color wheel in WPF application?

I started to play with WPF and wanted to draw color wheel on a form.

At first I tryed to use LinearGradientBrush on ArcSegment like this:

<Path StrokeThickness="35" Height="150" Width="150">
    <Path.Stroke>
        <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
            <GradientStop Color="Red" Offset="0.15" />
            <GradientStop Color="Orange" Offset="0.2" />
            <GradientStop Color="Yellow" Offset="0.35" />
            <GradientStop Color="Green" Offset="0.5" />
            <GradientStop Color="Blue" Offset="0.65" />
            <GradientStop Color="Indigo" Offset="0.75" />
            <GradientStop Color="Violet" Offset="0.9" />
        </LinearGradientBrush>
    </Path.Stroke>
    <Path.Data>
        <PathGeometry >
            <PathFigure IsClosed="True" StartPoint="25,70">
                <ArcSegment Point="25,71" IsLargeArc="True"
                    Size="50,50" SweepDirection="Clockwise" />
            </PathFigure>
        </PathGeometry>
    </Path.Data>
</Path>

Unsuccessfully, because gradient was still horizontal.

Another idea is what I have to bend line somehow after applying the gradient. But I can't find apropriate transform.

If there is no standard transform is it possible to make custom transform? Or should I draw color wheel by pixels?

Any ideas, please.

like image 463
Alexander Prokofyev Avatar asked May 05 '09 09:05

Alexander Prokofyev


2 Answers

Here is yet another example from silverlight: http://asyrovprog.host22.com/colorwheel.html. Source code is located here: timeline.codeplex.com under bsd license.

like image 190
asyrov Avatar answered Sep 21 '22 10:09

asyrov


This library has pixel shaders that draw color wheels

Sample xaml:

<Ellipse Width="300"
         Height="300"
         Fill="White">
    <Ellipse.Effect>
        <effects:HsvWheelEffect />
    </Ellipse.Effect>
</Ellipse>

Note that the ellipse must have a brush set on Fill for this to work, can be any colour.

like image 31
Johan Larsson Avatar answered Sep 23 '22 10:09

Johan Larsson