Sub test_A()
ActiveSheet.DrawingObjects.Delete
Randomize 1600
DessinerCardioide 160, Application.RandBetween(0, 6)
End Sub
Sub test_B()
ActiveSheet.DrawingObjects.Delete
DessinerCardioide 500, 6
End Sub
Sub test_C()
ActiveSheet.DrawingObjects.Delete
DessinerCardioide 350, 51
End Sub
Private Sub DessinerCardioide(nbpts%, pas)
Dim r%, x0%, y0%, i%, j%, tablo As Variant, vPi As Double, TT As Double
Dim cercle As Shape, ligne As Shape
vPi = 4 * Atn(1): x0 = 250: y0 = 250: r = 200: npoints = nbpts: step = pas
'Ajout cercle
Set cercle = ActiveSheet.Shapes.AddShape(msoShapeOval, x0 - r, y0 - r, 2 * r, 2 * r)
cercle.Line.ForeColor.RGB = vbRed: cercle.Fill.ForeColor.RGB = vbBlack: cercle.Line.Weight = 0.1
ReDim tablo(1 To npoints, 1 To 2)
'Dessin points
For i = 1 To npoints
TT = (i - 1) * 2 * vPi / npoints
tablo(i, 1) = x0 + r * Cos(TT): tablo(i, 2) = y0 - r * Sin(TT)
Set pts = ActiveSheet.Shapes.AddShape(9, tablo(i, 1) - 2, tablo(i, 2) - 2, 4, 4)
pts.Line.ForeColor.RGB = vbBlue: pts.Fill.ForeColor.RGB = vbBlue
Next i
'Dessin Cardiode
j = npoints / 2 + 1
For i = 1 To npoints
Set ligne = ActiveSheet.Shapes.AddLine(tablo(i, 1), tablo(i, 2), tablo(j, 1), tablo(j, 2))
ligne.Line.ForeColor.RGB = vbRed: ligne.Line.Weight = 0.9
j = (j + step - 1) Mod npoints + 1
Next i
End Sub
'Crédits: garnote et Arnaldo Gunzi