Microsoft Office Tutorials and References
In Depth Information
Figure A-3. A dampened sine wave of stars
StartTop = ActiveCell.Top
cCycles = 3
sDamp1 = 1
sDamp2 = 0.2
n = 2
k = 20
ScaleY = 0.5
sSize = Application.InchesToPoints(0.1)
' Loop for first curve with phase shift
For i = 1 To cCycles * k
x = n * i / k
y = ScaleY * Sin((2 * pi * i) / k + n) * _
(sDamp1 / (x + sDamp2))
y = Application.InchesToPoints(y)
x = Application.InchesToPoints(x)
Set sh = ActiveSheet.Shapes.AddShape _
(msoShape5pointStar, StartLeft + x, StartTop + y, sSize,
sSize)
sh.Fill.ForeColor.RGB = RGB(192, 192, 192) ' 25% gray
sh.Fill.Visible = msoTrue
Next i
End Sub
The output from this code is shown in Figure A-3 .
Figure A-3. A dampened sine wave of stars
The code in Example A-5 produces a random series of stars, each containing a single letter that
together spells a name. Note that each time the program is run, the pattern is different.
Example A-5. Code to Produce a Random Series of Stars
Sub DrawName()
' Random placement of large stars with name
Const pi = 3.1416
Dim i As Integer
Dim x As Single, y As Single
Dim z As Single
Dim rng As Range ' For starting point
Dim n As Single ' Cycle length in inches
Dim k As Integer ' k stars
Dim sSize As Single ' Star size
Dim sh As Shape
Dim sName As String ' Name to display
Dim StartLeft As Integer
Dim StartTop As Integer
 
 
 
 
Search JabSto ::




Custom Search