//   This is a tool macro similar to the spray can tool in NIH Image.
//   Double-click on the tool icon to set the spray width and dot size.

   var sprayWidth = 50;
   var dotSize  = 1;

   macro 'Spray Can Tool-Cb00Fad33F2233Fa133F2a33Fe733F8733' {
         requires("1.30k");
         setLineWidth(dotSize);
         radius=sprayWidth/2; radius2=radius*radius;
         start = getTime();
         autoUpdate(false);
         while (true) {
            getCursorLoc(x, y, z, flags);
            if (flags&16==0) exit();
            x2 = (random()-0.5)*sprayWidth;
            y2 = (random()-0.5)*sprayWidth;
            if (x2*x2+y2*y2<radius2) {
                x += x2;
                y += y2;
                drawLine(x, y, x, y);
                if (getTime()>start+50) {
                    updateDisplay();
                    start = getTime();
                 }
            }
            wait(1);
        }
   }

  // ImageJ runs this macro when user double-clicks on the tool icon
  macro 'Spray Can Tool Options' {
    sprayWidth = getNumber("Spray Width:", sprayWidth);
    dotSize = getNumber("Dot Size:", dotSize);
 }
