Attribute VB_Name = "ModAA"
Option Explicit

Public aAA   As Boolean
Public aRound As Boolean
Public zangle As Single

' Oval & Arc parameters
'Public zrad As Single, zratio As Single, zradx As Single, zrady As Single
'Public ArcTool As Integer

Public zAS As Single, zAE As Single   ' Start, End angles in radians
Public xpr As Single, ypr As Single
Public vbzAS As Single, vbzAE As Single  ' vbArc angles

Public ArcStep As Single

' Rounds
Public RA() As Byte

Public Sub ZSetArcAngles()
' Oval & Arc parameters
'Public ArcTool As Integer
'Public vbzAS As Single, vbzAE As Single  ' vbArc angles
'Public zAS As Single, zAE As Single      ' Start, End angles in radians for Arcs
Dim vbzAEE As Single
      
   Select Case ArcTool
'      Case 0 ' Oval
'         zAS = 0: zAE = 2 * pi#       ' 1 Full Oval
'         vbzAS = 2 * pi#: vbzAE = 0
   Case 0 ' TL Arc
      vbzAS = pi# / 2: vbzAE = pi#
   Case 1   ' BL Arc
      vbzAS = pi#: vbzAE = 3 * pi# / 2
   Case 2   ' TR Arc
      vbzAS = 0: vbzAE = pi# / 2
   Case 3   ' BR Arc
      vbzAS = 3 * pi# / 2: vbzAE = 2 * pi#
   Case 4   ' Left Semi Arc
      vbzAS = pi# / 2: vbzAE = 3 * pi# / 2
   Case 5   ' Right Semi Arc
      vbzAS = 3 * pi# / 2: vbzAE = pi# / 2
   Case 6   ' Top Semi Arc
      vbzAS = 0: vbzAE = pi#
   Case 7   ' Bottom Semi Arc
      vbzAS = pi#: vbzAE = 2 * pi#
   Case 8   ' TL 3/4 Arc
      vbzAS = 0: vbzAE = 3 * pi# / 2
   Case 9  ' BL 3/4 Arc
      vbzAS = pi# / 2: vbzAE = 2 * pi#
   Case 10  ' TR 3/4 Arc
      vbzAS = 3 * pi# / 2: vbzAE = pi#
   Case 11  ' BR 3/4 Arc
      vbzAS = pi#: vbzAE = pi# / 2
   Case 12  ' Bottom 3/4 Arc
      vbzAS = 3 * pi# / 4: vbzAE = pi# / 4
   Case 13  ' Left 3/4 Arc
      vbzAS = pi# / 4: vbzAE = 7 * pi# / 4
   Case 14  ' Top 3/4 Arc
      vbzAS = 7 * pi# / 4: vbzAE = 5 * pi# / 4
   Case 15  ' Right 3/4 Arc
      vbzAS = 5 * pi# / 4: vbzAE = 3 * pi# / 4
   End Select
   vbzAEE = vbzAE
   zAE = 2 * pi# - vbzAS
   zAS = 2 * pi# - vbzAEE
End Sub

Public Sub ZAACIRLIPSE(ByVal ixc As Integer, ByVal iyc As Integer, _
   ByVal zradx As Single, ByVal zrady As Single, DCul As Long, zAS As Single, zAE As Single, _
   Optional Anti As Long = 0)

Dim zrx As Single, zry As Single
Dim pix As Long
Dim ixs As Single, iys As Single
Dim svRound As Boolean

  ' Screen.MousePointer = vbHourglass
   
   zrx = zradx
   zry = zrady
   If zradx = 0 Then zradx = 0.001
   If zrady = 0 Then zrady = 0.001
   Select Case PixelSize
   Case 1
      ArcStep = 2 / zradx
      If zrady > zradx Then ArcStep = 2 / zrady
   Case 2 To 7
      ArcStep = 1 / zradx
      If zrady > zradx Then ArcStep = 1 / zrady
   Case 8 To 12
      ArcStep = 1 / (2 * zradx)
      If zrady > zradx Then ArcStep = 1 / (2 * zrady)
   Case Else
      ' Value to avoid gaps  NB << 1 deg!
      ArcStep = 0.002
   End Select
   
   svRound = aRound
   If aRound Then
      If zAS = 0 And zAE = 2 * pi# Then
         aRound = False   ' ie Square ends for complete circle
      End If              '    to avoid round bump at 0 deg
   End If
   
   zrx = zradx
   zry = zrady
   zradx = zradx - (PixelSize / 2)
   zrady = zrady - (PixelSize / 2)
   ' OK - IFs taken outside loop
   ' AA Draw 'Inside
   ZAAARC ixc, iyc, zradx, zrady, DCul, zAS, zAE, Anti
   If PixelSize > 1 Then
      For pix = 2 To PixelSize '+ 1
         ZAAARC ixc, iyc, zradx, zrady, DCul, zAS, zAE, 1  ' Draw
         zradx = zradx + 1
         zrady = zrady + 1
      Next pix
      ' AA Draw ' Outside
      ZAAARC ixc, iyc, zradx - 0.75, zrady - 0.75, DCul, zAS, zAE, Anti
   End If
   
   zradx = zrx
   zrady = zry
   
   If Tool = Boxes Then
   If BoxTool = [BoxRounded] Then
      Screen.MousePointer = vbDefault
      Exit Sub
   End If
   End If
   
   'If ArcTool <> 0 Then  ' ie NOT Oval
   If Tool <> Cirlipses Then
      If aRound Then
         ' Add round AA Dot
         If PixelSize > 2 Then
            ' Reduce size of round end dot (for Arcs, Bullet outline)
            pix = PixelSize
            PixelSize = PixelSize - 2
            zradx = zradx - 1
            zrady = zrady - 1
         
'            picDRAW.DrawWidth = 1
            ixs = ixc + zradx * Cos(zAS)
            iys = iyc + zrady * Sin(zAS)
            AdjustArcRoundEnd ixs, iys, 1 ' Using Public ArcTool, PixelSize
            DrawDot ixs, iys, DCul
            ixs = ixc + zradx * Cos(zAE)
            iys = iyc + zrady * Sin(zAE)
            AdjustArcRoundEnd ixs, iys, 2
            DrawDot ixs, iys, DCul
            PixelSize = pix
         End If
      End If
   End If

   zradx = zrx
   zrady = zry
   
   aRound = svRound
   'Screen.MousePointer = vbDefault
End Sub

Public Sub AdjustArcRoundEnd(ByVal ixs As Single, ByVal iys As Single, n As Long)
' Only called from ZAACIRLIPSE mainly for Arcs with no radii
' Using Public ArcTool, PixelSize
' N =1 for zAS, =2 for zAE angles

' ArcTools 4,5,6,7 L,R,T,B Semis

   If (PixelSize And 1) = 0 Then 'EVEN
      If n = 1 Then
         Select Case ArcTool
         Case 0, 2, 4, 11, 15
            iys = iys + 1
         Case 6, 7, 10
            ixs = ixs + 1
         End Select
      Else   ' N = 2
         Select Case ArcTool
         Case 0, 1, 11, 12
            ixs = ixs + 1
         Case 5, 10
            iys = iys + 1
         End Select
      End If
   End If
