Creating a SPIRAL of stars in Excel

J

jason

Keepitcool

Unfortunately that mail address is full of spam (32 pages the other
day!).Anything futher send to:

biggest (underscore) ears (at) hotmail (dot) com

I'm going to spend a while looking into this lot tonight - I think its
a cool way to learn excel
Just wish I could remember my triginomitery - can't even remember what
sin and cos are !! (will find out though)

Anything else cool please forward
J

keepitcool said:
Jason,

I've tried emailing you with an "improved" version.
bounced :) small wonder!

This may be of interest for the math/theory..
http://www.2dcurves.com/spiral/spirallo.html

Fixed:
plotting of stars: centre rather than topleft.

Added:
accelerator
starting angle
starting radius
direction


Just experiment a little with the settings..


Option Explicit

Sub DrawSpiral()

Const nStars = 100 'Stars to plot
Const nPower = 0.95 'Quadratic accelerator

Const nCircles = 4 'Full Rotation (# circles)
Const nCircle0 = 0.25 'Starting Rotation (# circles)
Const bClockWise = True 'Direction

Const rInner = 0.25 'InnerRadius/OuterRadius

Const sMin = 5 'Starting size of star
Const sMax = 20 'Ending size of stars

Dim i&, j! 'Counter
Dim x!, y! 'Positions
Dim s!, k! 'Size, Angle
Dim x0!, y0!, r0!, rN! 'Origin, Radii

'' Note:
'' Evenly distributed
'' nStars/nCircels => even
'' nPower => 1
''
'' Npower
'' > 1 will accelerate segment length
'' < 1 will decelerate segment length

With Worksheets.Add(before:=Sheets(1))
.Name = "Spiral" & Format(Time, "hhmmss")
With [a1:g30]
'Origin
x0 = (.Left + .Width) / 2
y0 = (.Top + .Height) / 2
'Radii
rN = WorksheetFunction.Min(x0 - .Left, y0 - .Top) - sMax / 2
r0 = rInner * rN
End With

With .Shapes
For i = 1 To nStars
'Distribution
j = (i - 1) ^ nPower / (nStars - 1) ^ nPower
'Star Size
s = sMin + (sMax - sMin) * j
'Angle
k = 2 * WorksheetFunction.pi * _
(nCircle0 + nCircles * j) * -bClockWise
x = x0 - s / 2 + Cos(k) * ((rN - r0 - s / 2) * j + r0 + s / 2)
y = y0 - s / 2 + Sin(k) * ((rN - r0 - s / 2) * j + r0 + s / 2)

.AddShape msoShape5pointStar, x, y, s, s
Next
End With

With .DrawingObjects.Group
.Name = "Spiral"
.ShapeRange.Fill.ForeColor.RGB = vbRed
.ShapeRange.Line.Visible = msoFalse
End With
End With
End Sub




keepITcool

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


keepitcool said:
i said "mathemagician" :)

i'm fairly good with numbers, but alas no formal training.
the thing is.. in this code the angle increment is linear
which with a low number of stars looks awful.

Whereas formally for a spiral the linesegment length should be fixed,
so the stars distribution is not on "spokes"/fixed angles but more
like wound string will the stars at fixed intervals.

I'll need to find a more elaborate algorithm somewhere. Might give it
a whirl later today. :)


keepITcool

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top