User Tools

Site Tools


weblogo:commands:graphics

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 Output panel. The SETBOUNDS command can be used to set the size of the viewport to a fixed value.

Please also check out the Graphics panel's properties. They let you monitor the mouse and touch events.

BOUNDS

Reports the d rawing bounds of the Graphics canvas.

Syntax

BOUNDS

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

BOUNCE

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.

Example

HOME
SETBOUNDS 100
SETH 20
BOUNCE
FD 500

BUTTON? (BUTTONP)

Reports the state of the left mouse button.

Syntax

BUTTON?

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

CLEAN

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 (CS)

Erases the graphics pane and homes the turtle.

Syntax

CLEARSCREEN

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

DRAW

Description

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

  • Removes all events handlers.
  • 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

FENCE

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.

Example

HOME
SETH 20
FENCE
FD 1000

GRID

Sets the characteristics of the graphics grid.

Syntax

GRID size
GRID [x-size x-size]
(GRID size display-units)
(GRID size [x-display-units y-display-units])
(GRID size FALSE)

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 window.

Syntax

GRIDOFF

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 window.

Syntax

GRIDON
(GRIDON size)
(GRIDON [horizontal-size vertical-size])

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 as background picture.

Syntax

LOADPIC filename.ext
(LOADPIC filename.ext TRUE)
LOADPIC [extensions-list]
(LOADPIC [extensions-list] TRUE)
(LOADPIC)

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 last 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.

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 and background image appear greenish.

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

MOUSE

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

MOUSESHAPE

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

SAVEPIC

Saves the contents of the Graphics window.

Syntax

SAVEPIC filename.ext
SAVEPIC [extensions-list]
(SAVEPIC)

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 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.

Note that SAVEPIC does not save any turtles or bitmaps. If you would like to also save all visible turtles or bitmaps, you need to STAMP them first.

Example

SAVEPIC "Sample

SETBOUNDS

Set the drawing bounds of the current Graphics canvas.

Syntax

SETBOUNDS size
SETBOUNDS [x y]
(SETBOUNDS)

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

</product>

SETMOUSESHAPE

Sets the shape of the mouse cursor.

Syntax

SETMOUSESHAPE number
(SETMOUSESHAPE)

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

WINDOW

Removes the boundary for turtle movements.

Syntax

WINDOW

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. The Graphics canvas becomes a small canvas overlooking the plane on which the turtle can travel.

See also BOUNCE, FENCE and WRAP.

Example

HOME
SETH 20
WINDOW
FD 1500

WRAP

Lets the turtles wrap inside the canvas.

Syntax

WRAP

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.

Example

HOME
SETH 20
WRAP
FD 1500
weblogo/commands/graphics.txt · Last modified: 2018/08/27 03:39 (external edit)