VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Star"
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 Enum StarStyles  ' Enum makes these value easily accessible
                        ' Pops up while using DrawStar method
    stNone = 0
    stStyle1 = 1
    stStyle2 = 2
    stStyle3 = 3
    stStyle4 = 4
    stStyle5 = 5
    stStyle6 = 6
    
End Enum

'This property procidure receives an object on which drawings are to be done.
'Input: The NAME property of Form or PictureBox object.
'Don't forget to use Set keyword while settig this property
'eg
'         Dim O As New Star
'         Set O.SetObj = Form1

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


'this frees object
Public Sub FreeRes()
    Set Obj = Nothing
End Sub

'Following procedure draws several kind of stars
Public Function DrawStar(X As Long, Y As Long, Insets As Integer, InsHeight As Integer, Radius As Integer, Lines As StarStyles, Rad3 As Single, offset As Single)

Dim PIE As Single: PIE = Pi / 180
Dim Px As Single, Py As Single, Px1 As Single, Py1 As Single
Dim Angle As Single, Stp As Single, Stp2 As Single, Rad2 As Single


Rad2 = Radius - InsHeight                   'Getting the inner radius from insets height
If Insets = 0 Then Insets = 1               'Preventing from division by zero error
Stp = (360 / Insets) * PIE: Stp2 = Stp / 2  'stp=steps=No. of insets

For Angle = 0 To 360 * PIE Step Stp         'Px & Py indicate the upper point from where two
                                            'Lines are drawn
                                            
    Px = X + Radius * Sin(Angle): Py = Y - Radius * Cos(Angle)
    Px1 = X + Rad2 * Sin(Angle - Stp2): Py1 = Y - Rad2 * Cos(Angle - Stp2)
    
    'the first line
    Obj.Line (Px1, Py1)-(Px, Py)
    
    'second point calculation
    Px1 = X + Rad2 * Sin(Angle + Stp2): Py1 = Y - Rad2 * Cos(Angle + Stp2)
    
    'drawing the second line it makes '>' shape of star
    Obj.Line (Px1, Py1)-(Px, Py)
    
    'following two lines are for various star style
    If Lines = stNone Then Obj.Circle (X + (Radius + offset) * Sin(Angle), Y - (Radius + offset) * Cos(Angle)), Rad3
    If Lines = stStyle1 Then Obj.Line (X, Y)-(Px, Py): Obj.Circle (X + (Radius + offset) * Sin(Angle), Y - (Radius + offset) * Cos(Angle)), Rad3
    If Lines = stStyle2 Then Obj.Line (X, Y)-(Px, Py): Obj.Line (X, Y)-(Px1, Py1): Obj.Circle (X + (Radius + offset) * Sin(Angle), Y - (Radius + offset) * Cos(Angle)), Rad3
    If Lines = stStyle3 Then Obj.Line (X, Y)-(Px1, Py1): Obj.Circle (X + (Radius + offset) * Sin(Angle), Y - (Radius + offset) * Cos(Angle)), Rad3
    If Lines = stStyle4 Then Obj.Line (X + Rad2 * Sin(Angle - Stp2), Y - Rad2 * Cos(Angle - Stp2))-(X + Rad2 * Sin(Angle + Stp2), Y - Rad2 * Cos(Angle + Stp2)): Obj.Circle (X + (Radius + offset) * Sin(Angle), Y - (Radius + offset) * Cos(Angle)), Rad3
    If Lines = stStyle5 Then Obj.Line (X + Rad2 * Sin(Angle - Stp2), Y - Rad2 * Cos(Angle - Stp2))-(X + Rad2 * Sin(Angle + Stp2), Y - Rad2 * Cos(Angle + Stp2)): Obj.Line (X, Y)-(Px1, Py1): Obj.Circle (X + (Radius + offset) * Sin(Angle), Y - (Radius + offset) * Cos(Angle)), Rad3
    If Lines = stStyle6 Then Obj.Line (X + Rad2 * Sin(Angle - Stp2), Y - Rad2 * Cos(Angle - Stp2))-(X + Rad2 * Sin(Angle + Stp2), Y - Rad2 * Cos(Angle + Stp2)): Obj.Line (X, Y)-(Px1, Py1): Obj.Line (X, Y)-(Px, Py): Obj.Circle (X + (Radius + offset) * Sin(Angle), Y - (Radius + offset) * Cos(Angle)), Rad3

Next Angle

End Function
