GPU¶
The GPU library is used to manipulate and draw on the screen.
Usage¶
Lua | |
---|---|
Warning
All coordinates start from 1, 1
Functions¶
getSize¶
gpu.getSize()
Get the size of the screen
Returns¶
width
: integer - Width of screenheight
: integer - Height of screen
setSize¶
gpu.setSize()
Set the size of the screen
Parameters¶
width
: integer - Width of screenheight
: integer - Height of screen
getScale¶
gpu.getScale()
Get the scale of the screen
Returns¶
scale
: number - Scale of screen
setScale¶
gpu.setScale()
Set the scale of the screen
Parameters¶
scale
: Number - Scale of screen
getPixel¶
gpu.getPixel( x, y )
Get the color of pixel at X,Y.
The color returned is black (#000000) if out of bounds.
Parameters¶
x
: number - X coordinate.y
: number - Y coordinate.
Returns¶
color
: integer - Decimal RGB color.
plot¶
gpu.plot( x, y, color )
Draw a pixel on the screen.
Parameters¶
x
: number - X coordinate.y
: number - Y coordinate.color
: integer - Decimal RGB color.
plots¶
gpu.plots( { x1, y1, x2, y2, ..., xn, yn}, color )
Draw multiple pixels on the screen.
Parameters¶
coordinates
: number[] - Table containing pairs of coordinates.color
: integer - Decimal RGB color.
Throws¶
- If the
coordinates
table length is not even. - If the
coordinates
table contains anything but numbers.
drawPoint¶
gpu.drawPoint( x, y, color, size? = 1)
Draw a square point.
Parameters¶
x
: number - X coordinate.y
: number - Y coordinate.color
: integer - Decimal RGB color.size
: number - Size of the pixel. Defaults to 1.
drawCircle¶
gpu.drawCircle( x, y, radius, color, size? = 1 )
Draw a circle.
Parameters¶
x
: number - X coordinate.y
: number - Y coordinate.radius
: numbeer - Radius of the circle.color
: integer - Decimal RGB color.size
: number - Border size.
drawLine¶
gpu.drawLine( startX, startY, endX, endY, color, size? = 1 )
Draw a line.
Parameters¶
startX
: number - Start X coordinate.startY
: number - Start Y coordinate.endX
: number - End X coordinate.endY
: number - End Y coordinate.color
: integer - Decimal RGB color.size
: number - Thickness.
drawRectangle¶
gpu.drawRectangle( x, y, width, height, color, size? = 1 )
Draw a rectangle.
Tip
Setting border size to the smallest of width or height fills the rectangle.
Parameters¶
x
: number - X coordinate.y
: number - Y coordinate.width
: number - Width.height
: number - Height.color
: integer - Decimal RGB color.size
: number - Border size.
drawPolygon¶
gpu.drawPolygon( x, y, { x1, y1, x2, y2, ..., xn, yn}, color, size? = 1 )
Draw a polygon.
Parameters¶
x
: number - X coordinate.y
: number - Y coordinate.points
: number[] - Table containing pairs of coordinates to indicate the points.color
: integer - Decimal RGB color.size
: number - Border size.
Throws¶
- If the
points
table length is not even. - If the
points
table contains anything but numbers.
drawEllipse¶
gpu.drawEllipse( x, y, radiusX, radiusY, color, size? = 1 )
Draw an ellipse.
Parameters¶
x
: number - X coordinate.y
: number - Y coordinate.radiusX
: number - Radius of X coordinate.radiusY
: number - Radius of Y coordinate.color
: integer - Decimal RGB color.size
: number - Border size.
drawString¶
gpu.drawString( x, y, color, text )
Draw a string.
Parameters¶
x
: number - X coordinate.y
: number - Y coordinate.color
: integer - Decimal RGB color.text
: string - Text to draw.
measureString¶
gpu.measureString( text )
Get the bounds of the string.
Parameters¶
text
: string - Text to measure.
Returns¶
width
: number - Width of the text.height
: number - Height of the text.
getBuffer¶
gpu.getBuffer()
Get a unsigned 32-bit integer buffer of all colors in the screen in 0xRRGGBB format.
Returns¶
gpuBuffer
: GPUBuffer - GPU Buffer
setBuffer¶
gpu.setBuffer( gpuBuffer )
Set the screen buffer.
Parameters¶
gpuBuffer
: GPUBuffer - GPU Buffer
newBuffer¶
gpu.newBuffer( [width, height] )
Create a new empty buffer.
The buffer is already sized for the current screen size, unless width and height are defined.
Parameters¶
width
: integer - Width of the buffer.height
: integer - Height of the buffer.
Returns¶
gpuBuffer
: GPUBuffer - Empty GPU Buffer
drawBuffer¶
gpu.drawBuffer( buffer, x, y, width, height )
Draw a buffer to the screen at an arbitrary location.
Parameters¶
buffer
: GPUBuffer - Buffer to drawx
: integer - X coordinate.y
: integer - Y coordinate.width
: integer - Width of the buffer.height
: integer - Height of the buffer.
Created: March 11, 2023