Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw an interesting curved Truchet Tiling
DescriptionThis example shows how to draw an interesting curved Truchet Tiling in Visual Basic.
KeywordsTruchet Tiling, curve, draw, graphics, tile, tiling
CategoriesGraphics
 

This example's Paint event handler generates a Truchet Tiling. It makes the image by tiling the form with one of the two tiles shown on the right, randomly picking a tile for each position. For more on Truchet Tilings, see Eric W. Weisstein's article Truchet Tiling at MathWorld--A Wolfram Web Resource.

 
Private Sub Form_Paint()
Const PI As Double = 3.14159265
Const RADIUS As Single = 12
Const WID As Single = 2 * RADIUS

Dim r As Integer
Dim c As Integer
Dim max_r As Integer
Dim max_c As Integer
Dim X As Single
Dim Y As Single

    Cls
    max_c = ScaleWidth \ WID + 1
    max_r = ScaleHeight \ WID + 1
    Y = 0
    For r = 0 To max_r
        X = 0
        For c = 0 To max_c
            If Rnd > 0.5 Then
                Me.Circle (X, Y), RADIUS, , 1.5 * PI, 2 * PI
                Me.Circle (X + WID, Y + WID), RADIUS, , 0.5 _
                    * PI, PI * 1.1
            Else
                Me.Circle (X + WID, Y), RADIUS, , PI, 1.5 * _
                    PI
                Me.Circle (X, Y + WID), RADIUS, , 0, 0.55 * _
                    PI
            End If
            X = X + WID
        Next c
        Y = Y + WID
    Next r

    Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), , B
End Sub
 
If you click on the image, the program uses the FloodFill API function to fill the clicked aera with a random color.
 
Private Sub Form_MouseDown(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
Dim color As Long

    ' Pick a random color other than black and
    ' the point's current color.
    Do
        color = QBColor(Int(15 * Rnd + 1))
    Loop While color = Point(X, Y)

    ' Create and select a brush of this color.
    FillStyle = vbFSSolid
    FillColor = color

    ' Do the flood,stopping when we
    ' reach black pixels.
    FloodFill hdc, X, Y, vbBlack

    FillStyle = vbFSTransparent
End Sub
 
For more information on graphics programming in Visual Basic, see my book Visual Basic Graphcis Programming.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated