The screen

The screen is 320 pixels wide and 240 high, x from the left and y from the top. Each pixel holds a color number, 0 to 255. A Rinc shows it at any whole-number scale (the Fruit Jam's HDMI output is 640x480, each pixel 2x2). An app starts with the screen all the theme's background (pc.theme(.bg); 235, Steel's dark gray, without one): Rinc's text screen, where what it logs shows until it draws, and where Rinc shows what went wrong if it fails.

Drawing

proc
pc.cls(c)every pixel becomes c
pc.pset({x, y}, c)pixel x, y becomes c; nothing happens off the screen
pc.pget({x, y}) -> Intpixel x, y, or 0 off the screen
pc.rect({x, y}, {w, h}, c)pixels from x up to x + w, and y up to y + h, become c; cut off at the screen's edges; nothing when w or h is 0 or less
pc.rect(pos, size, c, {outline = true, radius = r})its edge alone, a pixel wide; its corners rounded by r pixels (at most half its width or height)
pc.ellipse({x, y}, {w, h}, c)the ellipse in that rectangle (a square: a circle); a pixel's drawn if its center's inside; {outline = true}: its edge alone, with no gaps
pc.triangle(p, q, r, c)the triangle with those corners (pixels: each in it); {outline = true}: its three edges, as line draws them
pc.curve(from, c1, c2, to, c)a curve (cubic Bezier; its points [2]Float, between pixels too) from from to to, pulled toward c1 then c2 (both the same point: a gentler, quadratic-like bend); as lines a few pixels long, both ends drawn
pc.polygon(points, c, how?)a polygon, its corners in order ([][2]Float: between pixels too, a pixel in if its center is) ({{10, 10}, {40, 10}, {25, 30}}), the last joined to the first; filled where its edges wind around (crossing itself: still filled), each corner's pixel in; at most 64 edges crossing any one row; {outline = true}: its edges; two points: a line
p: pc.Path, then p.clear(), p.move(to), p.line(to), p.curve(c1, c2, to), p.arc(center, radii, from, to), p.close(), p.draw(c, how?)a path of lines, curves and arcs (angles in radians, as sin and cos: 0 right, a quarter turn down; an arc begins with a line from where the path is), in parts (move starts one); kept in the app's memory, 128 points at most (a curve or an arc takes 3); filled: each part closed, filled where its edges wind around (a part inside another going the other way round: a hole; move to the center, arc, close: a pie's slice); {outline = true}: its lines, a part closed only by close
pc.transform(m), pc.transformBy(m)the transform all drawing goes through (pset, line, rect, ellipse, triangle, curve, polygon, paths, blit, print): m is a, b, c, d, e, f, the plane the pixels tile (pixel x, y the square from x, y to x + 1, y + 1) taken to a x + c y + e, b x + d y + f, an image's or a rect's whole area with it (a scale of 2: as blit's own); a pixel's drawn if its center lands inside; an image, each screen pixel taken back to the image's pixel there (nearest); transform sets it, transformBy puts m under the one there (m first: a part turned inside its whole, moved); each gives back the one it replaced, to put back with transform; plain again at each frame's start and each app's. Made by pc.plain(), pc.moved(by), pc.scaled(by), pc.turned(angle) and pc.turnedAround(angle, at) (radians: a quarter turn, right to down). Transformed, a rect or an ellipse is drawn as a polygon (filled: its area's edge; outlined: through its edge pixels)
pc.line(from, to, c)a line, both ends drawn, a pixel each step along its longer way; cut off at the screen's edges (far off it costs nothing)
pc.rgb(c) -> Intcolor c of the palette (0 to 255), as 0xRRGGBB
pc.print(s, {x, y}, c)the text's characters, one every 6 pixels from x, drawn at y in color c
pc.blit(image, at, b?)a picture (a pc.Image: its pixels, row by row, a byte each or packed as its depth says, and its size; as pc.imageRead gives one, see apps), its top left at at, or b.size of it from b.from (a 0 in size: the rest of it that way), each pixel b.scale wide and high (a 0: 1; negative mirrors it that way: {-1, 1} flips it left for right); its 0s are see-through. b is a pc.Blit (from, size and scale, each a [2]Int, and map), so what's left out of {...} is 0, and b left out is all 0s: pc.blit(image, {10, 20}) draws all of it at its size. b.map, a []Int, draws it in other colors: each pixel's index (a byte-a-pixel picture's color) to the color drawn, 0 or -1 see-through, instead of its own palette: a sheet's red team blue, a hit's flash

A color is the low 8 bits of the number given: pc.cls(257) is pc.cls(1).

pc.cls(300)
pc.rect({-5, -5}, {10, 10}, 7)
pc.rect({10, 10}, {0, 5}, 9)
log(pc.pget({0, 0}), pc.pget({4, 4}), pc.pget({5, 5}), pc.pget({10, 10}))
7 7 44 44

A sprite drawn twice as big, its see-through pixel leaving what's under it, then its bottom row alone:

pc.cls(1)
pic: Blob[4] # (2 by 2)
pic[0] = 8
pic[1] = 0
pic[2] = 9
pic[3] = 10
image := pc.Image{pixels = pic[], size = {2, 2}}
pc.blit(image, {10, 10}, {scale = {2, 2}})
pc.blit(image, {40, 10}, {scale = {-2, 2}}) # (mirrored)
log(pc.pget({10, 10}), pc.pget({11, 11}), pc.pget({12, 10}), pc.pget({13, 13}), pc.pget({14, 14}))
pc.blit(image, {30, 30}, {from = {0, 1}, size = {0, 1}})
log(pc.pget({30, 30}), pc.pget({31, 30}), pc.pget({30, 31}))
8 8 1 10 1
9 10 1

Half and quarter screens

pc.screen(.half) makes the app's screen 160 by 120, each pixel shown 2 by 2; pc.screen(.quarter), 80 by 60, each shown 4 by 4; pc.screen(.full), 320 by 240 again. It's the app's alone: every app starts full. Drawing is clipped to the screen's size, so drawing is quicker the smaller it is; text is drawn as big as the pixels are, and the pointer's place (pc.pointerState().at) is in them. pc.screenSize() is its size now. The system's own (its notices, the command list) stay full size.

pc.screen(.half)
log(pc.screenSize())
pc.screen(.full)
log(pc.screenSize())
[160, 120]
[320, 240]

A frame that would come out wrong can be held back: pc.holdFrame(), during a frame, keeps it from being shown, the frame before it staying on the screen a 60th of a second more. It's for drawing that's right a frame late, as the ui library's layouts are when what's in them changes size: it holds that frame, and the next, laid out by it, is shown. Never two in a row: the next frame is shown whatever it asks, so a screen can't freeze.

Text

pc.print draws each character of the text (UTF-8: a code point each) with Rinc's own font, 5x11 glyphs in 6x12 cells, fixed width: the pixels of the character's glyph become c, and the rest are left as they are. It has ASCII and Latin-1, 33 to 255 (é, ñ, ©); the others draw nothing, and every character moves 6 pixels to the right. It's compact unless asked: a line of 9 pixels (the default) leaves out the glyphs' top 3 rows, which no ASCII glyph uses (the accents over capitals: É is drawn as E there), and a line of 12 ({font = {line = 12}}) has them all; a line between leaves out what it must. Rinc works the 3 out from the glyphs themselves (the rows above every ASCII one), so a font with other proportions needs no note.

A newline starts the next line, 9 pixels down. pc.print(s, pos, c, how) lays the text out as how, a pc.Text, says: width, in pixels, wraps it, a line breaking at the last space that fits (the space not drawn) and a word longer than a line breaking where it must; its font's line is the pixels from a line to the next (0: its cell's height; Rinc's own, 9, compact): {font = {line = 12}} spaces Rinc's own font 12 apart, its glyphs whole. pc.textSize(s, how?) is how big print draws it: its widest line's width and its lines' height, for a box around it or text placed by its size.

log(pc.textSize("Kree! Clouds below, stars above.", {width = 96}))
log(pc.textSize("a\nbc"))
[71, 26]
[11, 17]

Fonts

Rinc's own font is such a sheet too: src/core/rinc-font.png (5x11 cells, 16 across, 32 to 255, 1 bit, saved uncompressed), carried in the firmware as the file's bytes and drawn from where they lie, its cells as its notes say. To change it, draw it in Paint (any depth), then python tools/fontsheet.py --from it.png: it writes rinc-font.png and font.c (an ASCII glyph left blank keeps the one there now, named as a placeholder).

A font is a sheet of glyphs, a picture in cells of one size, a character a cell across its rows: Paint makes one as it makes a sprite sheet. Its notes say what it is, a line each:

line
font 32 126it's a font: its first cell's character and its last's
sprite 6x9its cells' size
proportionaleach glyph as wide as its columns with pixels (its empty ones trimmed, either side); else every glyph its cell's width (a 6x12 font of glyphs up to 5x11: sprite 5x11, gap 1, line 12; or sprite 6x12, the spare column and row left empty)
gap 1pixels after each glyph, negative for closer (if it's left out: 1 for a proportional font, 0 for a fixed one)
space 3a space's width, and an empty glyph's (half a cell if it's left out)
line 10pixels from a line to the next (its cells' height if it's left out)
colorsits glyphs drawn in their own colors (else in the color print is given)

pc.fontRead(path, room, o?) reads one into the Blob[..] room (its picture, as pc.imageRead does, at its own depth, or, o a pc.ImageRead with from and size, just whole rows of its cells: those characters, {from = {0, 12}, size = {80, 24}} the second and third rows of a 16-across 5x12 font; at its own depth: a font of 1 bit, 2 colors, takes an eighth of the room of 8; then two bytes a glyph for a proportional one: where it starts in its cell, and its width), as a pc.Font; pc.Text's font draws in it (print) and measures it (textSize), wrapping as its glyphs' widths say. A picture that isn't a font, or isn't there, reads as a pc.Font with no cells: Rinc's own.

room: Blob[..(96 + 1) * 54 + 190]          # its picture's rows, as it's read; and two bytes a glyph
title := pc.fontRead("title.png", room)
pc.print("CLOUDLAMP", {20, 20}, 10, {font = title})

The palette

The palette is 16 bands of 16 colors, a band to each row of 16 (as the Colors app shows them). Colors 0 to 15 are PICO-8's, 16 to 31 its secret palette (PICO-8's 128 to 143); then a band for each of 12 hues; then 16 tints and 16 grays. PICO-8's are:

colorRGBcolorRGB
0000000 black8FF004D red
11D2B53 dark blue9FFA300 orange
27E2553 dark purple10FFEC27 yellow
3008751 dark green1100E436 green
4AB5236 brown1229ADFF blue
55F574F dark gray1383769C lavender
6C2C3C7 light gray14FF77A8 pink
7FFF1E8 white15FFCCAA peach
16291814 brownish black24BE1250 dark red
17111D35 darker blue25FF6C24 dark orange
18422136 darker purple26A8E72E lime green
19125359 blue green2700B543 medium green
20742F29 dark brown28065AB5 true blue
2149333B darker gray29754665 mauve
22A28879 medium gray30FF6E59 dark peach
23F3EF7D light yellow31FF9D81 peach

The rest are made in OKLCH (Björn Ottosson's OKLab, as lightness, chroma and hue: a color space made so equal steps look equal), by tools/palette.py, which writes them as the table in src/core/palette.h:

colorsbandhue
32 to 47red29
48 to 63orange65
64 to 79yellow100
80 to 95lime121
96 to 111green142
112 to 127teal169
128 to 143cyan195
144 to 159azure229
160 to 175blue264
176 to 191violet296
192 to 207magenta328
208 to 223crimson359
224 to 239tints: 8 warm, then 8 cool60, 250
240 to 255grays
  • A hue's band: its first 8 are vivid, dark to light, then 8 muted, dark to light: 32 + 16 * k is hue k's darkest vivid, and + 8 its darkest muted. The hues are sRGB's red, yellow, green, cyan, blue and magenta (where OKLCH puts them, but a warmer yellow), and the hue halfway between each two. The vivid steps run from lightness 0.28 to 0.88 (0.91 for orange to azure, most vivid when light), one of them where the hue is most vivid, at nearly the most chroma sRGB has there, no step much more than its neighbours; the muted ones from 0.36 to 0.86, at the same chroma, 0.07, for every hue.
  • The tints: warm grays (toward orange) and cool ones (toward blue), each 8 from lightness 0.18 to 0.92, at chroma 0.025.
  • The grays: pure grays, black to white, even in lightness as it looks: 000000, 101010, 202020, 303030, 404040, 4E4E4E, 5E5E5E, 6E6E6E, 808080, 919191, A2A2A2, B4B4B4, C7C7C7, D9D9D9, EBEBEB, FFFFFF. Color 240 is black, as 0 is, for when 0 is see-through.

Each of the hues' and tints' colors is the one at 16 bits a pixel (below) nearest what OKLCH asked for, so what a Rinc shows keeps its hue.

Every Rinc shows the palette at 16 bits a pixel, RGB565: each component's top 5, 6 and 5 bits. Where a display has more bits, a component v of n bits becomes v * 255 / (2^n - 1), rounded down, so every Rinc shows exactly the same colors.