Screen documentation
Introductions
NEET Computers offer self-contained screen objects to aid in and facilitate computer graphics, With all computers starting with a base object at "screen" or "_G.screen". This master screen object is special only in that it provides a draw function to update the visible graphics of a computer from itself, colored screen peripherals also use these objects and have a comparable function.
Screen objects can create other screen objects, not sharing any special functionality of their parent, and these objects will support every useful graphical operation. If you desire to take advantage of a screen objects speed optimizations, it's wise to avoid alpha values other than 255, and to use write/read data functions to draw objects instead of manually using drawPixel or drawLine.
Lookup table
| getSize() | Gets the size of the screen |
| createLayer(sizeX, sizeY) | Creates a blank screen object without rendering capabilities |
| clone(x1, y1, x2, y2) | Clones the given sector of the screen onto a new screen object without rendering capabilities |
| substitute(srcR, srcG, srcB, destR, destG, destB) | Swaps the color src with the color dest, doesn't support alpha values |
| writeData(x, y, buffer, width) | Writes binary data to the screen (examples below) |
| readData(x1, y1, x2, y2) | Reads the given sector as a block of writeData compatible binary data |
| writePixel(x, y, R, G, B, A = 255) | Sets the pixel to the given color |
| readPixel(x, y) | Reads the color of one pixel |
| writeLine(x1, y1, x2, y2, R, G, B, A = 255) | Draws a line between and including two points |
| fill(x1, y1, x2, y2, R, G, B, A = 255) | Sets the given sector of the screen to one color |
| set(R, G, B, A = 255) | Sets the entirety of the screen to one color |
| set() | Sets the entirety of the screen to black |
| draw() | Updates the screen if its rendering compatible |
Functions in detail
getSize()
Gets the size of the screen object.
Parameters: None Returns: int, intcreateLayer(sizeX, sizeY)
Creates a black screen object of the given size, the object will not possess a draw function.
Parameters: sizeX[Integer], sizeY[Integer] Returns: Objectclone(x1, y1, x2, y2)
Clones the given region to a new screen object without a draw function, the new objects contents will be identical to the data of the original region.
Parameters: x1[Integer], y1[Integer], x2[Integer], y2[Integer] Returns: Objectsubstitute(srcR, srcG, srcB, destR, destG, destB)
Replaces the color described with the src arguments for the color described with the dest arguments, this operation does not support alpha values, if your trying to replace a color drawn with transparency, you will have to know what RGB color was generated when it was blended with the screen.
Parameters: srcR[Integer], srcG[Integer], srcB[Integer], destR[Integer], destG[Integer], destB[Integer] Returns: NonewriteData(x, y, buffer, width)
Efficiently and quickly write a block of data to the screen. this block will be drawn at xy, and will be drawn to
width, the height of the block is determined by the blocks size compared against its width.
The buffers length must be dividable by width * 4, and it constructed with alternating bytes for R, G, B, and A
with this pattern repeating for each pixel drawn left to right, and the buffer object should be one single string of bytes.
Lua example below
local chunks = {}
for py = 1, height do
for px = 1, width do
-- string.char packs one pixel's R,G,B,A into a 4-byte chunk
chunks[#chunks + 1] = string.char(r, g, b, a)
end
end
local buffer = table.concat(chunks) --merges all chunks together in one pass for optimal speed
screen.writeData(0, 0, buffer, width)
Parameters: x[Integer], y[Integer], buffer[Bytes], width[Integer]
Returns: None
readData(x1, y1, x2, y2)
Reads the full given area as a block of bytes, formatted the same way writeData accepts data. It is indeed possible to pass the output of readData to writeData, or preform other operations of it, it is noteworthy that the alpha values of the output block are always 255 or fully opaque, the output of any transparent operations already blended with the screen.
Parameters: x1[Integer], y1[Integer], x2[Integer], y2[Integer] Returns: ByteswritePixel(x, y, R, G, B, A = 255)
Sets the single pixel at xy to the provided color.
Parameters: x[Integer], y[Integer], R[Integer], G[Integer], B[Integer], A[Integer] Returns: NonereadPixel(x, y)
Reads the RGB color values of the given pixel, not including a alpha value which is assumed 255 or fully opaque.
Lua example below
R, G, B = readPixel(x, y)
Parameters: x[Integer], y[Integer]
Returns: Integer, Integer, Integer
writeLine(x1, y1, x2, y2, R, G, B, A = 255)
Draws a line between and including the two points.
Parameters: x1[Integer], y1[Integer], x2[Integer], y2[Integer], R[Integer], G[Integer], B[Integer], A[Integer] Returns: Nonefill(x1, y1, x2, y2, R, G, B, A = 255)
Fills the area between and including the two points with the color.
Parameters: x1[Integer], y1[Integer], x2[Integer], y2[Integer], R[Integer], G[Integer], B[Integer], A[Integer] Returns: Noneset(R, G, B, A = 255)
Sets the entire screen to the provided color.
Parameters: R[Integer], G[Integer], B[Integer], A[Integer] Returns: Noneset()
Sets the entire screen to the black.
Parameters: None Returns: Nonedraw()
If the screen object has rendering capabilities, this function updates the renderer, and is required to display changes to the screen object.
Parameters: None Returns: None