View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
jason jason is offline
external usenet poster
 
Posts: 104
Default creating a SPIRAL of stars in Excel

"not much of a mathematician" - hmmmmm - think u may be more of a
mathematician than you think!

Thanks KeepitCool

J

keepitcool wrote in message .. .
yep..

im not really a mathemagician..
and it took some puzzling

but!
..spiral draws within a given range Range
..star grows while spiralling
..renamed variables which makes it easier to understand and dimension.

have fun!


Option Explicit

Sub DrawSpiral()
Dim x#, y#, n#, s#, z#, i%
Dim poleX#, poleY#, rMax# 'Coordinates

Dim nSpokes%, nCircles# 'Quantities
Dim sMin#, sMax# 'Sizes

nSpokes = 20
nCircles = 4.25
sMin = 5
sMax = 20

With [a1:f15]
'Pole position
poleX = (.Left + .Width - sMax) / 2
poleY = (.Top + .Height - sMax) / 2
'Outside radius
rMax = WorksheetFunction.Min(poleX - .Left, poleY - .Top)
End With

ActiveSheet.DrawingObjects.Delete
n = nCircles * nSpokes
For i = nSpokes / 4 To n
z = 2 * WorksheetFunction.pi * i / nSpokes
x = poleX + rMax * Cos(z) * i / n
y = poleY + rMax * Sin(z) * i / n
s = sMin + i * (sMax - sMin) / n
ActiveSheet.Shapes.AddShape msoShape5pointStar, x, y, s, s
Next i

End Sub


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(jason) wrote:

I've seen some code in word for creating a spiral of stars on a
document.
I'm trying to adapt this to Excel.So far I have this:-

Const pi = 3.1416
Dim t As Single
Dim i As Integer
Dim z As Single
Dim x As Single, y As Single
Dim n As Single 'number of stars per cycle
Dim k As Single 'length of spiral
Dim sSize As Single 'star size
Dim sh As Shape

Sub DrawSpiral()

n = 80
k = 80000
sSize = 6

For i = 5 To n
t = k * pi * i / n
x = 2 * (1 / t) * Sin(t) * 100000000
y = 2 * (1 / t) * Cos(t) * 1000000

Set sh = ActiveSheet.Shapes.AddShape(msoShape5pointStar, x, y,
sSize, sSize)
Next i

End Sub

Unfortunately it just creates a shower of stars.Not altogether
unattractive!but not what I'm after.One of the problems I think is
that there seems to be an extra argument for the addshape method in
word - a fifth argument which specifies a starting point.

Are there any mathematicians out there who can help??

J