The screen

The screen is a “special” device that is automatically defined for every program you write – you never have to do anything special to get access to the screen.The screen is always defined in a variable called “screen” (which we hoped was pretty obvious).

Margins

In some experiments – especially those with animals – it may be convenient to define a margin around the outside of the screen.  For example, if you have birds sitting on a perch they might not be able to reach the top of the screen.  In these cases it is trivial to define a top margin so that the program will not use that part of the screen.

The screen has four different margin properties:

MarginTop

The margin at the top of the screen; either a percent or an absolute value.

MarginBottom

The margin at the bottom of the screen; either a percent or an absolute value.

MarginLeft

The margin at the left of the screen; either a percent or an absolute value.

MarginRight

The margin at the right of the screen; either a percent or an absolute value.


It is possible to define your margins so large that there is no space left over for the screen itself!  In this case you will get warning messages from the various moveShape* functions when trying to position a shape within the screen.


However, shapes can appear outside the margins – either by giving them negative coordinates or by placing them beside the edge because the margins do not clip shapes, images or text.

Coordinate system

When programming graphics (with Experimentor or any language) the screen is always assigned a coordinate system, which defines where the origin (0,0) is located.  In Experimentor the origin is the bottom left of the screen inside the defined margins.  The x-axis increases to the right and the y-axis increases up and the z-axis increases out of the screen toward the viewer (so objects with a higher z value appear to be above objects with a lower z value).  This mimics the standard Euclidean plane that you learned about in your high-school algebra course.

Notice in the diagrams below that the margins really do have a large impact on the coordinate system.  With non-zero bottom and left margins the origin can be moved far away from the bottom left of the physical screen.  Similarly, with non-zero top and right margins the (100%,100%) location can be moved away from the top right of the physical screen.

Normal “absolute” coordinates

“Relative” / percent coordinates

Percent values

Positioning shapes with percent values

As mentioned above, shapes, text and images may be positioned using percent values rather than absolute coordinates.  This makes your program more robust when running it on different computers with different screen resolutions, and also provides an easy way to position shapes at the left, right top, bottom or middle of the screen.

For example, to position a shape in the exact centre of the screen, simply move it to (50%, 50%) as follows:


moveShape( myShape, 50%, 50% )


Alternatively, you could set the x and/or y location – either in the shape definition or just wherever in your code (although the above is slightly more efficient):


myShape.X = 50%

myShape.Y = 50%


Here is an example of defining a circle positioned in the centre of the screen – regardless of the screen resolution:

// Define a circle in the centre of the screen

define type of circle CircleType

       X = 50%

       Y = 50%

       radius = 50

       IsVisible = true

       Colour = #0000FF

end circle

Sizing shapes with percent values

You can size shapes using percent values as well.  For example, here is a rectangle definition whose width and height are both defined as percents.


define type of rectangle TestRectangle

       colour = #55AA2B

       width = 10%

       height = 20%

       x = 50%

       y = 50%

       isVisible = false

end rectangle


When the width is specified as a percent, it is a percent of the width of the screen (inside the margins), while the height is a percent of the screen’s height (again, inside the margins).  When a circle’s radius is defined as a percent, it is a percent of the screen’s height (which is usually smaller than the screen’s width).