Pixels, vectors, machines
Foundations. You don't need to be a programmer to start, but you do need a picture of what the computer is doing. This page covers the ideas that come up every day, with small things to try.
- Read
- Before Day 6
- Talk
- Day 6, 9:30
- No code
- Needed to read it
- Try
- Three live demos
- Back to
- Techniques, Codex
From code to image
Code is a list of instructions. A program reads them in order, does the arithmetic, and writes the result somewhere: to the screen, or to a file.
Source
Plain text files in src/. You and Codex write these.
Execute
A program (a browser, Python, Node) reads the source and carries it out, line by line.
Draw or save
The result appears on screen, or is written to a file: SVG, PNG, STL.
Most creative-coding tools give you two places to write: setup, which runs once at the start, and draw, which runs again and again, many times a second, for animation. A still image for printing usually only needs setup, then a save.
Coordinates
Every mark has a position: x across, y down. On screens the origin (0, 0) is the top-left corner, and y grows downwards, the opposite of school graphs.
- Units. Screens count pixels. Plotters and printers think in millimetres. Decide early which your system uses, and convert once, at export.
- Angles are usually in radians, not degrees: a full turn is about 6.283 (2π), not 360.
- Size independence. Write positions as fractions of the width and height (0.5 × width is always the middle), so the same system works on screen and on A2.
Pixels and vectors
A raster image is a grid of coloured pixels. A vector image is a set of instructions: draw a line from here to there, a circle this big. Zoom in and see the difference.
| Raster | Vector | |
|---|---|---|
| Stores | Pixels in a grid | Points, lines, curves, shapes |
| Enlarged | Blurs or turns blocky | Stays sharp |
| Good for | Tone, texture, colour fields, millions of marks | Lines, geometry, anything a pen will draw |
| Files | PNG, JPG, TIFF | SVG, PDF |
| Machine | Archival printer | Pen plotter (and laser cutters) |
A pen plotter can only follow vectors. A printer needs pixels. If you might do both, keep your system's output as vectors and render pixels from them at the size you need.
Resolution
A pixel has no size until you print it. PPI (pixels per inch) says how many pixels fit into each inch of paper. Prints need about 300 PPI to look sharp up close.
One inch is 25.4 mm, so pixels = millimetres ÷ 25.4 × PPI. Your screen shows far fewer pixels than an A2 print needs, so render the print file at full size from the system, never by enlarging a screenshot.
Colour
Light: RGB
Red, green and blue light added together; all three at full is white. Written in code as rgb(219, 38, 31) or the hex code #db261f.
Ink: subtractive
Inks absorb light; more ink is darker. Some bright screen colours can't be printed, which is why prints can look duller than the screen.
A colour profile (ICC) describes how a device shows colour. Using the printer and paper's profile lets you preview the print on screen before you spend paper on it: see the archival guide.
CPU and GPU
The CPU is a few powerful workers that do tasks one after another. The GPU is thousands of simple workers that each do the same small job at the same moment, which is exactly what filling millions of pixels needs.
- Most of your system runs on the CPU: reading data, following rules, building paths. That's fine for drawings of thousands of lines.
- The GPU matters for pixels: live animation, shaders, very large images, 3D previews.
- Slow isn't broken. A complex system may take minutes to render one A2 file. Render a small preview while you work, and the full size only for export.
Rendering
Rendering is the work of turning your system's instructions into a finished image or file.
Real-time
Drawn fast enough to watch, often 60 frames a second, at screen size. Good for exploring parameters.
Offline
Drawn once, as long as it takes, at full size: an A2 SVG, a 300 PPI TIFF, an STL. This is the file the machine uses.
Keep the two apart in your code: a preview mode that's quick, and an export mode that's exact. The same seed must give the same result in both.
Chance and seeds
Computers can't really be random. They use a formula that produces numbers that look random, starting from a number called the seed. Same seed, same sequence, same artwork.
That's what makes a generative work reproducible: the seed and the parameters are its recipe. Name every output by its seed; the system worksheet shows how. Noise, the smooth kind of randomness behind flow fields, is explained with a live sketch in Techniques.
Files you'll meet
| Format | Kind | Used for |
|---|---|---|
.svg | Vector | Plotter files, line drawings, anything that must stay sharp |
.png | Raster, lossless | Screen outputs, log images, contact sheets |
.jpg | Raster, compressed | Photographs of the work; not for final art |
.tif | Raster, print quality | Archival print files with a colour profile |
.pdf | Vector or raster | Documents, sometimes print files |
.stl / .obj | 3D mesh | Resin printing; a surface made of triangles |
.json | Text data | Your parameters in config/params.json |
.csv | Text table | Datasets: one row per record, columns separated by commas |
.md | Text | Markdown: your README, manifesto, log |
A mesh describes a 3D form as many small triangles joined at their corners. For resin printing it must be watertight: closed all round, with no gaps, so the printer knows what's inside and outside. See the resin guide.