Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw an Apollonian gasket with circles filled by random colors in Visual Basic .NET
DescriptionThis example shows how to draw an Apollonian gasket with circles filled by random colors in Visual Basic .NET.
Keywordsrandom colors, mathematics, algorithms, graphics, Apollonian gasket, Apollonian packing, Apollonius' Problem, Apollonius, Apollonian circles, tangent cicles, geometry, example, example program, Windows Forms programming, Visual Basic .NET, VB.NET
CategoriesAlgorithms, Graphics
 

This example is similar to the example Draw an Apollonian gasket (or Apollonian packing) in Visual Basic .NET except it fills the circles it draws with random colors. The program uses the following code to generate random colors.

 
' Return a random color.
Private rand As New Random()
Private Colors() As Color = _
{ _
    Color.Red, Color.Green, Color.Blue, Color.Lime, _
    Color.Orange, Color.Fuchsia, Color.Yellow, _
        Color.LightGreen, _
    Color.LightBlue, Color.Cyan _
}
Private Function RandomColor() As Color
    Return Colors(rand.Next(0, Colors.Length))
End Function
 
This code defines a Random object that it later uses to generate random numbers and an array holding the colors that it should use. The RandomColor method uses the Random object to generate a random index in the array and returns the corresponding color.

The program uses the RandomColor method to create brushes for filling the circles that it draws. For example, the following code shows how the program draws the large enclosing circle.

 
' Draw the big circle.
Using the_brush As New SolidBrush(RandomColor())
    big_circle.Draw(gr, the_brush)
End Using
 
 
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated