1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

(Another) Sprial

Posted by Nikolaj B on Apr 10, 2008

I know there are some spiral things out there, but I was curious and whipped this up. Its pretty simple and ready to be hacked (random jitter anyone?)

import math
 
def spiral(a,b,t):
    r=a*math.exp(b*t)
    x= r * math.cos(t)
    y= r * math.sin(t)
    return x,y
    
def spiralpath(x,y,t1=-180,t2=720,a=20,b=0.1):
    path=[]
    for t in range(t1,t2,10):
        ax,ay=spiral(a,b,math.radians(t))
        path.append((x+ax,y+ay))
    return findpath(path)
 
nofill()
autoclosepath(False)
stroke(0.1)
strokewidth(3)
 
beginpath(300,300)
sp=spiralpath(300,300)
drawpath(sp)
endpath()


 
Posted by Nikolaj B on Apr 10, 2008

wooops, and apparently i misspelled spiral in the title. Yaaay!



Posted by Mark M on Apr 14, 2008

Very cool Nikolaj,

For amusement I came up with one in the form of one-liner:

stroke(.2)
nofill()
translate(250, 200)
          
drawpath (findpath([(x.real, x.imag) for x in 
    [((1+.4j)**i)*x for i, x in enumerate([1+1j]*75)]]))
enjoy!



Posted by Dethe Elza on Jul 28, 2008

Here's a spiral animation. It could probably be simplified even further, but I liked the result:

from math import sin, cos, pi
 
size(300,300)
speed(20)
 
ROTATION = pi / 45
CENTER_X = WIDTH / 2
CENTER_Y = HEIGHT / 2
EIGHTH = pi / 8.0
    
def setup():
    global outer_arms, clip_oval, inner_arms, fill_oval
#    outer_arms = [arm(a * (pi / 2.0), 500) for a in range(4)]
    fill_oval = oval(CENTER_X -45, CENTER_Y - 45, 90, 90, draw=False)
    clip_oval = oval(-45, -45, 90, 90, draw=False)
    outer_arms = []
    inner_arms = []
    for dt in range(4):
        theta = (pi / 2.0) * dt;
        for r in range(300):
            outer_arms.append((r * cos(theta - EIGHTH + ROTATION * r), r * sin(theta - EIGHTH + ROTATION * r)))
            inner_arms.append((r * cos(theta - EIGHTH - ROTATION * r), r * sin(theta - EIGHTH - ROTATION * r)))
        for r in reversed(range(300)):
            outer_arms.append((r * cos(theta + EIGHTH + ROTATION * r), r * sin(theta + EIGHTH + ROTATION * r)))
            inner_arms.append((r * cos(theta + EIGHTH - ROTATION * r), r * sin(theta + EIGHTH - ROTATION * r)))
 
def draw():
    reset()
    transform(CORNER)
    translate(CENTER_X, CENTER_Y)
    fill(0,0,0)
    push()
    rotate(FRAME * 3) # degrees
    drawpath(outer_arms)
    pop()
    fill(1,1,1)
    drawpath(clip_oval)
    beginclip(fill_oval)
    rotate(-FRAME * 3)
    fill(0,0,0)
    drawpath(inner_arms)
    endclip()



Posted by anonymous on Jul 29, 2008

I'm falling…

import math
 
def spiral(a,b,t):
    r=a*math.exp(b*t)
    x= r * math.cos(t)
    y= r * math.sin(t)
    return x,y
 
def spiralpath(x,y,t1=-180,t2=720,a=20,b=0.1):
    path=[]
    for t in range(t1,t2,10):
        ax,ay=spiral(a,b,math.radians(t))
        path.append((x+ax,y+ay))
    return findpath(path)
 
def draw():
    nofill()
    autoclosepath(False)
    stroke(0.1)
    strokewidth(3)
    transform(CORNER)
    translate(150, 150)
    rotate((FRAME*3)%360)
    sp=spiralpath(0, 0, -900, 1440)
    drawpath(sp)
 
speed(30)