// Example ImageJ scripts using the BeanShell interpreter
// from www.beanshell.org. Requires ImageJ v1.17s, which adds the
// IJ.run() method for running ImageJ commands in the current
// thread

// Use "java -cp ij.jar;bsh-1.0.jar bsh.Console" to start BeanShell 
// and try pasting, one at a time, the following commands and methods
// into the BeanShell console. Requires JDK 1.2 or JDK 1.3 and
// both bsh-1.0.jar and ij.jar must be in the current directory.

new ij.ImageJ(null); // start ImageJ

ij.IJ.run("Blobs (25K)"); // open the "Blobs" sample image

macro1() {
  ij.ImagePlus imp = ij.WindowManager.getCurrentImage();
  if (imp==null) {
    ij.IJ.error("No images are open");
    return;
  }
  for (int i=0; i= width) {
        x = 0;
        y += height/factor;
      }
    } while (y<height);
    imp.updateAndDraw();
    ij.IJ.wait(100);
  }
  ip.reset();
  imp.updateAndDraw();
}
macro2(); // runs macro2