Public Class Form1 Private img As New Bitmap(300, 300) '300x300サイズのImage Private g As Graphics, CID(5) As Color, Dtype As Boolean Private DTH As Double = Math.PI * 2 / 3, DX As Double = 2 * Math.Sqrt(3) - 3 Private StTH As Double = Math.PI / 6 Private Sub drawCircle(X0 As Double, Y0 As Double, R As Double, ID As Integer) Dim IX As Integer, IY As Integer, IR2 As Integer IX = X0 - R + 0.5 : IY = Y0 - R + 0.5 : IR2 = R * 2 + 0.5 If IR2 < 2 Then img.SetPixel(IX, IY, CID(ID Mod 5)) Else g.FillEllipse(New SolidBrush(CID(ID Mod 5)), IX, IY, IR2, IR2) End If End Sub Private Sub Carpet(X0 As Double, Y0 As Double, R As Double, ID As Integer) Dim RR As Double, RX As Double, XX As Double, YY As Double Dim TH As Double If Dtype Then drawCircle(X0, Y0, R, ID) If R < 1 Then If Not Dtype Then drawCircle(X0, Y0, R, ID) Else RR = DX * R : RX = R - RR : TH = StTH If Not Dtype Then drawCircle(X0, Y0, R - 2 * RR, ID + 1) For i = 1 To 3 XX = X0 + Math.Cos(TH) * RX YY = Y0 + Math.Sin(TH) * RX Carpet(XX, YY, RR, ID + 1) TH = TH + DTH Next Carpet(X0, Y0, R - 2 * RR, ID + 2) End If End Sub Private Sub initData() CID(0) = Color.YellowGreen : CID(1) = Color.DarkGreen : CID(2) = Color.DarkBlue CID(3) = Color.Red : CID(4) = Color.Yellow Dtype = RadioButton1.Checked g = Graphics.FromImage(img) : g.Clear(Color.White) End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click initData() Carpet(150, 150, 100, 0) PictureBox1.Image = img : g.Dispose() 'リソースを解放する End Sub End Class