extra low framerates in Processing

Nikolaus Gradwohl2009-01-29T04:45:00+01:00

when you want to write a processing sketch, that doesn't redraw several times a second, but updates the main method only once in a while (for example once per hour or minute) the following code can be used to start a thread that triggers a redraw after a delay. Just make sure the setup method calls the noLoop() methode and than start the thread calling start( millisecondsToWait );

void setup() {
  size(300,300);
  smooth();
  noLoop(); // <- turn off the processing loop

  start( 20 * 1000 ); // <- start the thread
}

void draw() {
  background( 255 );
  // draw some random circles
  for ( int i =0; i< 10; i++) {
    color c = color(random( 255 ));
    fill( c );
    stroke( c );
    int radius = int(random( 100 )+ 40);
    ellipse( random( width ), random( height ), radius, radius );     
  }  
}

void start( final int mil ) { //<- mil has to be final to be accessible in run() 
   new Thread() { 
   public void run() {
     while( true ) {     
        delay( mil );
        redraw(); 
      }
   }
 }.start();
}
Tweet This! submit to reddit Digg!   Tags: | no comments | no trackbacks

See also:

Processing and Blender Sound Visualizer for Magical Dreams
flowershape
cuircuitboard noise pattern
particles in the wind
curl noise field

Trackbacks

Comments

Leave a response

Leave a comment