clip( x, y, w, h )

Sets the clipping region in the draw state.

The x coordinate of the upper left corner of the clipping rectangle.
The y coordinate of the upper left corner of the clipping rectangle.
The width of the clipping rectangle, in pixels.
The height of the clipping rectangle, in pixels.

When the draw state has a clipping rectangle set, all draw operations will not affect any pixels in the graphics buffer outside of this rectangle. This is useful for reserving parts of the screen

When called without arguments, the function resets the clipping region to be the entire screen.

Technical notes Edit

The current clipping rectangle is memory-mapped and may be read or written directly:

  • 0x5f20: rectangle x
  • 0x5f21: rectangle y
  • 0x5f22: rectangle x+w
  • 0x5f23: rectangle y+h

Important: This is not the same format as the arguments to clip(). The second pair of values are the rectangle are absolute, rather than width and height relative to x and y.

Examples Edit

-- set the clipping region to exclude 8 pixels at the top and bottom
clip(0, 8, 128, 112)
-- these circles are clipped to (0-127,8-119)
circfill(10, 10, 8, 8)
circfill(10, 118, 8, 8)
-- reset the clipping region to full screen
-- these circles are not clipped
circfill(40, 10, 8, 7)
circfill(40, 118, 8, 7)
-- get the current clip rectangle from its memory-mapped addresses
clip example

See also Edit