Public Class Form1 Private img As New Bitmap(300, 300) '300x300サイズのImage Private g As Graphics = Graphics.FromImage(img) Private CID(5) As Color, dType As Boolean, dType2 As Boolean Private DTH As Double, stTH As Double, DL As Double, DR As Double Private NumDiv As Integer 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 : IY = Y0 - R : IR2 = R * 2 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, RR2 As Double, L 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 = DR * R : L = DL * R : RR2 = L + RR : TH = stTH If dType2 Then drawCircle(X0, Y0, L, ID) For i = 1 To NumDiv XX = X0 + Math.Cos(TH) * RR2 YY = Y0 + Math.Sin(TH) * RR2 Carpet(XX, YY, RR, ID + 1) TH = TH + DTH Next Carpet(X0, Y0, L, ID + 2) End If End Sub Private Sub initData() Dim TH As Double, sinTH As Double CID(0) = Color.Red : CID(1) = Color.Blue : CID(2) = Color.BlueViolet CID(3) = Color.Yellow : CID(4) = Color.Green g = Graphics.FromImage(img) : g.Clear(Color.White) dType = RadioButton1.Checked dType2 = RadioButton2.Checked NumDiv = Val(TextBox1.Text) TH = Math.PI / NumDiv : DTH = 2 * TH : stTH = DTH - Math.PI * 0.5 sinTH = Math.Sin(TH) DR = sinTH / (1 + sinTH) : DL = (1 - sinTH) / (1 + sinTH) 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