Example A Draw Sine to Generate a Dampened Sine Curve of Small Stars

Sub DrawSine2()

' Dampened sine wave of small stars Const pi = 3.1416

Dim i As Integer

Dim x As Single, y As Single

Dim rng As Range ' For starting point

Dim n As Single ' Cycle length in inches

Dim k As Integer ' k stars

Dim ScaleY As Single ' Vertical scaling

Dim sSize As Single ' Star size

Dim sDamp1 As Single ' Dampening factor

Dim sDamp2 As Single ' Dampening factor

Dim cCycles As Integer ' Number of cycles

Dim sh As Shape

Dim StartLeft As Integer

Dim StartTop As Integer

' Starting position StartLeft = ActiveCell.Left

StartTop = ActiveCell.Top cCycles = 3 sDampl = 1 sDamp2 = 0.2 n = 2 k = 20

sSize = Application.InchesToPoints(O.l)

' 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) * _

(sDampl / (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.

Was this article helpful?

0 -1

Post a comment