-
Notifications
You must be signed in to change notification settings - Fork 0
obsi.graphics
This is a 2D graphics module for drawing things on the screen, manipulating the screen offset and changing the palette.
File formats supported by the graphics module:
- NFP - a standard image format that stores each pixel in a hexadecimal character.
- ORLI - an image format developed for Obsi that uses bitwise Run-Length encoding to compress the NFP image.
- PAL - a csv file with 16 rows (for each color) and 3 columns (for rgb values).
Editors for the file formats:
- NFP - any text editor, but is mostly used by the built-in
paint
program in CraftOS. - ORLI - no editor, only a converter for converting NFP into ORLI.
- PAL - any text editor or ColSW.
Rendering APIs:
-
"pixelbox"
- developed by 9551-Dev, uses some quantization methods with blit characters to enlarge the resolution by 2 pixels on width and 3 pixels on height. -
"hmon"
- uses a normal way to draw the canvas by drawing them with empty characters with custom background. -
"parea"
- similar to"hmon"
, but actually uses some blit characters to make pixels appear like squares instead of 2:3 rectangles.
Functions of obsi.graphics:
function | description |
---|---|
obsi.graphics.draw | Draws an obsi.Image/obsi.Canvas object onto the canvas at certain coordinates and at any scale. |
obsi.graphics.newImage | Creates a new obsi.Image object that can be used for drawing on the canvas. |
obsi.graphics.newBlankImage | Creates a new obsi.Image object with any width, height and color. |
obsi.graphics.newImagesFromTilesheet | Returns an array of obsi.Image objects that represent a tilesheet. |
obsi.graphics.newCanvas | Creates a new obsi.Canvas object. |
obsi.graphics.pixelToTermCoordinates | Converts pixel coordinates from canvas to char coordinates. |
obsi.graphics.termToPixelCoordinates | Converts char coordinates from terminal to pixel coordinates. |
obsi.graphics.setPaletteColor | Sets the palette index to an rgb value. |
obsi.graphics.offsetOrigin | Offsets the origin from the point it is. |
obsi.graphics.setOrigin | Sets the origin to a position specified. |
obsi.graphics.resetOrigin | Sets the origin to (1, 1). |
obsi.graphics.getOrigin | Returns the x and y position of the origin. |
obsi.graphics.getPixelWidth | Returns the width of the canvas. |
obsi.graphics.getPixelHeight | Returns the height of the canvas. |
obsi.graphics.getWidth | Returns width of the terminal. |
obsi.graphics.getHeight | Returns height of the terminal. |
obsi.graphics.getSize | Returns width and height of the terminal. |
obsi.graphics.getPixelSize | Returns width and height of the canvas. |
obsi.graphics.setBackgroundColor | Sets the background color to a color specified (affects text and the canvas). |
obsi.graphics.setForegroundColor | Sets the foreground color to a color specified (used primarly in text). |
obsi.graphics.point | Puts a single pixel onto the canvas |
obsi.graphics.points | Takes an array of tables with the size of two and puts them all onto the canvas. |
obsi.graphics.rectangle | Draws a rectangle (either filled or not) on the canvas. |
obsi.graphics.line | Draws a line that connects two points on the canvas. |
obsi.graphics.write | Writes a text onto the terminal. Beware that it uses terminal coordinates and not pixel coordinates. |
obsi.graphics.newPalette | Creates a new obsi.Palette object. |
obsi.graphics.setPalette | Sets the current palette of the terminal to obsi.Palette. |
obsi.graphics.clearPalette | Clears the entire palette using shell.run("clear", "palette") . |
obsi.graphics.clear | Clears the whole canvas. Is already used internally so you probably don't need it. |
obsi.graphics.setRenderer | Changes the rendering API. |
obsi.graphics.getRenderer | Returns the name of the rendering API in use. |
obsi.graphics.setCanvas | Sets the current canvas to passed obsi.Canvas object. Resets to internal canvas if nil was passed. |
obsi.graphics.getCanvas | Returns the current canvas. May return internal canvas. |
obsi.graphics.flushCanvas | Draws the whole canvas onto the screen. Is used internally. |
obsi.graphics.flushText | Draws all of the queued text onto the terminal. Is already used internally after obsi.graphics.flushCanvas. |
obsi.graphics.flushAll | Just calls obsi.graphics.flushCanvas and obsi.graphics.flushText. |
obsi.graphics.show | Flickers the window onto the screen to update it. |
Draws an obsi.Image object onto the canvas at certain coordinates and at any scale.
Declared as:
obsi.graphics.draw(image: obsi.Image, x: number, y: number, sx?: number, sy?: number)
Creates a new obsi.Image object that can be used for drawing on the canvas.
Takes an imagePath
argument to .nfp
or .orli
image file.
Declared as:
obsi.graphics.newImage(imagePath: string) -> obsi.Image
Creates a new obsi.Image object with any width, height and color.
Declared as:
obsi.graphics.newBlankImage(width: number, height: number, filler?: string|integer) -> obsi.Image
Returns an array of obsi.Image objects that represent a tilesheet.
Declared as:
obsi.graphics.newImagesFromTilesheet(imagePath: string, tileWidth: number, tileHeight: number) -> obsi.Image
Creates a new obsi.Canvas object with any width and height. Default size is set to be the internal canvas' dimensions.
Declared as:
obsi.graphics.newCanvas(width?: number, height?: number) -> obsi.Canvas
Converts pixel coordinates from canvas to char coordinates.
Declared as:
obsi.graphics.pixelToTermCoordinates(x:number, y:number) -> number, number
Converts char coordinates from terminal to pixel coordinates.
Declared as:
obsi.graphics.termToPixelCoordinates(x:number, y:number) -> number, number
Sets the palette index to an rgb value.
Uses a color from the global colors
module, or a hex character.
Declared as:
obsi.graphics.setPaletteColor(color: string|integer, r: number, g: number, b: number)
Usage:
obsi.graphics.setPaletteColor(colors.green, 0, 1, 0)
-- is the same as
obsi.graphics.setPaletteColor("d", 0, 1, 0)
Offsets the origin from the point it is.
Declared as:
obsi.graphics.offsetOrigin(x: number, y: number)
Sets the origin to a position specified.
Declared as:
obsi.graphics.setOrigin(x: number, y: number)
Sets the origin to (1, 1).
Declared as:
obsi.graphics.resetOrigin()
Returns the x and y position of the origin.
Declared as:
obsi.graphics.getOrigin() -> number, number
Returns the width of the canvas.
Declared as:
obsi.graphics.getPixelWidth() -> number
Returns the height of the canvas.
Declared as:
obsi.graphics.getPixelHeight() -> number
Returns width of the terminal.
Declared as:
obsi.graphics.getWidth() -> number
Returns height of the terminal.
Declared as:
obsi.graphics.getHeight() -> number
Returns width and height of the terminal.
Declared as:
obsi.graphics.getSize() -> number, number
Returns width and height of the canvas.
Declared as:
obsi.graphics.getPixelSize() -> number, number
Sets the background color to a color specified (affects text and the canvas).
Declared as:
obsi.graphics.setBackgroundColor(color: string|integer)
Sets the foreground color to a color specified (used primarly in text).
Declared as:
obsi.graphics.setForegroundColor(color: string|integer)
Puts a single pixel onto the canvas
Declared as:
obsi.graphics.point(x: number, y: number)
Takes an array of tables with the size of two and puts them all onto the canvas.
Declared as:
obsi.graphics.points({{x, y}, {x, y}, {x, y}, ...})
Usage:
obsi.graphics.points({{5, 5}, {10, 5}, {10, 10}, {5, 10}}) -- puts 4 points like corners of a square
Draws a rectangle (either filled or not) on the canvas.
Declared as:
obsi.graphics.rectangle(mode: "fill"|"line", x: number, y: number, width: number, height: number)
Draws a line that connects two points on the canvas.
Declared as:
obsi.graphics.line({x, y}, {x, y})
Writes a text onto the terminal. Beware that it uses terminal coordinates and not pixel coordinates.
Declared as:
obsi.graphics.write(text: string, x: integer, y: integer, fgColor?: string|integer, bgColor?: string|integer)
Creates a new obsi.Palette object.
Declared as:
obsi.graphics.newPalette(palettePath: string) -> obsi.Palette
Sets the current palette of the terminal to obsi.Palette.
Declared as:
obsi.graphics.setPalette(palette: obsi.Palette)
Clears the entire palette using shell.run("clear", "palette")
.
Declared as:
obsi.graphics.clearPalette()
Clears the whole canvas. Is already used internally so you probably don't need it.
Declared as:
obsi.graphics.clear()
Changes the rendering API.
Declared as:
obsi.graphics.setRenderer(rend: "hmon"|"parea"|"pixelbox")
Returns the name of the rendering API in use.
Declared as:
obsi.graphics.getRenderer() -> "hmon"|"parea"|"pixelbox"
Sets the current canvas to passed obsi.Canvas object. Resets to internal canvas if nil was passed.
Declared as:
obsi.graphics.setCanvas(canvas?: obsi.Canvas)
Returns the current canvas. May return internal canvas.
Declared as:
obsi.graphics.getCanvas() -> obsi.Canvas
Draws the whole canvas onto the screen. Is used internally.
Declared as:
obsi.graphics.flushCanvas()
Draws all of the queued text onto the terminal. Is already used internally after obsi.graphics.flushCanvas.
Declared as:
obsi.graphics.flushText()
Just calls obsi.graphics.flushCanvas and obsi.graphics.flushText.
Declared as:
obsi.graphics.flushAll()
Flickers the window onto the screen to update it. Supposed to be called internally so please don't use it.
Declared as:
obsi.graphics.show()