Figure A Random stars spelling a name

Example A-6 prints a hypocycloid. (It may take a few minutes to complete.) Example A-6. The DrawHypocycloid Procedure

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

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,

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.

0 0

Post a comment