Public Class Form1 'this is a trochoid curve Dim x(10000) As Integer Dim y(10000) As Integer 'these are points on curve Const xs As Integer = 650 Const ys As Integer = 675 'start point at bottom of page Dim n As Integer 'the timer count Dim gonow As Integer Dim fast As Integer Dim xi As Integer Dim yi As Integer 'inner circle ellipse box Dim ri As Integer = 165 'inner circle defining points Dim cpen As New System.Drawing.Pen(System.Drawing.Color.Green, 1) 'start green Dim col As Integer = 0 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim g As Graphics = CreateGraphics() If gonow = 1 And fast = 0 Then g.DrawEllipse(Pens.White, xi, yi, 2 * ri, 2 * ri) 'erase previous red inner calc() g.DrawEllipse(Pens.Cyan, xi, yi, 2 * ri, 2 * ri) 'rotates anticlock from the bottom For i = 1 To n g.DrawLine(cpen, x(i - 1), y(i - 1), x(i), y(i)) 'this draws entire curve so white does not erase Next x(n) = x(n + 1) y(n) = y(n + 1) n = n + 1 If n = 10000 Then gonow = 0 'used up x,y array MsgBox("You can see how the curve is going. See final curve or start over", 0) End If End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click gonow = 1 'start drawing x(0) = xs y(0) = ys 'first point on curve xi = 450 + ri yi = 675 - 2 * ri 'first point in centre of inner n = 0 'first count End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Invalidate() 'clear existing page of drawing gonow = 0 'start a new graph fast = 0 'clear all buttons n = 0 'set all start values End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Function calc() 'the next point in the curve Const rpc As Double = 2 * Math.PI Dim angstep As Double 'angle outer moves Dim inang As Double 'angle inner moves angstep = (n * rpc) / 360 'the rotation angle of outer wheel inang = angstep * 325 / ri 'inner circle angle xi = (325 - ri) * Math.Sin(angstep) + (650 - 2 * ri) yi = (325 - ri) * Math.Cos(angstep) + (350 - 2 * ri) 'this is the centre of the inner circle xi = xi + ri yi = yi + ri 'start x,y of draw.ellipse x(n + 1) = ri * Math.Sin(inang) + xi + ri y(n + 1) = ri * Math.Cos(inang) + yi + ri 'next point on curve Return xi Return yi Return x(n + 1) Return y(n + 1) End Function Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim g As Graphics = CreateGraphics() g.DrawRectangle(Pens.Blue, 320, 20, 660, 660) 'a border g.FillRectangle(Brushes.White, 321, 21, 659, 659) g.DrawEllipse(Pens.Cyan, 323, 23, 655, 655) 'this is outer circle End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click fast = 1 'lets go fast Const rpc As Double = 2 * Math.PI Dim angstep As Double 'angle outer moves Dim inang As Double 'angle inner moves Dim xf As Integer = xs Dim yf As Integer = ys 'start of curve Dim xn As Integer Dim yn As Integer 'nextpoint on curve Dim g As Graphics = CreateGraphics() n = 1 'next point For i = 1 To 60000 angstep = (n * rpc) / 360 'the rotation angle of outer wheel inang = angstep * 325 / ri 'inner circle angle xi = (325 - ri) * Math.Sin(angstep) + (650 - 2 * ri) yi = (325 - ri) * Math.Cos(angstep) + (350 - 2 * ri) 'this is the centre of the inner circle xi = xi + ri yi = yi + ri 'start x,y of draw.ellipse xn = ri * Math.Sin(inang) + xi + ri yn = ri * Math.Cos(inang) + yi + ri 'next point on curve g.DrawLine(cpen, xf, yf, xn, yn) n = n + 1 xf = xn yf = yn 'next point Next End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged cpen.Color = Color.Green End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged cpen.Color = Color.Red End Sub Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged cpen.Color = Color.Blue End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim radius As String Dim noerr As Integer = 0 For i = 10 To 315 radius = i If radius = TextBox1.Text Then ri = radius noerr = 1 End If Next If noerr = 0 Then MsgBox("radius must be a number between 10 and 315", 16) End If End Sub End Class