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

Monsters

Posted by Zacharias Enochsson on Mar 21, 2008



For Tom De Smedt: approximately a year ago (thats eons ago in internet-time) you stumbled across my then website, which I at the time had pretty much abandoned (looks like I might start keeping it up again -we'll see).

Anyway, you left a comment on a post of some nodebox code asking to use it in the gallery. I'm sorry I never even noticed (again, I was faltering in keeping my site up at the time). I just wanted to let you know this way that you are more than welcome to use it anyway you like. For the interest of others, here's the code

from math import sin,cos,sqrt,pi
var("POSX",NUMBER,0,-200,200)
var("POSY",NUMBER,0,-200,200)
var("ROTATION",NUMBER,0,0,360)
var("FILL",BOOLEAN,False)
var("SIZE",NUMBER,200,10,1000)
var("TURNLEFT",NUMBER,60,0,180)
var("TURNRIGHT",NUMBER,60,0,180)
var("RECURSION",NUMBER,5,1,8)
N=int(RECURSION)
if not FILL: nofill()
x,y,a = SIZE+POSX,SIZE+POSY,ROTATION*pi/180
dx,dy,dal,dar = SIZE/float(2**N), 0, (TURNLEFT)*pi/180, (TURNRIGHT)*pi/180
l = dx
L,R,A,B = -1, -2, -3, -4 
S=[A,N]
stroke(0,0,0,1)
autoclosepath(False)
beginpath(x,y)
while len(S)>0:
    N = S.pop()
    if N>0:
        M=N-1
        F=S.pop()
        if F==A: S+=[B,M,L,A,M,L,B,M]
        else: S+=[A,M,R,B,M,R,A,M]
        continue
    if N==L:
        a -= dal
        dx = l*cos(a)
        dy = l*sin(a)
        continue
    if N==R:
        a += dar
        dx = l*cos(a)
        dy = l*sin(a)
        continue
    S.pop()
    x += dx
    y += dy
    lineto(x,y)
endpath()
And what it does is this: It basically draws a sierpinsky triangle using a L-system. But you can chage the left-turn angle and right-turn angle as well as vary the recursion depth, which produces a whole bunch of interesting and surprisingly organic shapes.

I'm no good at prettying up these things, so its just plain-ol b&w line drawings. If you wanna pretty it up, go right ahead, and please let me know too.


 
Posted by Tom De Smedt on Mar 21, 2008

Hi Zach, been a while!
Thanks for sharing the script, still produces very nice results.