Microsoft Office Tutorials and References
In Depth Information
Figure A-5. A hypocycloid
Sub DrawHypocycloid()
' Draw hypocycloid of small stars
Const pi = 3.1416
Dim t As Single
Dim i As Integer
Dim x As Single, y As Single
Dim rng As Range ' For starting point
Dim n As Single
Dim k As Integer
Dim sSize As Single ' Star size
Dim r As Integer
Dim r0 As Integer
Dim R1 As Integer
Dim sh As Shape
Dim sc As Single
Dim StartLeft As Integer
Dim StartTop As Integer
' Starting position
StartLeft = ActiveCell.Left
StartTop = ActiveCell.Top
r = 1
r0 = 3 * r
R1 = 8 * r
n = 400
k = 4
sc = 0.1
sSize = Application.InchesToPoints(0.03)
' Start curve at insertion point
Set rng = ActiveCell
For i = 1 To n
t = k * pi * i / n
x = (R1 - r) * Cos(t) + r0 * Cos(t * (R1 - r) / r)
y = (R1 - r) * Sin(t) - r0 * Sin(t * (R1 - r) / r)
x = sc * x
y = sc * y
x = Application.InchesToPoints(x)
y = Application.InchesToPoints(y)
Set sh = ActiveSheet.Shapes.AddShape _
(msoShape5pointStar, StartLeft + x, StartTop + y, sSize,
sSize)
Next i
End Sub
The results are shown in Figure A-5 . (The small vertical bar in Figure A-5 indicates the left edge
of the active cell.
Figure A-5. A hypocycloid
 
 
 
Search JabSto ::




Custom Search