(1) Your FC account doesn't work here; (2) All new usernames must be of the form (letters)(space)(letters); (3) Contribute!
NOTE: The style guide dictates that all headings and page titles are in sentence case.

Guide:Programming a spiral

From Fantastic Wiki

Jump to: navigation, search

You can generate spirals by programmatic means.

Contents

[edit] Implementation of dbroughton's algorithm

[edit] ColdFusion

This is the original version by dbroughton.

<cfset dl = 0 /> 
<cfset l = 5 />
<cfset h=10 />
<cfset b = 15 /> 
<cfset n = 6.25 />
<cfset degree = n*360 />
<cfset step = 10 />
<cfloop from="1" to="#degree/step#" index="d">
   <cfset theta = ((d*step)*(pi()/180)) />
   <cfset r = b*(theta) />
   <cfset x = round(r*cos((d*step)*(pi()/180)))/>
   <cfset y = round(r*sin((d*step)*(pi()/180)))/>
   <cfset angle = round(d*step+90) />
   <cfoutput>StaticRect (#x#,#y#), (#(l+dl)#,#h#), <cfif angle gt 360>#evaluate(angle mod 360)#<cfelse>#angle#</cfif></br></cfoutput>
   <cfset dl=dl+1 />
</cfloop>

[edit] Python

You can see it in action here: http://www.sagenb.org/home/pub/362/

import math

dl = 0 # Addition factor for length of bar
l = 25 # Starting length of bar
h = 10 # Height of each bar
b = 15 # Distance between arms
n = 2.25 # Number of turns in the spiral
degree = n*360
step = 10
for d in range(1, degree // step):
   theta = math.radians(d * step)
   r = b * theta
   x = round(r * math.cos(math.radians(d * step)))
   y = round(r * math.sin(math.radians(d * step)))
   angle = round(d * step + 90)
   print "StaticRect (%.4f, %.4f), (%.4f, %.4f), %.4f" % (x, y, (l + dl), h, angle % 360) 

[edit] WebFCML Equations Evaluator

Init:

dl = 0 # Addition factor for length of bar
l = 25 # Starting length of bar
h = 10 # Height of each bar
b = 15 # Distance between arms
n = 2.25 # Number of turns in the spiral
degree = n*360
step = 10
t_0 = 1
t_f = round(degree / step)
delta_t = 1

Iteration:

theta = (t * step) * (pi / 180)
r = b * theta
x = round(r * cos((t * step) * (pi / 180)))
y = round(r * sin((t * step) * (pi / 180)))
a = round(t * step + 90)
w = (l + dl)
h = h
Personal tools
Fantastic Contraption