Core 2D drawing functions for pixels, lines, rectangles, circles, and text rendering
The 2D Drawing API provides fundamental drawing primitives for creating retro-style graphics. It includes pixel-perfect drawing, geometric shapes, a camera system, and a sophisticated 64-bit color system (RGBA64) for high-precision color values.
Nova64 uses a 64-bit color system (RGBA64) with 16 bits per channel for precise color representation. Use the helper functions to work with colors easily.
Creates a 64-bit color from 8-bit RGB values (0-255).
const red = rgba8(255, 0, 0, 255);
const transparentBlue = rgba8(0, 0, 255, 128);
const white = rgba8(255, 255, 255);
Creates a 64-bit color from 16-bit RGB values (0-65535). Advanced use only.
The camera system allows you to scroll the viewport by offsetting all drawing coordinates automatically.
Sets the camera offset for all subsequent drawing operations.
// Follow player with centered camera
function update() {
const camX = player.x - 320; // Center horizontally (640/2)
const camY = player.y - 180; // Center vertically (360/2)
setCamera(camX, camY);
}
Gets the current camera offset.
{x: number, y: number}
Clears the screen with the specified color.
function draw() {
cls(rgba8(0, 0, 20)); // Dark blue background
}
Draws a single pixel at the specified coordinates.
for (let i = 0; i < 100; i++) {
const x = Math.random() * 640;
const y = Math.random() * 360;
pset(x, y, rgba8(255, 255, 255));
}
Draws a line between two points using Bresenham's algorithm.
const centerX = 320, centerY = 180;
const white = rgba8(255, 255, 255);
line(centerX - 10, centerY, centerX + 10, centerY, white);
line(centerX, centerY - 10, centerX, centerY + 10, white);
Draws a rectangle (outline or filled).
// Draw window with border
const blue = rgba8(0, 100, 200);
const white = rgba8(255, 255, 255);
rect(100, 100, 200, 150, blue, true); // Fill
rect(100, 100, 200, 150, white, false); // Border
Shortcut for drawing a filled rectangle (equivalent to rect(x, y, w, h, color, true)).
Draws a circle using midpoint circle algorithm (Bresenham).
const yellow = rgba8(255, 255, 0);
const orange = rgba8(255, 150, 0);
circle(100, 100, 30, yellow, true); // Filled inner
circle(100, 100, 40, orange, false); // Outline glow
Draws text using the bitmap font system.
const white = rgba8(255, 255, 255);
const cyan = rgba8(0, 255, 255);
print("SCORE: " + score, 10, 10, white);
print("GAME OVER", 250, 180, cyan, 2); // 2x scale
rectfill() or cls() for large filled areas instead of many pset() calls