Macro to draw a pattern of grid.

Designed for squares or circles.

Examples results:

Note that the title of each image reports the spacing, center to center, of the black spots, the width of each black square, and the number of squares on each side.

Macro here bundled with other macros and here:

/*  Draws a pattern at the center of an image.  Works better with even numbers.
    Finds the upper left corner and then draws the spots from there.
macro "grid pattern" {
  spacing = 36;         // center to center spacing
  diameter = 8;         // width of the square or circle
  numberSpots = 10;     // number of spots in each X and Y
  title = "spacing_" + spacing + " diameter_" + diameter + " numberSpots_" + numberSpots;
  newImage(title, "8-bit white", 512, 512, 1);  // make an image any size you want
  xc = getWidth/2;
  yc = getHeight/2;
  startX = xc  - (numberSpots*spacing/2) - diameter/2 - spacing/2;
  startY = yc  - (numberSpots*spacing/2) - diameter/2 - spacing/2;
  for (ys=1; ys<=numberSpots; ys++) 
    for (xs=1; xs<=numberSpots; xs++) {  
      makeRectangle(startX+xs*spacing-diameter/2, startY+ys*spacing-diameter/2, diameter, diameter);
      run("Set...", "value=0");
  run("Select None");


This should be modified to be a function with arguments spacing, diameter, and number spots. And could get fancier with circles or squares, colors, etc.


last updated 20191003_1000