プログラムは簡単に描画するため「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 flactal3, 2016/12/04 Dim xmin, xmax, ymin, ymax As Double Dim ar, ai, 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) ar = Val(TextBox5.Text) ai = Val(TextBox6.Text) dx = (xmax - xmin) / w dy = (ymax - ymin) / h For i = 0 To h - 1 For j = 0 To w - 1 zr = xmin + j * dx zi = ymin + i * dy For k = 0 To 1023 wr = zr * zr - zi * zi + ar wi = 2 * zr * zi + ai If (wr * wr + wi * wi > 4) Then Exit For zr = wr : zi = wi Next If k > 500 Then r = k 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 Dim Res, Ree, Ims, Ime As Double Dim Ar, Ai As Double Dim dr, di, zr, zi As Double Dim Re, Im 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) Ar = Val(TextBox5.Text) Ai = Val(TextBox6.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 zr = Res + j * dr zi = Ims + i * di For k = 0 To 1023 Re = zr * zr - zi * zi + Ar Im = 2 * zr * zi + Ai 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 = (85 - d) * 6 Case 2 r = (d - 86) * 6 : g = 255 : b = 0 Case 3 r = 255 : g = (171 - d) * 6 : b = 0 Case 4 r = 255 : g = 0 : b = (d - 172) * 6 Case 5 r = (255 - d) * 6 : 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 Dim Res, Ree, Ims, Ime As Double Dim Ar, Ai As Double Dim dr, di, zr, zi As Double Dim Re, Im 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) Ar = Val(TextBox5.Text) Ai = Val(TextBox6.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 zr = Res + j * dr zi = Ims + i * di For k = 0 To 1023 Re = zr * zr - zi * zi + Ar Im = 2 * zr * zi + Ai If (Re * Re + Im * Im > 4) Then Exit For zr = Re : zi = Im Next d = (k Mod 32) * 8 If d <= 0 Then r = 0 : g = 0 : b = 0 Else 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 End Select End If gr.DrawRectangle(New Pen(ColorTranslator.FromOle(RGB(r, g, b))), 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 Dim Res, Ree, Ims, Ime As Double Dim Ar, Ai As Double Dim dr, di, zr, zi As Double Dim Re, Im 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) Ar = Val(TextBox5.Text) Ai = Val(TextBox6.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 zr = Res + j * dr zi = Ims + i * di For k = 0 To 1023 Re = zr * zr - zi * zi + Ar Im = 2 * zr * zi + Ai 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 End Class
2.描画結果です。
1.プログラム。
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim Res, Ree, Ims, Ime As Double Dim Ar, Ai As Double Dim dr, di, zr, zi As Double Dim Re, Im 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) Ar = Val(TextBox5.Text) Ai = Val(TextBox6.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 zr = Res + j * dr zi = Ims + i * di For k = 0 To 1023 Re = zr * zr - zi * zi + Ar Im = 2 * zr * zi + Ai 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.Black Case 3 mybrush.Color = Color.Lime Case 4 mybrush.Color = Color.Pink Case 5 mybrush.Color = Color.Gold Case 6 mybrush.Color = Color.Red End Select gr.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 Dim Res, Ree, Ims, Ime As Double Dim Ar, Ai As Double Dim dr, di, zr, zi As Double Dim Re, Im 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) Ar = Val(TextBox5.Text) Ai = Val(TextBox6.Text) dr = (Ree - Res) / wi di = (Ime - Ims) / he For i = 0 To he - 1 For j = 0 To wi - 1 zr = Res + j * dr zi = Ims + i * di For k = 0 To 1023 Re = zr * zr - zi * zi + Ar Im = 2 * zr * zi + Ai 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.Blue Case 1 mybrush.Color = Color.DarkBlue Case 2 mybrush.Color = Color.MidnightBlue Case 3 mybrush.Color = Color.MediumBlue Case 4 mybrush.Color = Color.LightSkyBlue Case 5 mybrush.Color = Color.LightBlue Case 6 mybrush.Color = Color.PowderBlue End Select gr.FillRectangle(mybrush, j, i, 1, 1) Next Next End Sub End Class
2.描画結果です。