2D Drawing
2D drawing methods allow you to draw shapes, lines, and individual pixels directly onto a display framebuffer.
Methods
Section titled “Methods”Fills the entire display with a single color.
Requires: DisplayID, r : number, g : number, b : number
Example
Section titled “Example”gpu.clear(displayId, 0, 0, 0)drawCircle
Section titled “drawCircle”Draws a circle at the specified position.
Set filled to true to draw a solid circle.
Requires: DisplayID, cx : number, cy : number, radius : number, r : number, g : number, b : number, filled : boolean
Example
Section titled “Example”gpu.drawCircle(displayId, 100, 80, 30, 255, 0, 0, true)drawEllipse
Section titled “drawEllipse”Draws an ellipse with the specified radii.
Set filled to true to draw a solid ellipse.
Requires: DisplayID, cx : number, cy : number, rx : number, ry : number, r : number, g : number, b : number, filled : boolean
Example
Section titled “Example”gpu.drawEllipse(displayId, 100, 80, 40, 20, 255, 255, 0, false)drawLine
Section titled “drawLine”Draws a line between two points.
Requires: DisplayID, x1 : number, y1 : number, x2 : number, y2 : number, r : number, g : number, b : number
Example
Section titled “Example”gpu.drawLine(displayId, 0, 0, 100, 100, 255, 255, 255)drawPolygon
Section titled “drawPolygon”Draws a polygon using a list of points.
The pointsObj table should contain points in the following format:
{ {x1, y1}, {x2, y2}, {x3, y3}}Requires: DisplayID, pointsObj : table, r : number, g : number, b : number
Example
Section titled “Example”gpu.drawPolygon(displayId, { {20, 20}, {80, 20}, {50, 70}}, 0, 255, 0)drawPolylines
Section titled “drawPolylines”Draws connected line segments through a list of points.
The pointsObj table requires at least two points.
Requires: DisplayID, pointsObj : table, r : number, g : number, b : number
Example
Section titled “Example”gpu.drawPolylines(displayId, { {10, 10}, {20, 30}, {50, 40}, {90, 10}}, 255, 255, 255)fillEllipse
Section titled “fillEllipse”Draws a filled ellipse.
Requires: DisplayID, cx : number, cy : number, rx : number, ry : number, r : number, g : number, b : number
Example
Section titled “Example”gpu.fillEllipse(displayId, 100, 80, 40, 20, 0, 200, 255)fillRect
Section titled “fillRect”Draws a filled rectangle.
Requires: DisplayID, x : number, y : number, w : number, h : number, r : number, g : number, b : number
Example
Section titled “Example”gpu.fillRect(displayId, 10, 10, 60, 30, 255, 0, 0)clipRect
Section titled “clipRect”Restricts subsequent rendering operations to a rectangular region.
Requires: DisplayID, x : number, y : number, w : number, h : number
Example
Section titled “Example”gpu.clipRect(displayId, 10, 10, 60, 30)clearClip
Section titled “clearClip”Removes the active clipping region.
Requires: DisplayID
Example
Section titled “Example”gpu.clearClip(displayId)getPixel
Section titled “getPixel”Reads a pixel from the display and returns its color.
Requires: DisplayID, x : number, y : number
Returns:
{ r, g, b}Example
Section titled “Example”local pixel = gpu.getPixel(displayId, 10, 10)
print(pixel.r, pixel.g, pixel.b)setPixel
Section titled “setPixel”Sets the color of a single pixel.
Requires: DisplayID, x : number, y : number, r : number, g : number, b : number
Example
Section titled “Example”gpu.setPixel(displayId, 10, 10, 255, 255, 255)