Terrapin Resources

The Graphics canvas

The Graphics canvas is the drawing surface for the turtles. It is 2000 by 2000 pixels wide, but Logo only displays a small portion of it through its Graphics panel. The Graphics panel is the viewport, whose size varies depending on the size of the browser canvas or the position of the slider that separates the Graphics panel from the Listener panel. The SETBOUNDS command can be used to set the size of the viewport to a fixed value.

BOUNDS

Reports the drawing bounds of the Graphics canvas.

Syntax

Description

BOUNDS reports the drawing bounds of the Graphics canvas as a two-element list, which is the maximum value of the X and Y directions that a turtle can move. The bounds is the number of pixels a turtle can travel in either direction before it wraps in WRAP or BOUNCE modes, or stops in FENCE mode. A value of 200, for example, limits the turtle movements to the coordinates -200 and 200 in either direction. When Logo starts up, the bounds are set to follow the size of the viewport.

See also SETBOUNDS, WRAP, BOUNCE, and FENCE.

Example

BOUNDS Result: [680 450]

BOUNCE

Lets the turtles bounce off the graphics bounds inside the Graphics canvas.

Syntax

Description

BOUNCE maintains the turtle inside the drawing bounds of the Graphics canvas (see SETBOUNDS) no matter how large a movement command is given. Any time the turtle moves off the bounds, it bounces off the bound. When Logo starts up, the default canvas state is WRAP. See also WRAP, FENCE and WINDOW.

Note that you can set each turtle’s wrap mode individually by setting its WRAPMODE property to something else than DEFAULT.

Example

HOME SETBOUNDS 100 SETH 20 BOUNCE FD 500

BUTTON?

Also: BUTTONP

Reports the state of the left mouse button.

Syntax

Description

BUTTON? reports the state of the left mouse button. BUTTON? reports TRUE when the left button is depressed or FALSE when the button is not depressed.

See also MOUSE.

Example

TO CHASE SETPOS MOUSE IF BUTTON? [STOP] CHASE END CHASE

CLEAN

Erases the graphics canvas.

Syntax

Description

CLEAN erases the current Graphics canvas but does not affect the heading or position of the turtle. See also CLEARSCREEN and DRAW.

Example

HOME SETPC “RED SETH 20 FD 50 CLEAN FD 50

CLEARSCREEN

Also: CS

Erases the graphics panel and homes the turtle.

Syntax

Description

CLEARSCREEN erases the current Graphics canvas, returns the turtle to the center of the canvas, and sets the turtle’s heading to 0. CLEARSCREEN does not affect the pen state or canvas colors. See also CLEAN and DRAW.

Example

HOME SETPC “RED SETH 20 FD 50 CLEARSCREEN FD 50

DRAW

Clears the current graphics canvas and resets all attached turtles.

Syntax

Description

DRAW prepares the current Graphics canvas for drawing by doing the following:

  • Clears the canvas.
  • Resets the canvas bounds to follow the viewport.
  • Erases all images and controls.
  • Resets all turtles to their default values.
  • Sets turtle 0 to be the active turtle.
  • Homes the turtle.
  • Shows the turtle.
  • Puts the pen down.
  • Sets the canvas to WRAP mode.

See also CLEARSCREEN and CLEAN.

Example

TELL 0 HOME RT 22 FD 10000 DRAW

FENCE

Fences all turtles inside the drawing bounds.

Syntax

Description

FENCE prevents the turtle from moving beyond the edge of the Graphics drawing bounds (see SETBOUNDS). If you try to move the turtle outside the bounds, it moves to the drawing bound and stops. See also WRAP, BOUNCE, and WINDOW.

Note that you can set each turtle’s wrap mode individually by setting its WRAPMODE property to something else than DEFAULT.

Example

HOME SETH 20 FENCE FD 1000

FREEZEPIC

Freezes the display of the current graphics.

Syntax

Description

FREEZEPIC freezes the display of the current drawing. All drawings made after FREEZEPIC will not alter the drawing on screen, but will be executed in memory.

FREEZEPIC is useful if you want to create a drawing without the user noticing. Use FREEZEPIC to stop the display, then draw your picture, and finally use UNFREEZEPIC to make the drawing appear immediately.

A good example is the creation of a shape. Use FREEZEPIC on an empty screen to start drawing; then, create the shape and attach it to the turtle with a combination of the SNAP and SETSHAPE commands.

