# Code Snippets #21 - FillEllipse

Published 8/4/2013 by createdbyx in Code Snippets | Programming
Tags: ,
```/// <summary>
/// Draws a filled Ellipse.
/// </summary>
/// <param name="image">
/// The destination image.
/// </param>
/// <param name="x">
/// The x left most position of the ellipse.
/// </param>
/// <param name="y">
/// The y top most position of the ellipse.
/// </param>
/// <param name="width">
/// The width of the ellipse.
/// </param>
/// <param name="height">
/// The height of the ellipse.
/// </param>
/// <param name="color">
/// The color to use.
/// </param>
public static void FillEllipse<T>(this GenericImage<T> image, int x, int y, int width, int height, T color)
{
width = width / 2;
height = height / 2;
var centerX = x + width;
var centerY = y + height;

// source -> http://stackoverflow.com/questions/10322341/simple-algorithm-for-drawing-filled-ellipse-in-c-c
for (var indexY = -height; indexY <= height; indexY++)
{
for (var indexX = -width; indexX <= width; indexX++)
{
var dx = indexX / (double)width;
var dy = indexY / (double)height;
if (dx * dx + dy * dy <= 1)
{
image[centerX + indexX, centerY + indexY] = color;
}
}
}
}```

• Comment
• Preview

# Created by: X

## Just another personal website in this crazy online world

 Dean Lunz (aka Created by: X) Computer programming nerd, and tech geek. About Me -- Resume