A high-performance graphics engine for CC:Tweaked, written in Lua.
Flint lets you draw with arbitrary 24-bit hex colors instead of CC's 16 hardwired palette slots, composites multiple layers with z-ordering, and renders at up to 2× the horizontal and 3× the vertical resolution of a standard terminal using teletext mosaic characters. An optional CraftOS-PC pixel mode gives full per-pixel color fidelity with no two-color-per-cell limit.
- Hex colors — use
0xff4444,0x44aaff, or any 24-bit RGB value directly - Auto palette quantization — when more than 16 colors appear in a frame, agglomerative clustering maps them to the 16 hardware slots with minimal visual loss
- Subpixel canvas — a virtual canvas of
termWidth×2×termHeight×3subpixels, rendered as teletext mosaic characters for higher effective resolution - Precomputed texel LUT — all 6⁶ subpixel color patterns are resolved at load time, so per-cell compositing is three table lookups
- Layer system — stack multiple drawing surfaces with z-index ordering and per-layer dirty rect tracking
- Diff-based present — only changed rows are sent to the terminal via
blit(), minimizing CPU overhead - CraftOS-PC pixel mode — opt-in mode where each subpixel maps to a real 3×3 pixel block; text is rasterized using the original CC bitmap font embedded in the engine
Copy flint.lua into your ComputerCraft computer and require it:
local flint = require("flint")No external dependencies. Works in CC:Tweaked and CraftOS-PC. Pixel mode (setGraphicsMode) requires CraftOS-PC.
local flint = require("flint")
-- Create an engine bound to the current terminal
local sys = flint.new(term)
-- Add layers (lower zIndex = further back)
local bg = sys:addLayer(1)
local fg = sys:addLayer(2)
-- Optional: enable CraftOS-PC pixel mode (3×3 px per subpixel, full color)
sys:setGraphicsMode(true)
local vw, vh = sys.vWidth, sys.vHeight
local tw, th = sys.termWidth, sys.termHeight
-- Draw a title in the foreground layer
fg:drawText(2, 1, "Hello from Flint!", "0", "b")
-- Animate a sine wave in the background layer
local phase = 0
while true do
bg:clear()
for vx = 1, vw do
local vy = math.floor(vh / 2 + math.sin(vx * 2 * math.pi / vw + phase) * (vh / 4) + 0.5)
bg:drawSubpixel(vx, vy, 0x44aaff)
bg:drawSubpixel(vx, math.max(1, vy - 1), 0x1a4f7a)
end
sys:compileSubpixels()
sys:present()
phase = phase + 0.1
local timer = os.startTimer(0.05)
while true do
local ev, p1 = os.pullEvent()
if ev == "timer" and p1 == timer then break end
if ev == "char" and (p1 == "q" or p1 == "Q") then return end
end
endCreates a new Flint engine attached to the given terminal. targetTerm must expose .blit() and .getSize() — term, window.create(...), and monitor objects all work.
Creates a new layer and registers it in draw order. Layers with a lower zIndex are drawn first (further back).
Clears all registered layers.
Resolves the hardware palette, composites all layers into the output buffer, and marks changed rows for the next present() call. Call once per frame after all draw calls.
Flushes the composite buffer to the terminal using diff-based blit(). In pixel mode, renders real pixels via drawPixels(). Call after compileSubpixels().
Forces a full repaint on the next present() call, clearing the blit cache. Useful after external terminal writes or palette resets.
Switches CraftOS-PC pixel graphics mode on (true) or off (false). Returns false, reason if the terminal does not support it (i.e. standard CC / Minecraft).
Restricts all subsequent draw calls to the given cell rectangle. Both character-space and subpixel-space clip regions are updated.
Removes the clip region, restoring the full terminal extent.
Colors can be a CC palette slot ("0"–"f") or a 24-bit RGB integer (0xRRGGBB). nil means "leave unchanged" for optional parameters.
Clears all char, subpixel, and color data on this layer.
Clears only the subpixel canvas, leaving character data intact. More efficient than clear() for subpixel-only layers.
Writes a single character at terminal-cell position (x, y).
Writes a string starting at terminal-cell position (x, y).
Fills a rectangle in terminal-cell coordinates.
Sets a single subpixel on the virtual canvas at (vx, vy).
Fills a rectangle on the virtual canvas in subpixel coordinates.
Draws a Bresenham line on the virtual canvas between two subpixel positions.
| Property | Description |
|---|---|
sys.termWidth / sys.termHeight |
Terminal size in cells |
sys.vWidth / sys.vHeight |
Virtual canvas size in subpixels (termWidth×2 / termHeight×3) |
MIT