VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Polygon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Const Pi = 3.14159265359
Dim Obj As Object  ' This holds Form or Picture box object

Public Sub DrawAngle(x As Long, Y As Long, Degree As Single, Length As Long)
Dim eX As Single
Dim eY As Single

    Degree = Degree
    Degree = Degree * Pi / 180 'converting to Degree from radian
    
    eX = x + Length * Sin(Degree)
    eY = Y - Length * Cos(Degree)
    
    Obj.Line (x, Y)-(eX, eY)

End Sub


Public Property Set SetObj(ByVal vNewValue As Object)
If TypeOf vNewValue Is Form Or TypeOf vNewValue Is PictureBox Then
Set Obj = vNewValue
Else
MsgBox "The value of SetObj property must be either the name of Form or Picturebox." _
+ vbCrLf + "Use the following code" + vbCrLf + vbCrLf + "Dim O As New Star" + vbCrLf + "Set O.SetObj = Form1"

End
End If
End Property

Public Function Draw_Poly(x As Long, Y As Long, Sides As Integer, Radius As Integer, LineFrCenter As Boolean, rotation As Single)
Dim First As Boolean
Dim PIE As Single
Dim Angle As Single
Dim Px As Single, Py As Single
First = True
PIE = Pi / 180

Dim S As Single: S = 360 / Sides



    For Angle = 0 To 360 * PIE + S Step S * PIE
        Px = x + Radius * Sin(Angle + (rotation * PIE)) 'Px= X of first point
        Py = Y - Radius * Cos(Angle + (rotation * PIE)) 'Py =Y of first point
        If First Then Obj.PSet (Px, Py): First = False 'Making them current for first time with
        If Not First Then Obj.Line -(Px, Py) 'with PSET method then Drawing the line from there
        If LineFrCenter Then Obj.Line (x, Y)-(Px, Py) ' This draws line from center if required
    Next Angle
    
End Function

Public Sub FreeRes()
    Set Obj = Nothing
End Sub
