Public Class Form1 Private img As New Bitmap(500, 500) '500x500サイズのImage Private gf As Graphics Private a As Double, b As Double, dt As Double, g As Double, dg As Double Private XS As Double, YS As Double, ZS As Double Private Function screenX(X As Double, Y As Double) As Double Return 5 * (X - 0.6 * Y) + 200 End Function Private Function screenY(Y As Double, Z As Double) As Double Return 300 - 5 * (Z - 0.6 * Y) End Function Private Sub Line3D(X1 As Double, Y1 As Double, Z1 As Double, _ X2 As Double, Y2 As Double, Z2 As Double, C As Color) Dim XS1 As Integer = screenX(X1, Y1) + 0.5 Dim YS1 As Integer = screenY(Y1, Z1) + 0.5 Dim XS2 As Integer = screenX(X2, Y2) + 0.5 Dim YS2 As Integer = screenY(Y2, Z2) + 0.5 gf.DrawLine(New Pen(C), XS1, YS1, XS2, YS2) End Sub Private Sub Point3D(X1 As Double, Y1 As Double, Z1 As Double, C As Color) Dim XS1 As Integer = screenX(X1, Y1) + 0.5 Dim YS1 As Integer = screenY(Y1, Z1) + 0.5 img.SetPixel(XS1, YS1, C) End Sub Private Sub Coord3D() Line3D(-30, 0, 0, 50, 0, 0, Color.Red) Line3D(0, -30, 0, 0, 50, 0, Color.DarkGreen) Line3D(0, 0, -30, 0, 0, 50, Color.DarkBlue) End Sub Private Sub initData() a = Val(TextBox1.Text) : b = Val(TextBox2.Text) dt = Val(TextBox3.Text) : g = Val(TextBox4.Text) dg = Val(TextBox5.Text) XS = Val(TextBox6.Text) : YS = Val(TextBox6.Text) : ZS = Val(TextBox6.Text) End Sub Private Sub Attractor() gf = Graphics.FromImage(img) : gf.Clear(Color.Black) '描画クリア Dim X As Double = XS, Y As Double = XS, Z As Double = YS Dim XN As Double, YN As Double, ZN As Double, i As Integer Coord3D() For i = 1 To 6000 XN = X + dt * a * (Y - X) YN = Y + dt * (-X * Z + g * X - Y) ZN = Z + dt * (X * Y - b * Z) Line3D(X, Y, 0, XN, YN, 0, Color.YellowGreen) Line3D(X, 0, Z, XN, 0, ZN, Color.Blue) Line3D(X, Y, Z, XN, YN, ZN, Color.Yellow) X = XN : Y = YN : Z = ZN Next PictureBox1.Image = img : gf.Dispose() 'リソースを解放する End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click initData() : Attractor() End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click initData() Timer1.Enabled = True End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick If g >= 30 Then Timer1.Enabled = False Else Attractor() : g = g + dg : TextBox4.Text = g End If End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click Timer1.Enabled = False End Sub End Class