2D Display & Sprites
Reference for 2D hardware graphics primitives, 16-bit RGB565 color packing, BMP direct streaming, typography, and double-buffered mini-sprites in KryonOS.
2D Display & Sprites API
KryonOS uses a direct-to-glass rendering pipeline powered by high-speed SPI DMA hardware transfers. User scripts can draw directly to the physical display glass or to off-screen RAM double-buffers (Sprites) to eliminate visual tearing and flickering.
Driver implementations and pinouts are located in the KryonOS GitHub Repository.
1. Color System (16-bit RGB565)
The display uses the 16-bit RGB565 color format (5 bits red, 6 bits green, 5 bits blue). Colors can be supplied directly as hex literals or computed dynamically.
Standard Color Constants
| Color Constant | Hex Value | RGB Representation |
|---|---|---|
| Black | 0x0000 | (0, 0, 0) |
| White | 0xFFFF | (255, 255, 255) |
| Red | 0xF800 | (255, 0, 0) |
| Green | 0x07E0 | (0, 255, 0) |
| Blue | 0x001F | (0, 0, 255) |
| Cyan | 0x07FF | (0, 255, 255) |
| Magenta | 0xF81F | (255, 0, 255) |
| Yellow | 0xFFE0 | (255, 255, 0) |
System.color(r, g, b)
Packs 24-bit RGB values (0-255 each) into the 16-bit integer expected by the hardware.
- Parameters:
r(Integer, 0 to 255)g(Integer, 0 to 255)b(Integer, 0 to 255)
- Returns:
Integer(16-bit packed color)
2. 2D Drawing Primitives
System.fillScreen(color)
Clears the entire display canvas with a solid color via SPI DMA.
- Parameters:
color(Integer)
System.drawPixel(x, y, color)
Renders a single pixel.
- Parameters:
x(Integer),y(Integer),color(Integer)
System.drawLine(x1, y1, x2, y2, color)
Draws a line between two coordinates using Bresenham's line algorithm.
- Parameters:
x1,y1,x2,y2(Integer),color(Integer)
System.drawRect(x, y, w, h, color) / System.fillRect(x, y, w, h, color)
Renders hollow or filled rectangles.
- Parameters:
x,y,w,h(Integer),color(Integer)
System.drawRoundRect(x, y, w, h, radius, color) / System.fillRoundRect(...)
Renders rectangles with rounded corner radiuses.
- Parameters:
x,y,w,h,radius(Integer),color(Integer)
System.drawCircle(x, y, radius, color) / System.fillCircle(...)
Renders hollow or filled circles.
- Parameters:
x,y,radius(Integer),color(Integer)
System.drawTriangle(x1, y1, x2, y2, x3, y3, color) / System.fillTriangle(...)
Renders hollow or filled 2D triangles.
- Parameters:
x1,y1,x2,y2,x3,y3(Integer),color(Integer)
System.drawFastVLine(x, y, h, color) / System.drawFastHLine(x, y, w, color)
Hardware-accelerated vertical and horizontal line rendering.
3. Direct BMP Image Streaming
System.drawBMP(path, x, y)
Streams a 16-bit, 24-bit, or 32-bit .bmp image from /local/ or /sd/ directly to the display glass via SPI DMA without consuming JavaScript heap RAM.
- Parameters:
path(String): File path (e.g."/sd/assets/logo.bmp")x,y(Integer): Destination screen coordinates
- Returns:
Boolean(trueon success)
4. Typography & Text Rendering
System.setTextColor(fg_color, bg_color)
Sets text foreground and optional background color. Setting bg_color enables hardware overwriting, clearing old character pixels without requiring rectangle fills.
- Parameters:
fg_color(Integer): Text colorbg_color(Integer, optional): Background fill color
System.setTextSize(size)
Sets the font scale multiplier (1 to 5).
- Parameters:
size(Integer)
System.drawString(text, x, y, font)
Renders text using hardware-embedded bitmap fonts.
- Parameters:
text(String)x,y(Integer)font(Integer):1(compact 6x8),2(standard 8x12), or4(large 12x16).
5. Hardware Double Buffering (Mini-Sprites)
Double buffering prevents screen flickering during high-frequency animations by rendering into an off-screen RAM buffer before pushing it to the glass in a single SPI burst.
Double-Buffering Lifecycle
// Allocate a 120x60 pixel off-screen sprite buffer
if (System.createSprite(120, 60)) {
// Direct all drawing commands to the sprite
System.bindSprite(true);
System.fillScreen(0x000000);
System.drawCircle(60, 30, 20, 0x00FFC2);
System.drawString("Mini-HUD", 20, 24, 2);
// Stop sprite redirection
System.bindSprite(false);
// Push the completed frame to screen coordinates (60, 100)
System.pushSprite(60, 100);
// Release buffer memory when finished
System.deleteSprite();
}
Memory Consideration: Full-screen 240x320 16-bit double buffers require 153.6 KB of RAM. For full-screen 3D and 2D games, external PSRAM is recommended, or use the dedicated Kryon3D Hardware Engine.