プログラムは簡単に描画するため「Visual Studio」で「Visual Basic」を使用しました。
各プログラムは、基本的に同じですが、それぞれの色相を変化させるために各プログラムを
少し変化させています。
色付けには、繰返し回数を使用しています。
1.プログラム。
kは、繰返しの計算回数です。i, jは縦横の位置です。
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click REM マンデルブロート1, 2016/12/06 Dim xmin, xmax, ymin, ymax As Double Dim cr, ci, dx, dy, zr, zi, wr, wi As Double Dim i, j, k, r, g, b As Integer Dim gr As Graphics = PictureBox1.CreateGraphics Dim w As Integer = PictureBox1.ClientRectangle.Width Dim h As Integer = PictureBox1.ClientRectangle.Height gr.Clear(PictureBox1.BackColor) xmin = Val(TextBox1.Text) xmax = Val(TextBox2.Text) ymin = Val(TextBox3.Text) ymax = Val(TextBox4.Text) dx = (xmax - xmin) / w dy = (ymax - ymin) / h For i = 0 To h - 1 For j = 0 To w - 1 cr = xmin + j * dx ci = ymin + i * dy zr = 0 zi = 0 For k = 0 To 600 wr = zr * zr - zi * zi + cr wi = 2 * zr * zi + ci If (wr * wr + wi * wi > 4) Then Exit For zr = wr : zi = wi Next If (k Mod 3) = 0 Then r = 255 : g = 0 : b = 0 Else r = k : g = k + 64 : b = k + 128 End If gr.DrawRectangle(New Pen(ColorTranslator.FromOle(RGB(r, g, b))), j, i, 1, 1) Next Next End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click End End Sub End Class
2.描画結果です。
1.プログラム。
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click REM マンデルブロート2, 2016/12/06 Dim Res, Ree, Ims, Ime As Double Dim Re, Im As Double Dim dr, di, zr, zi As Double Dim cr, ci As Double Dim i, j, c, k As Integer Dim g As Graphics = PictureBox1.CreateGraphics Dim mybrush As New SolidBrush(Color.Black) Dim wi As Integer = PictureBox1.ClientRectangle.Width Dim he As Integer = PictureBox1.ClientRectangle.Height g.Clear(PictureBox1.BackColor) Res = Val(TextBox1.Text) Ree = Val(TextBox2.Text) Ims = Val(TextBox3.Text) Ime = Val(TextBox4.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 cr = Res + j * dr ci = Ims + i * di zr = 0 zi = 0 For k = 0 To 600 Re = zr * zr - zi * zi + cr Im = 2 * zr * zi + ci If (Re * Re + Im * Im > 4) Then Exit For zr = Re : zi = Im Next c = k Mod 7 Select Case c Case 0 mybrush.Color = Color.Yellow Case 1 mybrush.Color = Color.Magenta Case 2 mybrush.Color = Color.Red Case 3 mybrush.Color = Color.Lime Case 4 mybrush.Color = Color.Pink Case 5 mybrush.Color = Color.Gold Case 6 mybrush.Color = Color.Black End Select g.FillRectangle(mybrush, j, i, 1, 1) Next Next End Sub End Class
2.描画結果です。
1.プログラム。
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click REM マンデルブロート2, 2016/12/06 Dim Res, Ree, Ims, Ime As Double Dim Re, Im As Double Dim dr, di, zr, zi As Double Dim cr, ci As Double Dim i, j, c, k, r, g, b, d As Integer Dim gr As Graphics = PictureBox1.CreateGraphics Dim mybrush As New SolidBrush(Color.Black) Dim wi As Integer = PictureBox1.ClientRectangle.Width Dim he As Integer = PictureBox1.ClientRectangle.Height gr.Clear(PictureBox1.BackColor) Res = Val(TextBox1.Text) Ree = Val(TextBox2.Text) Ims = Val(TextBox3.Text) Ime = Val(TextBox4.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 cr = Res + j * dr ci = Ims + i * di zr = 0 zi = 0 For k = 0 To 1023 Re = zr * zr - zi * zi + cr Im = 2 * zr * zi + ci If (Re * Re + Im * Im > 4) Then Exit For zr = Re : zi = Im Next d = (k Mod 64) * 4 If d <= 0 Then r = 0 : g = 0 : b = 0 Else c = Int(d / 43) Select Case c Case 0 r = 255 : g = d * 5 : b = 0 Case 1 r = (88 - d) * 5 : g = 255 : b = 0 Case 2 r = 0 : g = 255 : b = (d - 86) * 5 Case 3 r = 0 : g = (172 - d) * 5 : b = 255 Case 4 r = (d - 172) * 5 : g = 0 : b = 255 Case 5 r = 255 : g = 0 : b = (255 - d) * 5 End Select End If gr.DrawRectangle(New Pen(ColorTranslator.FromOle(RGB(r, g, b))), j, i, 1, 1) Next Next End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click End End Sub End Class
2.描画結果です。
1.プログラム。
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click REM マンデルブロート2, 2016/12/06 Dim Res, Ree, Ims, Ime As Double Dim Re, Im As Double Dim dr, di, zr, zi As Double Dim cr, ci As Double Dim i, j, c, k, r, g, b, d As Integer Dim gr As Graphics = PictureBox1.CreateGraphics Dim mybrush As New SolidBrush(Color.Black) Dim wi As Integer = PictureBox1.ClientRectangle.Width Dim he As Integer = PictureBox1.ClientRectangle.Height gr.Clear(PictureBox1.BackColor) Res = Val(TextBox1.Text) Ree = Val(TextBox2.Text) Ims = Val(TextBox3.Text) Ime = Val(TextBox4.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 cr = Res + j * dr ci = Ims + i * di zr = 0 zi = 0 For k = 0 To 1023 Re = zr * zr - zi * zi + cr Im = 2 * zr * zi + ci If (Re * Re + Im * Im > 4) Then Exit For zr = Re : zi = Im Next d = (k Mod 32) * 8 c = Int(d / 42.667) Select Case c Case 0 r = 0 : g = d * 6 : b = 255 Case 1 r = 0 : g = 255 : b = 255 - 6 * (d - 43) Case 2 r = 6 * (d - 86) : g = 255 : b = 0 Case 3 r = 255 : g = 255 - 6 * (d - 129) : b = 0 Case 4 r = 255 : g = 0 : b = 6 * (d - 171) Case 5 r = 255 - 6 * (d - 214) : g = 0 : b = 255 Case Else r = 0 : g = 0 : b = 0 End Select gr.DrawRectangle(New Pen(ColorTranslator.FromOle(RGB(r, g, b))), j, i, 1, 1) Next Next End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click End End Sub End Class
2.描画結果です。
1.プログラム。
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click REM マンデルブロート2, 2016/12/06 Dim Res, Ree, Ims, Ime As Double Dim Re, Im As Double Dim dr, di, zr, zi As Double Dim cr, ci As Double Dim i, j, c, k As Integer Dim g As Graphics = PictureBox1.CreateGraphics Dim mybrush As New SolidBrush(Color.Black) Dim wi As Integer = PictureBox1.ClientRectangle.Width Dim he As Integer = PictureBox1.ClientRectangle.Height g.Clear(PictureBox1.BackColor) Res = Val(TextBox1.Text) Ree = Val(TextBox2.Text) Ims = Val(TextBox3.Text) Ime = Val(TextBox4.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 cr = Res + j * dr ci = Ims + i * di zr = 0 zi = 0 For k = 0 To 600 Re = zr * zr - zi * zi + cr Im = 2 * zr * zi + ci If (Re * Re + Im * Im > 4) Then Exit For zr = Re : zi = Im Next c = k Mod 7 Select Case c Case 0 mybrush.Color = Color.DeepPink Case 1 mybrush.Color = Color.Magenta Case 2 mybrush.Color = Color.HotPink Case 3 mybrush.Color = Color.LightPink Case 4 mybrush.Color = Color.Pink Case 5 mybrush.Color = Color.PeachPuff Case 6 mybrush.Color = Color.Red End Select g.FillRectangle(mybrush, j, i, 1, 1) Next Next End Sub End Class
2.描画結果です。