Scratch determines where to display sprites through a coordinate system, or a mathematical grid of infinite values. It uses the Cartesian coordinate system in which on a two-dimensional plane, a point has two values to locate or reference its exact position.
Scratch's coordinate system uses 2 coordinates, "X position" and "Y position", to determine the location of a sprite on the stage. The "X position" value determines the horizontal location of the sprite and the "Y position" value determines the vertical location or height. The screen is a 480x360 rectangle, such that: the X position can range from 240 to -240, where 240 is the rightmost a sprite can be and -240 is the leftmost, and the Y position can range from 180 to -180, where 180 is the highest it can be and -180 is the lowest it can be.
Coordinates are, by convention, written as a pair (X, Y): for example, the center of the screen is (0, 0).
|Note:||In this system, (0, 0) is considered the center of the screen; unlike many popular coordinate systems such as Quartz 2D and the HTML5 canvas API, which use (0, 0) as the top-left or bottom-left corner. This point (0, 0) is called the Origin.|
This is also called a Cartesian coordinate system, and is an essential part of elementary algebra. (Specifically, most equations and expressions in algebra can be graphed on the Cartesian plane so to produce various shapes. For example, a line defined as x = y will produce a diagonal line.)
The X position and Y position of a sprite can be determined, set, and changed by the following blocks:
set x to ()
set y to ()
go to x: () y: ()
glide () secs to x: () y ()
move () steps
change x by ()
change y by ()
[ v] of ( v)::sensing reporter
- Main article: Direction (value)
Direction is determined by a rotational number system. The direction 0 is straight up. Every 90 units are equivalent to a quarter turn, where +90 is 90 degrees clockwise and -90 is 90 degrees counter-clockwise. The diagram below shows how this works.
The direction never exceeds 180 or goes below -180; it is always (internally) kept within these limits with the function:
set [bounded direction v] to (((old direction) mod (360)) - (180))
However, it is usually more helpful to set the direction from 0° to 360°, purely for convenience.
Any direction is equal to 360° + the direction: 90° = 90°+360° = 450°.
These are similar to polar coordinates, except rotated 90° counter-clockwise. A polar coordinate consists of an angle and the distance away from the origin.