Hi ALL, here is a method to produce a SPIRAL. You can specify startRadius, endRadius, direction and distanceBetweenTurnsInPixels as well as the startAngle. Enjoy!!

# Hi ALL, here is a method to produce a SPIRAL. You can specify startRadius, endRadius, direction and distanceBetweenTurnsInPixels as well as the startAngle. Enjoy!!

• Monday, April 30, 2012 10:56 PM

Hi ALL,

Here is some code you can play around with.  :)

I thought it was better that you can specify a value for the endRadius so you can limit the spiral.

Please note: For this to work startRadius must be greater than the value for endRadius as the

Please also note the distanceBetweenTurnsInPixels , so for one full turn make the difference in the startRadius and endRadius

equal to this distance.

Try different values for these variables.>>

```        Dim startRadius As Double = (Me.Height / 2) - 50
Dim endRadius As Integer = 50
Dim dir As Direction = Direction.Clockwise
Dim distanceBetweenTurnsInPixels As Integer = 50
'Please note the startAngle is from the EAST direction
' in the direction specified by the variable 'dir' as Direction.>>
Dim startAngleInDegrees As Double = 45```

_________________________

Here is the code in full. Enjoy!!

_________________________

>>

_________________________

```Public Class Form1

Const PiTimesTwo As Double = Math.PI * 2
Const DegreesInOneRadian As Double = 180 / Math.PI

Public Enum Direction
AntiClockwise = -1
Clockwise = 1
End Enum

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Me.BackColor = Color.Black
Me.WindowState = FormWindowState.Maximized

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim startRadius As Double = (Me.Height / 2) - 50
Dim endRadius As Integer = 50
Dim dir As Direction = Direction.Clockwise
Dim distanceBetweenTurnsInPixels As Integer = 50
'Please note the startAngle is from the EAST direction
' in the direction specified by the variable 'dir' as Direction.>>
Dim startAngleInDegrees As Double = 45

Dim angle1 As Double = startAngleInDegrees / DegreesInOneRadian
Dim angle2 As Double = (startAngleInDegrees + 360) / DegreesInOneRadian
Dim x1, y1 As Double
Dim myPen As New Pen(Color.White, 1)
Dim mypoints As New List(Of Point)

Do
For index As Double = angle1 To angle2 Step 0.05
x1 = radius * Math.Cos(index) + (Me.Width \ 2)
y1 = dir * radius * Math.Sin(index) + (Me.Height \ 2)
Next
Loop

e.Graphics.DrawCurve(myPen, mypoints.ToArray)

End Sub

End Class```

'--------------------------------------------------------------------------

If anyone wants a version to start at a specific angle and spiral outwards

then I can post an altered version of the above code, just say yes please.

##### Regards,

Click this link to see the NEW way of how to insert a picture into a forum post.

Installing VB6 on Windows 7

App Hub for Windows Phone & XBOX 360 developers.

### All Replies

• Tuesday, May 01, 2012 11:03 AM

Lol, I tried it, it is intresting. :)

Ghost,
Call me ghost for short, Thanks
To get the better answer, it should be a better question.

• Tuesday, May 01, 2012 11:55 PM