End Sub

Public Sub ZAAARC(ByVal ixc As Integer, ByVal iyc As Integer, _
   ByVal zradx As Single, ByVal zrady As Single, DCul As Long, zAS As Single, zAE As Single, _
    Optional Anti As Long = 0)  ' , Optional Convert As Long = 0 DONE IN ZADRAWER
' Only Called from ZAACIRLIPSE

' ixc=xsto(1), iyc=ysto(1)  centre coords
' zradx,zrady
' Cul
'Public ArcStep As Single     ' Default to .002
Dim TAlpha As Double
Dim xp As Single, yp As Single     ' points on ellipse
Dim zstep As Single
Dim avh As Long
Dim zzAE As Single

'      ' FULL,TRQ, BRQ
'      Select Case Q
'      Case 0   ' Oval, BRQ, BL 3/4 Arc
'      Case 1   ' TLQ, TRQ, Right Semi Arc, BR 3/4 Arc
'      Case 2   ' BLQ, Left Semi Arc, TL 3/4 Arc
'      Case 3   ' Top Semi Arc, Bottom Semi Arc, TR 3/4 Arc
'      Case 4   ' Bottom 3/4 Arc, Left 3/4 Arc
'      Case 5   ' Top 3/4 Arc
'      Case 6   ' Right 3/4 Arc
'      End Select
      
   xpr = ixc + zradx * Cos(zAS)
   ypr = iyc + zrady * Sin(zAS)
      
   zstep = ArcStep
   zzAE = zAE
   
   If zAE < zAS Then
      zzAE = zAE + 2 * pi#
   End If
   
   For TAlpha = zAS To zzAE + zstep / 2 Step zstep / 2
   'For TAlpha = zAS To (zAE - zStep) Step zStep
      xp = ixc + zradx * Cos(TAlpha)
      yp = iyc + zrady * Sin(TAlpha)
      If xp = Int(xp) Then xp = xp + 0.001
      If yp = Int(yp) Then yp = yp + 0.001
      ZAADRAWER xpr, ypr, xp, yp, DCul, avh, Anti
' TEST
'If TAlpha = zAS Then
'picDRAW.DrawWidth = 3
'picDRAW.PSet (xpr, ypr), vbRed
'picDRAW.DrawWidth = 1
'End If
         
      xpr = xp 'r2
      ypr = yp 'r2
   Next TAlpha
End Sub


Public Sub InsideGRAD(ByVal xc As Integer, ByVal yc As Integer, _
   ByVal xi As Integer, ByVal yi As Integer, _
   ByVal zA As Single, ByVal zB As Single, _
   EllRot As Single, Optional Anti As Long = 0)
   
   ' Called frm EllTangents(Cones) & TubeDraw(Tubes)
   ' Center grads are [CONE4], [CONE5] & [TUBE3]
   
