Draw text filled with random colored circles in C#

The example Draw text filled with random colored lines in C# shows how to draw text filled with random colored lines. This example is similar except it fills the text with random colored circles instead of lines.

After creating the clipping region (see the previous example for details), the program uses the following code to draw the random circles.

// Fill the path with circles.
Random rand = new Random();
for (int i = 1; i < 200; i++)
{
int radius = rand.Next(5, 50);
int cx = rand.Next(0, ClientSize.Width);
int cy = rand.Next(0, ClientSize.Height);
using (Brush colored_brush = new SolidBrush(RandomColor()))
{
e.Graphics.FillEllipse(colored_brush,
cx - radius, cy - radius, 2 * radius, 2 * radius);
}
}

The code generates random X and Y coordinates for the circle's center and a random radius. It then calls the RandomColor method to pick a random color for the circle and fills it.

  

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.