Draw the Tiles
 
 
 

Now that you have developed the user input subroutine, along with the subroutine to draw the outline, you are ready to fill the path with circular tiles. This task requires some geometry.

In the VBA IDE, enter the following code in the Code window, after the drawout subroutine:

' Place one row of tiles the given distance along path
' and possibly offset it
Private Sub drow(pd As Double, offset As Double)
	Dim pfirst(0 To 2) As Double
	Dim pctile(0 To 2) As Double
	Dim pltile(0 To 2) As Double
	Dim cir As AcadCircle
	Dim varRet As Variant
	varRet = ThisDrawing.Utility.PolarPoint( _
	 sp, pangle, pd)
	pfirst(0) = varRet(0)
	pfirst(1) = varRet(1)
	pfirst(2) = varRet(2)
	varRet = ThisDrawing.Utility.PolarPoint( _
	 pfirst, angp90, offset)
	pctile(0) = varRet(0)
	pctile(1) = varRet(1)
	pctile(2) = varRet(2)
	pltile(0) = pctile(0)
	pltile(1) = pctile(1)
	pltile(2) = pctile(2)
	Do While distance(pfirst, pltile) < (hwidth - trad)
		Set cir = ThisDrawing.ModelSpace.AddCircle( _
		 pltile, trad)
		varRet = ThisDrawing.Utility.PolarPoint( _
		 pltile, angp90, (tspac + trad + trad))
		pltile(0) = varRet(0)
		pltile(1) = varRet(1)
		pltile(2) = varRet(2)
	Loop
	varRet = ThisDrawing.Utility.PolarPoint( _
	 pctile, angm90, tspac + trad + trad)
	pltile(0) = varRet(0)
	pltile(1) = varRet(1)
	pltile(2) = varRet(2)
	Do While distance(pfirst, pltile) < (hwidth - trad)
		Set cir = ThisDrawing.ModelSpace.AddCircle( _
		 pltile, trad)
		varRet = ThisDrawing.Utility.PolarPoint( _
		 pltile, angm90, (tspac + trad + trad))
		pltile(0) = varRet(0)
		pltile(1) = varRet(1)
		pltile(2) = varRet(2)
	Loop
End Sub
' Draw the rows of tiles
Private Sub drawtiles()
	Dim pdist As Double
	Dim offset As Double
	pdist = trad + tspac
	offset = 0
	Do While pdist <= (plength - trad)
		drow pdist, offset
		pdist = pdist + ((tspac + trad + trad) * Sin(dtr(60)))
		If offset = 0 Then
			offset = (tspac + trad + trad) * Cos(dtr(60))
		Else
			offset = 0
		End If
	Loop
End Sub

To understand how these subroutines work, refer to the following illustration. The subroutine drow draws a row of tiles at a given distance along the path specified by its first argument, and offsets the row perpendicular to the path by a distance specified by its second argument. You want to offset the tiles on alternate rows to cover more space and make a more pleasing arrangement.

The drow subroutine finds the location for the first row by using the PolarPoint method to move along the path by the distance specified by the first argument. The subroutine then uses the PolarPoint method again to move perpendicularly to the path for the offset. The subroutine uses the While statement to continue to draw circles until the edge of the path is encountered. The PolarPoint method in the first While statement moves on to the next tile location by spacing a distance of two tile radii (trad) and one intertile space (tspac). A second while loop then draws the tiles in the row in the other direction until the other edge is encountered.

The drawtiles subroutine calls drow repeatedly to draw all the tile rows. The subroutine While loop steps along the path, calling drow for each row. Tiles in adjacent rows form equilateral triangles, as shown in the previous illustration. The edges of these triangles are equal to twice the tile radius plus the spacing between the tiles. Therefore, by trigonometry, the distance along the path between rows is the sine of 60 degrees multiplied by this quantity, and the offset for odd rows is the cosine of 60 degrees multiplied by this quantity.

The If statement is used in drawtiles to offset every other row. If the offset is equal to 0, set it to the spacing between the centers of tiles multiplied by the cosine of 60 degrees, as explained earlier. If the offset is not equal to 0, set it to 0. This alternates the offset on the rows as you want.

Save your work.