moveShapesOnCheckerboard( referenceShape, width, height, rows, columns, shapes… )

Arranges the shape(s) in a grid that is centered on the referenceShape.

The location of each shape is saved into the database and automatically associated with the current session, trial and phase (if applicable).

This function is quite handy when you need to move more than one shape at a time and want them all arranged in a rectangle.



- the reference shape (this shape is not moved) acts as the centre of the imaginary grid on which the other shapes will be placed.   Note that this shape does not need to be visible to use it as the reference shape.


- The width of the imaginary grid on which you want to place the shapes.
  If you do not specify a width then the function will attempt to calculate the width based on the widest shape provided.


- The height of the imaginary grid on which you want to place the shapes.

If you do not specify a height then the function will attempt to calculate the height based on the tallest shape provided.


- The number of rows (of shapes) in the grid that your shapes will be arranged in.


- The number of columns (of shapes) in the grid that your shapes will be arranged in.


- Any number of shapes to move, or a collection of shapes.  Each shape will be placed on the imaginary grid centred on the reference shape.  The first of these shapes will be positioned at the top-left of the rectangle, and then are placed left-to-right and top-to-bottom.


The following diagram attempts to depict exactly how the moveShapesOnCheckerboard function actually arranges the shapes on  an example grid with three rows and three columns.


The number of shapes that were moved, which is always the number of shapes passed in.


The following displays a simple black and white checker-board pattern centered on a red reference rectangle.

// First, we’ll define how big our squares are,

// and the number of rows and columns that we want

define sizeOfSquare = 100

define rows = 5

define columns = 5

// Define our square “template”

define type of rectangle Square

       width = sizeOfSquare

       height = sizeOfSquare

       colour = #000000

       LineThickness = 1

       LineColour = #000000

       isVisible = true

end rectangle

// Define our collection of shapes for the grid

define squares = create collection

// Create the squares for our checker-board, alternating black and white

define isWhite = true

define counter = 1

define numberOfSquares = rows * columns

while counter <= numberOfSquares

       // Create our new square

       define s = create Square

       // Should our share be white?

       if isWhite then s.colour = #FFFFFF

       // We could also easily make a checker-board from a set of colours like this:

       // s.Colour = random( #FF0000, #00FF00, #0000FF )


       // Add our new square to the collection of squares

       squares += s


       // Toggle our isWhite variable for next time around the loop

       isWhite = not isWhite


       counter = counter + 1

end while

// Define the shape around which the checker-board will be centered

// (and make it invisible because we don’t want it shown)

define center = create square

center.X = 50%

center.Y = 50%

center.colour = #FF0000

center.IsVisible = true

// We will arrange all of our shapes on the checker-board

// Notice that we haven’t specified the width or the height; we’ll let the function figure that out.

moveShapesOnCheckerBoard( referenceShape=center, rows=rows, columns=columns, shapes=squares )

// Now wait so we can admire the checker-board

wait for 30 seconds

Here’s a screen shot of what this looks like in action: