Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing Spheres with RadialGradientBrush

I'm trying to draw spherical pieces for a game, in WPF. Pieces are drawns as Elipses with RadialGradientBrushs. As you can see below, my black pieces look fantastic, but it is hard to get the white ones having any depth without making them look grey.

enter image description here

I'm currently using:

private readonly Brush _whitePieceBrush = new RadialGradientBrush(Colors.Snow, Colors.Ivory);
private readonly Brush _blackPieceBrush = new RadialGradientBrush(Colors.DarkGray, Colors.Black);

...

using (DrawingContext dc = _piecesVisual.RenderOpen())
{
    ....
    Brush brush = piece.Value.IsBlack ? _blackPieceBrush : _whitePieceBrush;
    var pen = new Pen(new SolidColorBrush(Colors.Black), 0.5); 
    dc.DrawEllipse(brush, pen, new Point(posX, posY), 15, 15);
    ...

}

The black circles around the white pieces don't help, but with out them, it looks even worse. (If I can find a good way to draw them that looks better, I'll be removing it)

like image 429
Lyndon White Avatar asked May 10 '12 13:05

Lyndon White


1 Answers

What about something like the following. The focal point is a bit off-center, which i find improves the spatial impression.

enter image description here

<Ellipse Width="60" Height="60">
    <Ellipse.Fill>
        <RadialGradientBrush GradientOrigin="0.3,0.3">
            <RadialGradientBrush.GradientStops>
                <GradientStop Color="White" Offset="0"/>
                <GradientStop Color="White" Offset="0.3"/>
                <GradientStop Color="#FFF0F0F0" Offset="1"/>
            </RadialGradientBrush.GradientStops>
        </RadialGradientBrush>
    </Ellipse.Fill>
</Ellipse>
like image 167
Clemens Avatar answered Oct 01 '22 16:10

Clemens