See also UNFREEZEPIC.

Example

Create a golden block and use that block as the turtle shape.

DRAW FREEZEPIC SETPC “GOLD (STAMPRECT 20 20 TRUE) SETSHAPE (SNAP 20 20 “DRAWING) CLEAN UNFREEZEPIC

GRID

Sets the characteristics of the graphics grid.

Syntax

Description

GRID sets the horizontal and vertical characteristics of the Graphics panel grid to its inputs. The first input is either a number, or, if different values are desired for the horizontal and vertical size, a two-element list with the horizontal and vertical grid size. The input values are between 20 and 1000.

The second input is optional. If the input is FALSE, the grid does not display any coordinate values. If it is a number, the grid displays multiples of the given value as horizontal and vertical coordinates. If it is a two-element list, the list contains numbers for the horizontal and vertical coordinates.

See also GRIDON and GRIDOFF.

Example

GRIDON WAIT 1000 ; show a grid with a size of 80 and values as multiples of 10 horizontal and 5 vertical (GRID 80 [10 5]) WAIT 1000 ; show a grid with 100 horizontal and 50 vertical units, no coordinates (GRID [100 50] FALSE)

GRIDOFF

Hides the grid of the Graphics panel.

Syntax

Description

GRIDOFF makes a visible grid in the Graphics panel invisible.

See also GRIDON and GRID.

Example

GRIDON WAIT 1000 GRIDOFF

GRIDON

Displays the grid of the Graphics panel.

Syntax

Description

GRIDON makes a grid visible in the Graphics panel. By default, the size of the grid is 100 pixels on each axis.

The size of the grid may be changed by supplying GRIDON with a list containing the desired horizontal and vertical scales for the grid and putting GRIDON and its argument in parentheses. The permitted value range is between 20 and 1000. Use the GRID command for more display options.

See also GRIDOFF.

Example

(GRIDON [150 50]) WAIT 1000 GRIDON

LOADPIC

Loads a picture.

Syntax

Description

LOADPIC loads the file from the cloud to the current graphics canvas. The file is loaded as a bit map that fills the current viewport. If no extension is given to the filename, the picture format that is loaded is the format specified in the built-in variable :PICTURE.FORMAT. If the file has a different extension, then the extension must be specified in the LOADPIC command.

If the second input to LOADPIC is TRUE, LOADPIC loads multiple copies of the image instead and fills the entire graphics screen with these copies (it tiles the images).

If you use a list of file extensions as the file name, or use the command without inputs, Logo displays a Select File dialog with the list of files limited to the ones matching the list of extensions. Logo also supports old-style Terrapin Logo typelists, but their use is not recommended. See SELECT.FILE for more information.

If loaded as a background image, the loaded picture is behind any background color; if the background color is non-transparent, is hides the background image. For example, if you use the command SETBG "GOLD, the background turns into gold, and any background image is hidden. If you set a background pattern, the pattern hides the background image only partially, allowing the background image to “shine through”. This is especially true if you use a color with a lower alpha value, making the color transparent. If you, for example, use the command SETBG [0 255 0 0.2], the background color changes to a transparent green, making the background image appear greenish.

The optional third input is either “BACKGROUND to load the image as a background image (which is the default), or “DRAWING to load the image as a drawing.

The combination of background images, background patterns and partially transparent background colors allows for a lot of interesting and fun color effects.

MOUSE

Reports the position of the mouse cursor.

Syntax

Description

MOUSE reports the coordinates of the position of the mouse pointer as a list of two numbers representing the x coordinate and the y coordinate. The coordinates are relative to the center of the Graphics canvas. See also BUTTON?.

Example

TO CHASE SETPOS MOUSE IF BUTTON? [STOP] CHASE END CHASE

MOUSESHAPE

Reports the shape of the mouse cursor.

Syntax

Description

MOUSESHAPE reports the number of the current mouse pointer shape as defined with the SETMOUSESHAPE command. On startup, the mouse shape is 1.

Example

MOUSESHAPE

REDO

Redoes the last drawing command after an UNDO command.

Syntax

Description

REDO redoes the last graphics drawing operation after an UNDO command has undone the last graphics drawing operation. Multiple REDO commands redo subsequent undone graphics drawing operations until the original graphics has been restored, and there is nothing left to redo.

