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

animation

Posted by Sam on Oct 27, 2007

I need help creating an animation that will eventually simulate a growth patten. In order to learn the software, I'm starting by randomly placing red dots in the field but cannot get the red dots to accumulate. The code i've started with below places a dot but each new frame erases the previous dot. The result i'm looking for is where over time the whole field will be covered in red dots. Thanks.

size(400,400)
speed(.5)
def setup():
    global frame
    frame =1
    
def draw():
    
    fill(1,1,1)
    rect(0,0,WIDTH,HEIGHT)
    
    for i in range(1):
        
        x = random(WIDTH)
        y = random(HEIGHT)
        
        fill(1,0,0)
        oval(x,y,3,3)


 
Posted by Giorgio O. on Oct 27, 2007

Hello Sam,

here's a piece of code that does what you need.
First it creates an empty list "red_dots", then it append an X,Y value as a tuple to the list at every frame of the animation. Then draws the entire list using the X,Y values as origins of the red dots.
(and it has a limit "maxdots" that set the maximum number of dots that are going to be drawn).

The problem with my code is that it does work ok, but redrawing the entire list gets very slow after few iterations.
Does anybody know a FASTER way to achieve this?
Thanks. Giorgio

size(400,400)
background()
speed(100)
 
red_dots = []
maxdots = 1000
 
def setup():
    pass
    
def draw():  
        fill(1,0,0)
        x = random(WIDTH)
        y = random(HEIGHT)
        if (len(red_dots) <= maxdots):
            append_dot( (x, y) )
        draw_dot()
 
 
def append_dot( (x, y) ):
    red_dots.append( (x, y) )   
        
def draw_dot():
    for i in range( len(red_dots) ):
        #print red_dots[i]
        oval_centered(red_dots[i], 10)
        
def oval_centered( (x, y) ,d):
    r = d/2.0
    oval(x-r,y-r,d,d)



Posted by Sam on Oct 27, 2007

Giorgio,

This is great. It is exactly what I needed. I want to study the code a bit and may have some questions but in the meantime thanks.



Posted by anonymous on Oct 29, 2007

A faster way may be to cache the canvas each frame and draw it the next frame, as well as drawing a dot over it. Like the "Feedback.py" example. I tried this, but without success.



Posted by G. on Oct 30, 2007

I can not find the "Feedback.py" example, can you point me a link? thanks.



Posted by anonymous on Oct 30, 2007

It's in the advanced folder… You need V1.9.x for it to be there. The script should be in your Applications/NodeBox/Examples/Advanced/Feedback.py (replace Applications with wherever you installed NB)



Posted by Sam on Oct 31, 2007

I think what would make this growth animation more realistic is if it grew like a bacteria, growing out from the center. For instance if every new red dot landed within a certain distance from an existing red dot while still being random. Does anyone have recommendations for doing this?



Posted by anonymous on Oct 31, 2007

This has allready been done, but not in NB: www.jwz.org/xscreensaver
See the "Petri" saver.