Public Class Form1 Private img As New Bitmap(500, 500) '500x500サイズのImage Private gf As Graphics Dim k As Double, B As Double, DT As Double, NSEP As Integer, DB As Double Dim check As Boolean = True Private Sub InitData() k = Val(TextBox1.Text) B = Val(TextBox2.Text) DB = Val(TextBox3.Text) check = CheckBox1.Checked NSEP = 800 : DT = 2 * Math.PI / NSEP End Sub Private Function RED(I As Integer) As Integer RED = (I Mod &H1000000) \ &H10000 End Function Private Function GREEN(I As Integer) As Integer GREEN = (I Mod &H10000) \ &H100 End Function Private Function BLUE(I As Integer) As Integer BLUE = I Mod &H100 End Function Private Function intX(X As Double) As Integer If check Then intX = X * 100 + 0.5 Else intX = 250 + X * 40 + 0.5 End If End Function Private Function intY(Y As Double) As Integer intY = 250 - Y * 20 + 0.5 End Function Private Sub drawPic(X As Double, Y As Double, i As Integer) Dim IX As Integer = intX(X), IY As Integer = intY(Y) If IX >= 0 And IX < img.Width And IY >= 0 And IY < img.Height Then img.SetPixel(intX(X), intY(Y), Color.FromArgb(RED(i), GREEN(i), BLUE(i))) End If End Sub Private Sub drawAttract() Cursor.Current = Cursors.WaitCursor gf = Graphics.FromImage(img) : gf.Clear(Color.Black) '描画クリア Dim T As Double = 0, X As Double = 0.2, Y As Double = 0.1 Dim XN As Double, YN As Double, i As Integer, DX As Double, DY As Double Dim iflag As Boolean For j = 1 To 8000 iflag = True For i = 1 To NSEP If Not check Then drawPic(X, Y, j * 127) DX = Y * DT : DY = (-k * Y - X * X * X + B * Math.Cos(T)) * DT XN = X + DX : YN = Y + DY If XN > 100 Or XN < -100 Or YN > 100 Or YN < -100 Then iflag = False : Exit For End If T = T + DT : X = XN : Y = YN Next If iflag Then drawPic(X, Y, j * 127) Next PictureBox1.Image = img : gf.Dispose() Cursor.Current = Cursors.Default End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click InitData() Timer1.Enabled = True End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick If B > 12.07 Then Timer1.Enabled = False Else Label1.Text = Format(B, "B = #0.00") drawAttract() B = B + DB End If End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Timer1.Enabled = False End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click InitData() drawAttract() End Sub End Class