REDO is the same as clicking the green Redo button in the icon bar.

Example

REDO

SAVEPIC

Saves the contents of the Graphics panel.

Syntax

Description

SAVEPIC saves the contents of the Graphics panel into a bitmap file in a data space. SAVEPIC uses the boundaries of the Graphics panel. SAVEPIC saves its files in PNG or JPG format depending on the setting of the PREFS property PICTURE.FORMAT.

If you use a list of file extensions as the file name, or use the command without inputs, Logo displays a Select File dialog with the list of files limited to the ones matching the list of extensions. Logo also supports old-style Terrapin Logo typelists, but their use is not recommended. See SELECT.FILE for more information.

The optional second input is either “BACKGROUND to save the background only, “DRAWING to save the drawing only, or “BOTH to save both, which is the default.

If the PREFS property PRINT.BITMAPS is TRUE, SAVEPIC also saves all turtles, bitmaps and controls as well.

Example

SAVEPIC “Sample

SETBOUNDS

Set the drawing bounds of the current Graphics canvas.

Syntax

Description

SETBOUNDS sets the drawing bounds of the current Graphics canvas. The bounds is the number of pixels a turtle can travel in either direction before it wraps in WRAP mode, bounces in BOUNCE mode, or stops in FENCE mode. A value of 200, for example, limits the turtle movements to the coordinates -200 and 200 in either direction. When Logo starts up, the bounds follow the size of the viewport.

If SETBOUNDS is called with a two-element list, the list is used to set separate values in X and Y directions. If SETBOUNDS is called without inputs, the bounds are reset to follow the viewport.

See also BOUNDS, WRAP, BOUNCE, and FENCE.

Example

MAKE “X BOUNDS SETBOUNDS 100 (SETBOUNDS) SETBOUNDS :X

SETMOUSESHAPE

Sets the shape of the mouse cursor.

Syntax

Description

SETMOUSESHAPE changes the shape of the mouse cursor when it is within the Graphics canvas. Its input is a number representing one of 17 available mouse shapes. When Logo starts, the mouse shape is 1. If SETMOUSESHAPE is enclosed in parentheses without inputs, shape 1 is used.

MOUSESHAPE reports the number of the current mouse shape.

Example

SETMOUSESHAPE 2

UNDO

Undoes the last drawing command.

Syntax

Description

UNDO undoes the last graphics drawing operation. Multiple uses of the UNDO command undo the next last operation until there is nothing left to undo. UNDO is the same as clicking the red Undo button in the icon bar.

Use the REDO command to redo an Undo command.

Example

UNDO

UNFREEZEPIC

Unfreezes the display of the current graphics.

Syntax

Description

UNFREEZEPIC undoes the FREEZEPIC command. It updates the display with the drawing made while the graphics display is frozen, and resumes normal drawing mode, where all drawings immediately appear on the display.

See also FREEZEPIC.

Example

Create a golden block and use that block as the turtle shape.

DRAW FREEZEPIC SETPC “GOLD (STAMPRECT 20 20 TRUE) SETSHAPE (SNAP 20 20 “DRAWING) CLEAN UNFREEZEPIC

WINDOW

Removes the boundary for turtle movements.

Syntax

Description

WINDOW removes the boundaries from the turtle’s field of movement. If the turtle moves beyond the bounds of the Graphics drawing bounds, it continues to move, but cannot be seen if it leaves the visible portion of the Graphics panel. The Graphics canvas becomes a small canvas overlooking the plane on which the turtle can travel.

See also BOUNCE, FENCE and WRAP.

Note that you can set each turtle’s wrap mode individually by setting its WRAPMODE property to something else than DEFAULT.

Example

HOME SETH 20 WINDOW FD 1500

WRAP

Lets the turtles wrap inside the canvas.

Syntax

Description

WRAP maintains the turtle inside the Graphics drawing bounds (see SETBOUNDS) no matter how large a movement command is given. Any time the turtle moves off the canvas bound, it wraps around the canvas and reappears on the opposite edge. When Logo starts up, the default canvas state is WRAP.

See also BOUNCE, FENCE and WINDOW.

Note that you can set each turtle’s wrap mode individually by setting its WRAPMODE property to something else than DEFAULT.

Example

HOME SETH 20 WRAP FD 1500