' xi,yi point inside ellipse
' for [CONE2] to [CONE5] only
Dim TAlpha As Single
Dim xp As Single, yp As Single     ' points on ellipse
Dim xpr As Single, ypr As Single   ' points on ellipse
Dim zstep As Single
Dim rx As Single, ry As Single
Dim RA As Single
Dim aRev As Boolean

   zstep = 0.0125 '0.01 'ArcStep
   ' xi,yi ?
   ' xsto(2),ysto(2)
   RA = -EllRot
   
   Select Case TubularTool
   Case [CONE4], [CONE5], [TUBE3]
      NSteps = (pi#) / (zstep / 4)
      aRev = False
   Case Else
      NSteps = (pi#) / (zstep / 8)
      aRev = True
   End Select
   
   GetColorSteps

   For TAlpha = 0 To 2 * pi# Step zstep / 4
      ' Ellipse point about (0,0)
      xp = zA * Cos(TAlpha)
      yp = zB * Sin(TAlpha)
      ' Rotate
      rx = xp * Cos(RA) - yp * Sin(RA)
      ry = xp * Sin(RA) + yp * Cos(RA)
      ' Translate
      xp = rx + xc
      yp = ry + yc
      ' SIDE COLOR IGNORE BASE IE CONE2
      BresLine xp, yp, xi, yi, CByte(zRL), CByte(zGL), CByte(zBL), 1, 1
      If aRev = False Then
         If TAlpha >= pi# Then
            aRev = True
            zRIncr = -zRIncr
            zGIncr = -zGIncr
            zBIncr = -zBIncr
         End If
      End If
      GetNextColors
   Next TAlpha
   
   If aAA Then
      'If PixelSize = 1 Then
      PixelSize = 2
      Select Case TubularTool
      Case [CONE4], [CONE5], [TUBE3]
         NSteps = (pi#) / (zstep / 4)
         aRev = False
      Case Else
         NSteps = (pi#) / (zstep / 8)
         aRev = True
      End Select
      GetColorSteps
      
      zA = zA + 1
      xpr = zA * Cos(0)
      ypr = zB * Sin(0)
      ' Rotate
      rx = xpr * Cos(RA) - ypr * Sin(RA)
      ry = xpr * Sin(RA) + ypr * Cos(RA)
      ' Translate
      xpr = rx + xc
      ypr = ry + yc
      
      For TAlpha = 0 To 2 * pi# Step zstep / 4
         ' Ellipse point about (0,0)
         xp = zA * Cos(TAlpha)
         yp = zB * Sin(TAlpha)
         ' Rotate
         rx = xp * Cos(RA) - yp * Sin(RA)
         ry = xp * Sin(RA) + yp * Cos(RA)
         ' Translate
         xp = rx + xc
         yp = ry + yc
         ZDrawAALine xpr, ypr, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         'ZDrawAALine xpr, ypr, xp, yp, LeftColor, 0
         xpr = xp
         ypr = yp
         If aRev = False Then
            If TAlpha >= pi# Then
               aRev = True
               zRIncr = -zRIncr
               zGIncr = -zGIncr
               zBIncr = -zBIncr
            End If
         End If
         GetNextColors
      Next TAlpha
   
   End If
   PixelSize = pxsvORG

End Sub

Public Sub CONEGRAD(ByVal xc As Integer, ByVal yc As Integer, _
   ByVal zA As Single, ByVal zB As Single, _
   ByVal zAS As Single, ByVal zAE As Single, _
   EllRot As Single, ByVal xt As Single, ByVal yt As Single, Optional Anti As Long = 0)
' Called from ModDRAW.Sub EllTangents

' For Color steps in ModDRAW
' Public NSteps As Long
' Public zIStep As Single
' Public zRL As Single, zGL As Single, zBL As Single
' Public zRR As Single, zGR As Single, zBR As Single
' Public zRIncr As Single, zGIncr As Single, zBIncr As Single

Dim TAlpha As Single
Dim xp As Single, yp As Single     ' points on ellipse
Dim xpr As Single, ypr As Single   ' points on ellipse
Dim zstep As Single
Dim z1 As Single, z2 As Single
Dim rx As Single, ry As Single
Dim RA As Single
Dim aRev As Boolean
Dim zFrac As Single  'To reduce underlying cones'area for aAA
   
   zstep = 0.0125 '0.01 'ArcStep
   
   xt = xsto(2): yt = ysto(2)
   RA = -EllRot
PixelSize = 2

Select Case TubularTool
Case [CONE2], [CONE3] ' Side gradient cones
   z1 = zAS
   z2 = zAE
   If z2 < z1 Then
      z2 = 2 * pi# + z2
   End If

   NSteps = (z2 - z1) / (zstep / 4)
   GetColorSteps
   
   For TAlpha = z1 To z2 Step zstep / 4
      ' Ellipse point about (0,0)
      xp = zA * Cos(TAlpha)
      yp = zB * Sin(TAlpha)
      ' Rotate
      rx = xp * Cos(RA) - yp * Sin(RA)
      ry = xp * Sin(RA) + yp * Cos(RA)
      ' Translate
      xp = rx + xc
      yp = ry + yc
      ' SIDE COLOR IGNORE BASE IE CONE2
      BresLine xt, yt, xp, yp, CByte(zRL), CByte(zGL), CByte(zBL), 1, 1
      GetNextColors
   Next TAlpha
      
   If TubularTool = [CONE2] Then ' Side grad no base
   If aAA Then ' AA to outside tangents and arc
      If PixelSize = 1 Then PixelSize = 2
      ZDrawAALine xt, yt, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
      
      GetColorSteps
      xp = zA * Cos(z1)
      yp = zB * Sin(z1)
      ' Rotate
      rx = xp * Cos(RA) - yp * Sin(RA)
      ry = xp * Sin(RA) + yp * Cos(RA)
      ' Translate
      xp = rx + xc
      yp = ry + yc
      ZDrawAALine xt, yt, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
      PixelSize = pxsvORG
   
      xpr = zA * Cos(z1 - zstep / 4)
      ypr = zB * Sin(z1 - zstep / 4)
      ' Rotate
      rx = xpr * Cos(RA) - ypr * Sin(RA)
      ry = xpr * Sin(RA) + ypr * Cos(RA)
      ' Translate
      xpr = rx + xc
      ypr = ry + yc
      
      GetColorSteps
      For TAlpha = z1 To z2 Step zstep / 4
         ' Ellipse point about (0,0)
         xp = zA * Cos(TAlpha)
         yp = zB * Sin(TAlpha)
         ' Rotate
         rx = xp * Cos(RA) - yp * Sin(RA)
         ry = xp * Sin(RA) + yp * Cos(RA)
         ' Translate
         xp = rx + xc
         yp = ry + yc
         ' SIDE COLOR BASE ARC FOR CONE2
         ZDrawAALine xpr, ypr, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         xpr = xp
         ypr = yp
         GetNextColors
      Next TAlpha
   End If
   End If
   
   If TubularTool = [CONE3] Then ' Side grad with base
      aRev = False
      z1 = zAS
      z2 = zAE
      If z1 < z2 Then
         z1 = 2 * pi# + z1
      End If
      NSteps = (z1 - z2) / (zstep / 4)
      GetColorSteps
      ' SIDE COLOR TO BASE
      For TAlpha = z2 To z1 Step zstep / 4
         ' Ellipse point about (0,0)
         xp = zA * Cos(TAlpha)
         yp = zB * Sin(TAlpha)
         ' Rotate
         rx = xp * Cos(RA) - yp * Sin(RA)
         ry = xp * Sin(RA) + yp * Cos(RA)
         ' Translate
         xp = rx + xc
         yp = ry + yc
         ' To overwrite underlying [CONE2]
         BresLine xt, yt, xp + 1, yp + 1, CByte(zRL), CByte(zGL), CByte(zBL), 1, 1
         BresLine xt, yt, xp - 1, yp - 1, CByte(zRL), CByte(zGL), CByte(zBL), 1, 1
         BresLine xt, yt, xp + 1, yp - 1, CByte(zRL), CByte(zGL), CByte(zBL), 1, 1
         BresLine xt, yt, xp - 1, yp + 1, CByte(zRL), CByte(zGL), CByte(zBL), 1, 1
         GetNextColors
      Next TAlpha
   
      If aAA Then ' AA to outside tangents
         If PixelSize = 1 Then PixelSize = 2
         ' To ensure AA tangent lines
         ZDrawAALine xt, yt, xp + 1, yp + 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         ZDrawAALine xt, yt, xp - 1, yp - 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         ZDrawAALine xt, yt, xp + 1, yp - 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         ZDrawAALine xt, yt, xp - 1, yp + 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         
         GetColorSteps
         xp = zA * Cos(z2)
         yp = zB * Sin(z2)
         ' Rotate
         rx = xp * Cos(RA) - yp * Sin(RA)
         ry = xp * Sin(RA) + yp * Cos(RA)
         ' Translate
         xp = rx + xc
         yp = ry + yc
         ' To ensure AA tangent lines
         ZDrawAALine xt, yt, xp + 1, yp + 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         ZDrawAALine xt, yt, xp - 1, yp - 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         ZDrawAALine xt, yt, xp + 1, yp - 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         ZDrawAALine xt, yt, xp - 1, yp + 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         
         PixelSize = pxsvORG
      End If
   End If
   

Case [CONE4], [CONE5]   ' Center gradient cones
   aRev = False

   z1 = zAS
   z2 = zAE
   If z2 < z1 Then
      z2 = 2 * pi# + z2
   End If
   
If TubularTool = [CONE4] Then
'If aAA Then
zFrac = (z2 - z1) / 24
z1 = z1 + zFrac
z2 = z2 - zFrac
'End If
End If

If TubularTool = [CONE5] Then
'If aAA Then
zFrac = (z2 - z1) / 24
z1 = z1 + zFrac
z2 = z2 - zFrac
'End If
End If


   NSteps = (z2 - z1) / (zstep / 2)
   GetColorSteps

   For TAlpha = z1 To z2 Step zstep / 4
      ' Ellipse point about (0,0)
      xp = zA * Cos(TAlpha)
      yp = zB * Sin(TAlpha)
      ' Rotate
      rx = xp * Cos(RA) - yp * Sin(RA)
      ry = xp * Sin(RA) + yp * Cos(RA)
      ' Translate
      xp = rx + xc
      yp = ry + yc
      ' CENTER COLOR IGNORE BASE
      BresLine xt, yt, xp, yp, CByte(zRL), CByte(zGL), CByte(zBL), 1, 1
         
      If aRev = False Then
         If TAlpha >= (z1 + z2) / 2 Then
            aRev = True
            zRIncr = -zRIncr
            zGIncr = -zGIncr
            zBIncr = -zBIncr
         End If
      End If

      GetNextColors
   Next TAlpha
   
   If TubularTool = [CONE4] Then ' Center grad no base
z1 = z1 - zFrac
z2 = z2 + zFrac

   If aAA Then
      'If PixelSize = 1 Then PixelSize = 2
      ZDrawAALine xt, yt, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
      xp = zA * Cos(z1)
      yp = zB * Sin(z1)
      ' Rotate
      rx = xp * Cos(RA) - yp * Sin(RA)
      ry = xp * Sin(RA) + yp * Cos(RA)
      ' Translate
      xp = rx + xc
      yp = ry + yc
      ZDrawAALine xt, yt, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
      PixelSize = pxsvORG
      xpr = zA * Cos(z1 - zstep / 4)
      ypr = zB * Sin(z1 - zstep / 4)
      ' Rotate
      rx = xpr * Cos(RA) - ypr * Sin(RA)
      ry = xpr * Sin(RA) + ypr * Cos(RA)
      ' Translate
      xpr = rx + xc
      ypr = ry + yc
      
      aRev = False
      GetColorSteps
      For TAlpha = z1 To z2 Step zstep / 4
         ' Ellipse point about (0,0)
         xp = zA * Cos(TAlpha)
         yp = zB * Sin(TAlpha)
         ' Rotate
         rx = xp * Cos(RA) - yp * Sin(RA)
         ry = xp * Sin(RA) + yp * Cos(RA)
         ' Translate
         xp = rx + xc
         yp = ry + yc
         ' SIDE COLOR BASE ARC FOR CONE2
         ZDrawAALine xpr, ypr, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         xpr = xp
         ypr = yp
         If aRev = False Then
            If TAlpha >= (z1 + z2) / 2 Then
               aRev = True
               zRIncr = -zRIncr
               zGIncr = -zGIncr
               zBIncr = -zBIncr
            End If
         End If
         
         GetNextColors
      Next TAlpha
   
   End If
   End If
   
   If TubularTool = [CONE5] Then ' Center color to base

      aRev = False
      z1 = zAS
      z2 = zAE
      If z1 < z2 Then
         z1 = 2 * pi# + z1
      End If
   
      NSteps = (z1 - z2) / (zstep / 2)
      GetColorStepsReversed
      
      ' CENTER COLOR TO BASE
      For TAlpha = z2 To z1 Step zstep / 4
         ' Ellipse point about (0,0)
         xp = zA * Cos(TAlpha)
         yp = zB * Sin(TAlpha)
         ' Rotate
         rx = xp * Cos(RA) - yp * Sin(RA)
         ry = xp * Sin(RA) + yp * Cos(RA)
         ' Translate
         xp = rx + xc
         yp = ry + yc
         ' To overwrite underlying [CONE2]
         If TAlpha > z2 + zFrac And TAlpha < z1 - zFrac Then
            BresLine xt, yt, xp, yp, CByte(zRL), CByte(zGL), CByte(zBL), 1, 1
         Else
            BresLine xt, yt, xp, yp, CByte(zRL), CByte(zGL), CByte(zBL), 0, 1
         End If
'         BresLine xt, yt, xp + 1, yp + 1, CByte(zRL), CByte(zGL), CByte(zBL), 0, 1
'         BresLine xt, yt, xp - 1, yp - 1, CByte(zRL), CByte(zGL), CByte(zBL), 0, 1
'         BresLine xt, yt, xp + 1, yp - 1, CByte(zRL), CByte(zGL), CByte(zBL), 0, 1
'         BresLine xt, yt, xp - 1, yp + 1, CByte(zRL), CByte(zGL), CByte(zBL), 0, 1
         
         If aRev = False Then
            If TAlpha >= (z1 + z2) / 2 Then
               aRev = True
               zRIncr = -zRIncr
               zGIncr = -zGIncr
               zBIncr = -zBIncr
            End If
         End If
         GetNextColors
      Next TAlpha
      If aAA Then ' AA to outside tangents
         'PixelSize = 2
         GetColorStepsReversed
         ' To ensure AA tangent lines
         
         xp = zA * Cos(z1)
         yp = zB * Sin(z1)
         ' Rotate
         rx = xp * Cos(RA) - yp * Sin(RA)
         ry = xp * Sin(RA) + yp * Cos(RA)
         ' Translate
         xp = rx + xc
         yp = ry + yc
         
         ZDrawAALine xt, yt, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0

         'ZDrawAALine xt, yt, xp + 1, yp + 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         'ZDrawAALine xt, yt, xp - 1, yp - 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         'ZDrawAALine xt, yt, xp + 1, yp - 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         'ZDrawAALine xt, yt, xp - 1, yp + 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0

         xp = zA * Cos(z2)
         yp = zB * Sin(z2)
         ' Rotate
         rx = xp * Cos(RA) - yp * Sin(RA)
         ry = xp * Sin(RA) + yp * Cos(RA)
         ' Translate
         xp = rx + xc
         yp = ry + yc
         ' To ensure AA tangent lines
         ZDrawAALine xt, yt, xp, yp, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0

'         ZDrawAALine xt, yt, xp + 1, yp + 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
'         ZDrawAALine xt, yt, xp - 1, yp - 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
'         ZDrawAALine xt, yt, xp + 1, yp - 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
'         ZDrawAALine xt, yt, xp - 1, yp + 1, RGB(CByte(zRL), CByte(zGL), CByte(zBL)), 0
         
      End If
   End If

End Select
PixelSize = pxsvORG
End Sub

Public Sub ZAADRAWER(ByVal xpr As Single, ByVal ypr As Single, _
      ByVal xp As Single, ByVal yp As Single, DCul As Long, _
      Optional avh As Long = 0, Optional Anti As Long = 0)
      
' Anti = 0 (default) do AA, = 1 No AA just set pixels to DCul
      
' Calculates points on a line (xpr,ypr) to (xp,yp)  Bresenham method
Dim zm As Single, zc As Single     ' slope & cut-off
Dim xs As Single, ys As Single     ' calculated points on line segment
Dim zstep As Single
Dim zStepx As Single
Dim zStepy As Single

   Select Case PixelSize
   Case 1
      zstep = 1
   Case 2, 3
      zstep = 0.75
   Case Else
      zstep = 0.5
   End Select
   
   If Abs(xp - xpr) <= Abs(yp - ypr) Then   '-- Steep slope
      zStepy = zstep
      If yp < ypr Then
         zStepy = -zstep
      End If
      If xp = xpr Then
         zm = 10000
      Else
         zm = (yp - ypr) / (xp - xpr)
      End If
      zc = ypr - zm * xpr
      
      For ys = ypr To yp Step zStepy
         xs = (ys - zc) / zm  ' (ys-ypr+zm*xpr)/zm = (ys-ypr)/zm + xpr ~= xpr
         AntiAlias picDATA(), xs, ys, DCul, 0, Anti, 1   ' 1 is Convert to picDATA() coords
      Next ys
   
   Else  ' -- Shallow slope
      zStepx = zstep
      If xp < xpr Then
         zStepx = -zstep
      End If
      If xp = xpr Then
         zm = 10000
      Else
         zm = (yp - ypr) / (xp - xpr)
      End If
      zc = ypr - zm * xpr
      For xs = xpr To xp Step zStepx
         ys = zm * xs + zc
         AntiAlias picDATA(), xs, ys, DCul, 0, Anti, 1   ' 1 is Convert to picDATA() coords
      Next xs
   End If
End Sub

Public Sub AntiAlias(picDATA() As Byte, ByVal xs As Single, ByVal ys As Single, DCul As Long, _
                  Optional avh As Long = 0, Optional Anti As Long = 0, Optional Convert As Long = 0)
                  
' avh  = 0 Area, 1 VertLeft, 2 VertRight, 3 HorzTop, 4 HorzBottom, 5 Change area weighting
' Anti = 0 (default) do AA, = 1 No AA just set pixels to DCul


Dim ix As Single, iy As Single
Dim rc As Byte, gc As Byte, bc As Byte
'Dim LCul As Long
Dim f1 As Single, f2 As Single
Dim A(1 To 4) As Single
Dim r(1 To 4) As Byte
Dim g(1 To 4) As Byte
Dim B(1 To 4) As Byte
Dim Cul(1 To 4) As Single
Dim Red(1 To 4)  As Long
Dim Green(1 To 4) As Long
Dim Blue(1 To 4) As Long
Dim k As Long

   If Convert > 0 Then
         xs = xs + xlo
         ys = Form1.picDRAW.Height - ys + ylo
   End If

   If Anti > 0 Then   'No AA just plot
      If xs >= 0 And xs <= FullW - 1 _
         And ys >= 0 And ys <= FullH - 1 Then
            LngToRGB DCul, r(1), g(1), B(1)
            picDATA(0, xs, ys) = B(1)
            picDATA(1, xs, ys) = g(1)
            picDATA(2, xs, ys) = r(1)
      End If
      'SetPixelV picDRAW.hDC, xs, ys, DCul
      Exit Sub
   End If

   If xs = Int(xs) Then xs = xs + 0.01 '0.001
   If ys = Int(ys) Then ys = ys + 0.01 '0.001
   ix = Int(xs)
   iy = Int(ys)
   ' Area weightings
   A(1) = (ix + 1 - xs) * (iy + 1 - ys)
   A(2) = (xs - ix) * (iy + 1 - ys)
   A(3) = (ix + 1 - xs) * (ys - iy)
   A(4) = (xs - ix) * (ys - iy)
   
   If avh = 5 Then   ' Increase area weightings
      A(1) = 2 * A(1)
      A(2) = 2 * A(2)
      A(3) = 2 * A(3)
      A(4) = 2 * A(4)
   End If
   
   ' Bit faster unrolled
   ' Get colors around point
   'LCul = GetPixel(picDRAW.hDC, ix, iy)
   If ix >= 0 And ix + 1 <= FullW - 1 _
      And iy >= 0 And iy + 1 <= FullH - 1 Then
      
      r(1) = picDATA(2, ix, iy) 'LCul And &HFF&
      g(1) = picDATA(1, ix, iy) '(LCul And &HFF00&) \ &H100&  ' Integer divides
      B(1) = picDATA(0, ix, iy) '(LCul And &HFF0000) \ &H10000
   
   'LCul = GetPixel(picDRAW.hDC, ix + 1, iy)
      r(2) = picDATA(2, ix + 1, iy) 'LCul And &HFF&
      g(2) = picDATA(1, ix + 1, iy) '(LCul And &HFF00&) \ &H100&
      B(2) = picDATA(0, ix + 1, iy) '(LCul And &HFF0000) \ &H10000
   
   'LCul = GetPixel(picDRAW.hDC, ix, iy + 1)
      r(3) = picDATA(2, ix, iy + 1) 'LCul And &HFF&
      g(3) = picDATA(1, ix, iy + 1) '(LCul And &HFF00&) \ &H100&
      B(3) = picDATA(0, ix, iy + 1) '(LCul And &HFF0000) \ &H10000
   
   'LCul = GetPixel(picDRAW.hDC, ix + 1, iy + 1)
      r(4) = picDATA(2, ix + 1, iy + 1) 'LCul And &HFF&
      g(4) = picDATA(1, ix + 1, iy + 1) '(LCul And &HFF00&) \ &H100&
      B(4) = picDATA(0, ix + 1, iy + 1) '(LCul And &HFF0000) \ &H10000
   
   Else
      Exit Sub
   End If
   
   rc = DCul And &HFF&
   gc = (DCul And &HFF00&) \ &H100&
   bc = (DCul And &HFF0000) \ &H10000

   For k = 1 To 4
      Red(k) = A(k) * (1& * rc - r(k)) + r(k)
      Green(k) = A(k) * (1& * gc - g(k)) + g(k)
      Blue(k) = A(k) * (1& * bc - B(k)) + B(k)
   Next k
   If avh = 5 Then
      For k = 1 To 4
         If Red(k) < 0 Then Red(k) = 0
         If Red(k) > 255 Then Red(k) = 255
         If Green(k) < 0 Then Green(k) = 0
         If Green(k) > 255 Then Green(k) = 255
         If Blue(k) < 0 Then Blue(k) = 0
         If Blue(k) > 255 Then Blue(k) = 255
      Next k
   End If
   
   For k = 1 To 4
      Cul(k) = RGB(Red(k), Green(k), Blue(k))
   Next k
   ' Strength factors for vert & horz lines
   'f1 = 0.3
   f1 = 0.4
   f2 = 1 - f1
   ' avh = 0 Area, 1 VL, 2 VR, 3 HT, 4 HB
   Select Case avh
   Case 0, 5
      ' OUT 4 x,y pairs
      picDATA(2, ix, iy) = Red(1)
      picDATA(1, ix, iy) = Green(1)
      picDATA(0, ix, iy) = Blue(1)
      
      picDATA(2, ix + 1, iy) = Red(2)
      picDATA(1, ix + 1, iy) = Green(2)
      picDATA(0, ix + 1, iy) = Blue(2)
      
      picDATA(2, ix, iy + 1) = Red(3)
      picDATA(1, ix, iy + 1) = Green(3)
      picDATA(0, ix, iy + 1) = Blue(3)
      
      picDATA(2, ix + 1, iy + 1) = Red(4)
      picDATA(1, ix + 1, iy + 1) = Green(4)
      picDATA(0, ix + 1, iy + 1) = Blue(4)
      
'      SetPixelV picDRAW.hDC, ix, iy, Cul(1)
'      SetPixelV picDRAW.hDC, ix + 1, iy, Cul(2)
'      SetPixelV picDRAW.hDC, ix, iy + 1, Cul(3)
'      SetPixelV picDRAW.hDC, ix + 1, iy + 1, Cul(4)
   
'      If PixelSize = 1 Then
'        ' SetPixelV picDRAW.hDC, xs, ys, DCul
'        ' This enables AA shapes to be filled using
'        ' Border Fill without showing AA pixels.
'         Select Case Tool
'         Case Cirlipses, Arcs, Tubulars, ALines
'            picDATA(2, xs, ys) = r(1)
'            picDATA(1, xs, ys) = g(1)
'            picDATA(0, xs, ys) = B(1)
'            'SetPixelV picDRAW.hDC, xs, ys, DCul
'
'         Case Radials
'            Select Case RadialTool
'            Case [Circles], [CSpokes], [CStars], [CPolygons]
'               picDATA(2, xs, ys) = r(1)
'               picDATA(1, xs, ys) = g(1)
'               picDATA(0, xs, ys) = B(1)
'               'SetPixelV picDRAW.hDC, xs, ys, DCul
'            End Select
'         Case Waves
'            If WaveTool = [CircWaves] Then
'               picDATA(2, xs, ys) = r(1)
'               picDATA(1, xs, ys) = g(1)
'               picDATA(0, xs, ys) = B(1)
'               'SetPixelV picDRAW.hDC, xs, ys, DCul
'            End If
'         End Select
'      End If
      
    Case 1   ' V left
      If ix - 1 > 0 Then
         'r(1) = picDATA(2, ix - 1, iy)
         'g(1) = picDATA(1, ix - 1, iy)
         'B(1) = picDATA(0, ix - 1, iy)
         picDATA(2, ix - 1, iy) = 1& * f1 * rc + f2 * picDATA(2, ix - 1, iy)
         picDATA(1, ix - 1, iy) = 1& * f1 * gc + f2 * picDATA(1, ix - 1, iy)
         picDATA(0, ix - 1, iy) = 1& * f1 * bc + f2 * picDATA(0, ix - 1, iy)
      End If
'      LngToRGB GetPixel(picDRAW.hDC, ix - 1, iy), r(1), g(1), B(1)
'      SetPixelV picDRAW.hDC, ix - 1, iy, RGB((1& * f1 * rc + f2 * r(1)), _
'                                             (1& * f1 * gc + f2 * g(1)), _
'                                             (1& * f1 * bc + f2 * B(1)))
   Case 2   ' V right
         picDATA(2, ix + 1, iy) = 1& * f1 * rc + f2 * picDATA(2, ix + 1, iy)
         picDATA(1, ix + 1, iy) = 1& * f1 * gc + f2 * picDATA(1, ix + 1, iy)
         picDATA(0, ix + 1, iy) = 1& * f1 * bc + f2 * picDATA(0, ix + 1, iy)
'      LngToRGB GetPixel(picDRAW.hDC, ix + 1, iy), r(2), g(2), B(2)
'      SetPixelV picDRAW.hDC, ix + 1, iy, RGB((1& * f1 * rc + f2 * r(2)), _
                                             (1& * f1 * gc + f2 * g(2)), _
                                             (1& * f1 * bc + f2 * B(2)))
   Case 3   ' H top
      If iy - 1 > 0 Then
         picDATA(2, ix, iy - 1) = 1& * f1 * rc + f2 * picDATA(2, ix, iy - 1)
         picDATA(1, ix, iy - 1) = 1& * f1 * gc + f2 * picDATA(1, ix, iy - 1)
         picDATA(0, ix, iy - 1) = 1& * f1 * bc + f2 * picDATA(0, ix, iy - 1)
      End If
'      LngToRGB GetPixel(picDRAW.hDC, ix, iy - 1), r(1), g(1), B(1)
'      SetPixelV picDRAW.hDC, ix, iy - 1, RGB((1& * f1 * rc + f2 * r(1)), _
'                                             (1& * f1 * gc + f2 * g(1)), _
                                             (1& * f1 * bc + f2 * B(1)))
   Case 4   ' H bottom
         picDATA(2, ix, iy + 1) = 1& * f1 * rc + f2 * picDATA(2, ix, iy + 1)
         picDATA(1, ix, iy + 1) = 1& * f1 * gc + f2 * picDATA(1, ix, iy + 1)
         picDATA(0, ix, iy + 1) = 1& * f1 * bc + f2 * picDATA(0, ix, iy + 1)
'      LngToRGB GetPixel(picDRAW.hDC, ix, iy + 1), r(2), g(2), B(2)
'      SetPixelV picDRAW.hDC, ix, iy + 1, RGB((1& * f1 * rc + f2 * r(2)), _
'                                             (1& * f1 * gc + f2 * g(2)), _
                                             (1& * f1 * bc + f2 * B(2)))
   End Select

End Sub



Public Sub ZDrawAALine(ByVal x1 As Single, ByVal y1 As Single, _
   ByVal x2 As Single, ByVal y2 As Single, _
   DCul As Long, Optional Extend As Single = 0, Optional Anti As Long = 0)
   

'ZDrawAALine  x1, y1, x2, y2, DCul, Anti, Extend
' Extend = 0(Default) no extension, = Frac  extend by Extend * PixelSize
' Anti   = 0(default) do AA,                  = 1 no AA (just SetPixel)
   
' Always AA or non-AA with square ends

' In with x1/y1 -> x2/y2  devel  x3/y3 - x4y4
'                 3
'                / \
'               /   \
'              1     4
'               \   /
'           zLen \ /  zD=Pixelsize
'                 2
Dim zD As Single ', zLen As Single
Dim zdx As Single, zdy As Single
Dim oxa As Single, oya As Single
Dim oxb As Single, oyb As Single
Dim ixc As Single, iyc As Single
Dim zk As Single, zklo As Single, zkup As Single, zkStep As Single
Dim IAng As Single
Dim pix As Long

   x1 = CLng(x1)
   y1 = CLng(y1)
   x2 = CLng(x2)
   y2 = CLng(y2)
   
   zangle = zATan2(y2 - y1, x2 - x1)
   IAng = (r2d# * zangle)
   zkStep = 0.25
            
   zD = PixelSize
   zklo = 0: zkup = zD
            
   ' Adjustments for detecting line boundaries
   If (PixelSize And 1) = 1 Then ' ODD PixelSize
      If (x1 = x2) Or (y1 = y2) Then ' Odd HV SQ & RD
         zD = PixelSize - 0.5
         zklo = 0: zkup = zD
      Else  ' Odd Angled
         Select Case PixelSize
         Case 1, 11
            zD = PixelSize - 0.5
            zklo = 0: zkup = zD
         Case 3
            zD = PixelSize
            zklo = 0: zkup = zD - 0.5
         Case 7
            zD = PixelSize + 0.5
            zklo = 0: zkup = zD - 0.5
         Case Else   ' 5,9
            zD = PixelSize
            zklo = 0: zkup = zD + 0.5
         End Select
      End If
      
   Else  ' EVEN PixelSize
      If (x1 = x2) Or (y1 = y2) Then  'Even HV SQ
         zD = PixelSize + 0.5
         zklo = 0: zkup = zD - 1
      Else ' Angled
         Select Case PixelSize
         Case 2
            zD = PixelSize
            zklo = 0: zkup = zD - 1
         Case 4
            zD = PixelSize + 0.5
            zklo = 0: zkup = zD - 0.5
         Case 6
            zD = PixelSize
            zklo = 0: zkup = zD '+ 0.5
         Case 8
            zD = PixelSize - 0.5
            zklo = 0: zkup = zD + 0.5
         Case 10
            zD = PixelSize
            zklo = 0: zkup = zD - 0.5
         Case 12
            zD = PixelSize
            zklo = 0: zkup = zD
         Case Else
            zD = PixelSize
            zklo = 0: zkup = zD + 0.5
         End Select
      End If
   End If
   ' Generalised extension for square end lines
   If Extend <> 0 Then ' Extend
      zdx = (Extend * PixelSize) * Cos(zangle)
      zdy = (Extend * PixelSize) * Sin(zangle)
      x1 = x1 - zdx
      y1 = y1 - zdy
      x2 = x2 + zdx
      y2 = y2 + zdy
   End If
   
   zdx = (zD) * Sin(zangle) / 2
   zdy = (zD) * Cos(zangle) / 2  ' From Centre
   If Abs(zdx) < 0.0001 Then zdx = 0
   If Abs(zdy) < 0.0001 Then zdy = 0
   If Tool = Boxes Then
      Select Case BoxTool
      Case [BGradient1] To [BGradient5]
      Case Else
         x1 = x1 - zdx: y1 = y1 + zdy
         x2 = x2 - zdx: y2 = y2 + zdy
      End Select
   Else   ' Tool <> Boxes
         x1 = x1 - zdx: y1 = y1 + zdy
         x2 = x2 - zdx: y2 = y2 + zdy
   End If
   
   If Not aAA Or (aAA And Anti = 1) Then
      If PixelSize >= 3 Then
         zkup = zkup - 0.5
      End If
   End If
   
' ZAADRAWER calls AntiAlias which converts coords to picDATA() coords  !!!
   
   For zk = zklo To zkup Step zkStep
      If zk = zklo Then
         If Not aAA Then
            ZAADRAWER x1, y1, x2, y2, DCul, 0, 1          ' Draw line
            If PixelSize = 1 Then Exit For
         Else
            ZAADRAWER x1, y1, x2, y2, DCul, 0, Anti       ' Draw Anti line
         End If
      
      ElseIf zk = zkup Then
         GetParallelCoords zk, x1, y1, x2, y2, oxa, oya, oxb, oyb
         If Not aAA Then
            ZAADRAWER oxa, oya, oxb, oyb, DCul, 0, 1      ' Draw solid single
            If PixelSize = 2 Then Exit For
         Else
            ZAADRAWER oxa, oya, oxb, oyb, DCul, 0, Anti   ' Draw Anti line
         End If
      Else
         GetParallelCoords zk, x1, y1, x2, y2, oxa, oya, oxb, oyb
         ZAADRAWER oxa, oya, oxb, oyb, DCul, 0, 1         ' Draw solid single
      End If
   Next zk
      
   If aAA Then
         If PixelSize > 3 Or Tool = Boxes Then
               GetParallelCoords zk - zkStep, x1, y1, x2, y2, oxa, oya, oxb, oyb
               ZAADRAWER x1, y1, oxa, oya, DCul, 0, Anti     ' Draw Anti Line
               ZAADRAWER x2, y2, oxb, oyb, DCul, 0, Anti     ' Draw Anti Line
         End If
   End If

   If Tool = [ALines] And LineTool = [LAGradient] Then GoTo skipover2 ' ie Round done in ModDRAW
   
   If aRound Then
      pix = PixelSize
      If PixelSize > 3 Then
         
         Select Case Tool
         Case Boxes
            If (pix And 1) = 0 Then ' Even
               PixelSize = PixelSize - 1
            End If
         Case ALines
            If LineTool = [LDoubleEnded] Then
               PixelSize = PixelSize - 1
            End If
         Case Circuits
               PixelSize = PixelSize - 1
         Case Shapes
               PixelSize = PixelSize - 1
         Case Freedraw
            If FreeDrawTool = [FDraw] Then
               PixelSize = PixelSize - 1
            End If
         Case Radials
            PixelSize = PixelSize - 1
         Case Cirlipses
            If CircTool = [CRotate] Then
            End If
         End Select
         
         'PixelSize = pix
         ixc = (x1 + oxa) / 2
         iyc = (y1 + oya) / 2
         ZAdjustAARounds x1, y1, x2, y2, ixc, iyc, IAng
         DrawDot ixc, iyc, DCul

         ixc = (x2 + oxb) / 2
         iyc = (y2 + oyb) / 2
         ZAdjustAARounds x1, y1, x2, y2, ixc, iyc, IAng
         DrawDot ixc, iyc, DCul
      
      
      End If
      
      PixelSize = pix
   End If
skipover2:

End Sub

Private Sub ZAdjustAARounds(x1 As Single, y1 As Single, x2 As Single, y2 As Single, _
                           ixc As Single, iyc As Single, IAng As Single)
' For Lines
   If (PixelSize And 1) = 1 Then ' ODD PixelSize
      If (x1 = x2) Or (y1 = y2) Then ' Odd HV SQ & RD
      End If
      Select Case PixelSize
      Case 5, 9
         If IAng < 0 And IAng > -180 Then
            If IAng <> -90 Then
               ixc = ixc + 0.5
            End If
         End If
      Case 3, 7
         If IAng > 0 And IAng < 180 Then
            If IAng <> 90 Then
               ixc = ixc + 0.5
            End If
         End If
      End Select
   Else  ' EVEN
'      If (x1 = x2) Then ' Vert
'         ixc = ixc + 0.5
'      End If
      Select Case PixelSize
      Case 4, 6, 10
         If (y1 = y2) Then ' Horz
            iyc = iyc + 0.5
         End If
         If IAng > 0 And IAng < 180 Then
               ixc = ixc + 0.5
         End If
         If IAng >= -90 And IAng < 0 Then
            If IAng = -90 Then
               ixc = ixc + 0.5
            Else
             ixc = ixc + 1
            End If
         End If
      Case 8
         If (x1 = x2) Or (y1 = y2) Then ' Odd HV SQ & RD
            If (x1 = x2) Then
               ixc = ixc + 0.5
            End If
            If (y1 = y2) Then ' Horz
               iyc = iyc + 0.5
            End If
         Else
            Select Case IAng
            Case -90 To 0
               ixc = ixc + 1.5
            Case -180 To -91
               ixc = ixc + 1.5
               iyc = iyc + 0.5
            Case 90 To 180
               ixc = ixc + 1
            Case 1 To 89
               ixc = ixc + 1
            End Select
         End If
      Case 12
         If (x1 = x2) Or (y1 = y2) Then ' Odd HV SQ & RD
            If (x1 = x2) Then
               ixc = ixc + 0.5
            End If
            If (y1 = y2) Then ' Horz
               iyc = iyc + 0.5
            End If
         Else
            Select Case IAng
            Case -90 To 0
               ixc = ixc + 1
            Case -180 To -91
               ixc = ixc + 1
               iyc = iyc + 0.5
            
            Case 90 To 180
               ixc = ixc + 1
            Case 1 To 89
               ixc = ixc + 1
            End Select
         End If
      
      End Select
   End If
   If Tool = Boxes Then
   If BoxTool = [BoxTop] Or BoxTool = [BoxRight] Then
      iyc = iyc - 1
   End If
   End If
   
End Sub
                         
Public Sub ZFillRAArray()   'Round Dot Array
   ReDim RA(1 To 12, 1 To 12)
   'ReDim RA(1 To 24, 1 To 24)
   ' RA() entry = 10*Length + Offset
   'Use:-
   '   k = (PixelSize \ 2)  ' To centre
   '   iy = py
   '      For j = 1 To PixelSize
   '         Length = RA(PixelSize, j) \ 10
   '         Offset = RA(PixelSize, j) - (10 * Length)
   '         ax1 = px + (Offset) - k
   '         ay1 = iy - k
   '         ax2 = px + (Offset) + (Length) - k - 1
   '         ay2 = iy - k


   RA(1, 1) = 10
   
   RA(2, 1) = 20: RA(2, 2) = 20
   
   RA(3, 1) = 11: RA(3, 2) = 30: RA(3, 3) = 11
   
   RA(4, 1) = 21: RA(4, 2) = 40: RA(4, 3) = 40: RA(4, 4) = 21
   
   RA(5, 1) = 31: RA(5, 2) = 50: RA(5, 3) = 50: RA(5, 4) = 50: RA(5, 5) = 31
   
   RA(6, 1) = 41: RA(6, 2) = 60: RA(6, 3) = 60: RA(6, 4) = 60: RA(6, 5) = 60: RA(6, 6) = 41
   
   RA(7, 1) = 32: RA(7, 2) = 51: RA(7, 3) = 70: RA(7, 4) = 70: RA(7, 5) = 70: RA(7, 6) = 51
   RA(7, 7) = 32
   
   RA(8, 1) = 42: RA(8, 2) = 61: RA(8, 3) = 80: RA(8, 4) = 80: RA(8, 5) = 80: RA(8, 6) = 80
   RA(8, 7) = 61: RA(8, 8) = 42
   
   RA(9, 1) = 33: RA(9, 2) = 71: RA(9, 3) = 71: RA(9, 4) = 90: RA(9, 5) = 90: RA(9, 6) = 90
   RA(9, 7) = 71: RA(9, 8) = 71: RA(9, 9) = 33
   
   RA(10, 1) = 43: RA(10, 2) = 81: RA(10, 3) = 81: RA(10, 4) = 100: RA(10, 5) = 100: RA(10, 6) = 100
   RA(10, 7) = 100: RA(10, 8) = 81: RA(10, 9) = 81: RA(10, 10) = 43
   
   RA(11, 1) = 34: RA(11, 2) = 72: RA(11, 3) = 91: RA(11, 4) = 91: RA(11, 5) = 110: RA(11, 6) = 110
   RA(11, 7) = 110: RA(11, 8) = 91: RA(11, 9) = 91: RA(11, 10) = 72: RA(11, 11) = 34
   
   RA(12, 1) = 44: RA(12, 2) = 82: RA(12, 3) = 101: RA(12, 4) = 101: RA(12, 5) = 120: RA(12, 6) = 120
   RA(12, 7) = 120: RA(12, 8) = 120: RA(12, 9) = 101: RA(12, 10) = 101: RA(12, 11) = 82: RA(12, 12) = 44:

'   RA(14, 1) = 44: RA(14, 2) = 82: RA(14, 3) = 101: RA(14, 4) = 101: RA(14, 5) = 120: RA(14, 6) = 120
'   RA(14, 7) = 120: RA(14, 8) = 120: RA(14, 9) = 101: RA(14, 10) = 101: RA(14, 11) = 82: RA(14, 12) = 44:
'   RA(14, 13) = 120: RA(14, 14) = 44
'
'   RA(16, 1) = 44: RA(16, 2) = 82: RA(16, 3) = 101: RA(16, 4) = 101: RA(16, 5) = 120: RA(16, 6) = 120
'   RA(16, 7) = 120: RA(16, 8) = 120: RA(16, 9) = 101: RA(16, 10) = 101: RA(16, 11) = 82: RA(16, 12) = 44:
'   RA(16, 13) = 120: RA(16, 14) = 44: RA(16, 15) = 44: RA(16, 16) = 44
'
'   RA(18, 1) = 44: RA(18, 2) = 82: RA(18, 3) = 101: RA(18, 4) = 101: RA(18, 5) = 120: RA(18, 6) = 120
'   RA(18, 7) = 120: RA(18, 8) = 120: RA(18, 9) = 101: RA(18, 10) = 101: RA(18, 11) = 82: RA(18, 12) = 44:
'   RA(18, 13) = 120: RA(18, 14) = 44: RA(18, 15) = 44: RA(18, 16) = 44: RA(18, 17) = 44: RA(18, 18) = 44
'
'   RA(20, 1) = 44: RA(20, 2) = 82: RA(20, 3) = 101: RA(20, 4) = 101: RA(20, 5) = 120: RA(20, 6) = 120
'   RA(20, 7) = 120: RA(20, 8) = 120: RA(20, 9) = 101: RA(20, 10) = 101: RA(20, 11) = 82: RA(20, 12) = 44:
'   RA(20, 13) = 120: RA(20, 14) = 44: RA(20, 15) = 44: RA(20, 16) = 44: RA(20, 17) = 44: RA(20, 18) = 44
'   RA(20, 19) = 44: RA(20, 20) = 44
'
'   RA(22, 1) = 44: RA(22, 2) = 82: RA(22, 3) = 101: RA(22, 4) = 101: RA(22, 5) = 120: RA(22, 6) = 120
'   RA(22, 7) = 120: RA(22, 8) = 120: RA(22, 9) = 101: RA(22, 10) = 101: RA(22, 11) = 82: RA(22, 12) = 44:
'   RA(22, 13) = 120: RA(22, 14) = 44: RA(22, 15) = 44: RA(22, 16) = 44: RA(22, 17) = 44: RA(22, 18) = 44
'   RA(22, 19) = 44: RA(22, 20) = 44: RA(22, 21) = 44: RA(22, 22) = 44
'
'   RA(24, 1) = 107: RA(24, 2) = 145: RA(24, 3) = 164: RA(24, 4) = 183: RA(24, 5) = 202: RA(24, 6) = 202
'   RA(24, 7) = 221: RA(24, 8) = 221: RA(24, 9) = 221: RA(24, 10) = 240: RA(24, 11) = 240: RA(24, 12) = 240
'   RA(24, 13) = 240: RA(24, 14) = 240: RA(24, 15) = 240: RA(24, 16) = 221: RA(24, 17) = 221: RA(24, 18) = 221
'   RA(24, 19) = 202: RA(24, 20) = 202: RA(24, 21) = 183: RA(24, 22) = 164: RA(24, 23) = 145: RA(24, 24) = 107
   
End Sub

                         
