moveShape2

moveShape2( referenceShape, shapeToMove, minimumDistance, maximumDistance )

Moves the shapeToMove relative to the referenceShape at least minimumDistance away and at most maximumDistance away (chosen at random each time the function is called)

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

Note that just like the moveShape(…) function, using moveShape2 creates the dedicated “moved” event in the Events table within the database.

Arguments

referenceShape

- the reference shape; this shape is not moved.

shapeToMove

- the shape that will be moved relative to the referenceShape

minimumDistance

- the  minimum distance away from the referenceShape to move the shapeToMove.

This value may be either absolute or a percent; if it is a percent then it is a percentage of the larger of the screen’s width and height.

maximumDistance

- the maximum distance away from the referenceShape to move the shapeToMove.

This value may be either absolute or a percent; if it is a percent then it is a percentage of the larger of the screen’s width and height.

This argument is optional, and if not provided will be set to the minimum distance, which allows you to easily control the exact distance from the referenceShape.

keepOnScreen

- determines if the shape should be kept on the screen

This argument is optional, and if not provided defaults to true.

The moveShape2 function tries very hard to ensure that the shapeToMove is positioned on the screen.  However, with a very large maximum distance it is possible that the randomly selected distance may cause the shape to be completely off the screen.  If this value is false the shape will be allowed to be off the screen either partially or completely based on the distance.  If this argument if true then the shape will be moved back so that it is on the screen.  In general this is possible without violating the minimum distance, but not always (usually for very small screens or very large minimum values).

Note that if the minimum distance is larger than the maximum distance then the function switches the minimum and the maximum distances and proceeds as normal.

Returns

The shape that was moved (the shapeToMove argument).

Example

The following moves two shapes around the screen, randomly positioning the black shape and then moving the red shape somewhere on the screen relative to the black shape, so that the red and black shapes never overlap:

// Set up the margin so that it is at least as big as the shapes we’re moving around

screen.MarginTop                = 100

screen.MarginLeft                = 100

screen.MarginRight                = 100

screen.MarginBottom        = 100


// Define our circle

define type of circle CircleType

       radius = 50                // The circle’s diameter is 100

       IsVisible = false        // hide it so it only appears once we’ve positioned it

end circle


// Create our reference circle and set its colour to black

define refCircle = create CircleType

refCircle.Colour = #000000


// Create our circle to move and set its colour to red

define secondCircle = create CircleType

secondCircle.Colour = #FF0000


define counter = 0

while( counter < 1000 )

       // Move the reference circle

       moveShape( refCircle, random(0,100%), random(0,100%) )

       

       // Position the second circle somewhere else

       // To move the shape a constant amount away, simply remove the 100%

       // and the red circle will always be positioned just beside the black reference circle

       moveShape2(refCircle, secondCircle, 200, 100%)

       refCircle.IsVisible = true

       secondCircle.IsVisible = true

       

       wait for 1sec

       counter += 1

end while


print(“Done!”)