reference
Every word of the language, with an example and the picture it draws. Examples are drawn in a window of 400 by 300 pixels; a window of your own that is given no size is 800 by 600, so the same drawing sits in its top-left corner.
Shapes
The shapes a sketch draws. Positions are in pixels from the top left of the window.
circle- Draws a circle around a point.
ellipse- Draws an ellipse.
rect- Draws a rectangle.
square- Draws a square.
line- Draws a line between two points.
point- Draws a single point.
triangle- Draws a triangle through three points.
quad- Draws a four-sided shape through four points.
arc- Draws part of an ellipse, between two angles in degrees.
Color and style
How shapes look: the color inside them, the line around them, and colors made from numbers.
background- Sets the color or gradient behind everything in the window, wherever it is written.
clear- Empties the window, leaving it transparent.
fill- Sets the color of areas from now on.
no fill- Turns area color off from now on.
stroke- Sets the color of outlines and lines from now on.
no stroke- Turns outlines off from now on.
thickness- Sets the width of outlines and lines, in pixels.
alpha- Sets how solid fill and stroke are: 0 (gone) to 100 (solid) in the language, 0 to 255 in the Odin and C APIs.
caps- Sets how lines and points end from now on: butt, round or square.
joins- Sets how outlines turn corners from now on: miter, round or bevel.
rgb- Makes a color from red, green and blue, each 0 to 255.
hsb- Makes a color from hue, saturation and brightness, each 0 to 255.
oklch- Makes a color from lightness 0 to 1, chroma and hue in degrees.
gradient- Makes a gradient from a list of colors, to use wherever a color goes.
mix- Blends two colors, or two numbers; amount 0 gives the first and 1 the second.
with- Styles everything in a block, then puts the style back; the words are the ones that style one element, or a record of them.
Transforms
Moving, turning and growing everything drawn after them.
The turtle
A pen that walks and turns, as in Logo. Each window has one.
forward- Walks the turtle forward, drawing a line while its pen is down.
back- Walks the turtle backwards, without turning it round.
left- Turns the turtle anticlockwise, in degrees.
right- Turns the turtle clockwise, in degrees.
pen up- Lifts the turtle's pen: it moves without drawing.
pen down- Puts the turtle's pen down: it draws as it moves, in the stroke, or in black while there is none.
home- Sends the turtle back to the middle of the window, facing up, without drawing.
Running
When the lines of a sketch run: once, every frame, again and again, or when something happens.
draw- Runs a block every frame, for the default window or one you name.
every- Runs a block again and again, every so many seconds or frames.
on- Runs a block when something happens: a key, a mouse button, a finger, a window change, or a message. A window may be named first, and a mouse button after
mouse downormouse up. if- Runs a block when a condition is true, and another when it is not.
repeat- Runs a block a number of times.
while- Runs a block for as long as a condition is true.
for- Counts from one number to another, inclusive, and runs a block for each.
for each- Runs a block for each item of a list, with a name for the item.
Input
The mouse, the keyboard and fingers, as values a sketch reads.
mouse- Where the mouse is in the window:
mouse.xandmouse.y. pmouse- Where the mouse was a frame ago.
pressed- Whether a mouse button is held down in this window.
wheel- How far the mouse wheel turned since the last frame:
wheel.yup,wheel.xto the right. key- The name of the key pressed last.
held- Whether the key or mouse button with this name is held down right now: held "space", held "left" (the arrow key), held "mouse right". Keys have the names of on key; buttons are mouse left, middle, right, back and forward.
finger- The finger an
on touch downoron touch upblock runs for: a record withid,pos,startandpressure. touches- The fingers down in the window now, in the order they went down, each a record like
finger.
Time and animation
Time, frames, and values that move smoothly from one place to another.
time- Seconds since the sketch started.
frame- How many frames the sketch has drawn, counting from 0.
fps- How many frames a second the sketch is drawing.
tween- Moves a number, vector or color to a value over some seconds, a little each frame:
tween ball.pos to mouse over 0.5 as out. A new tween of the same place replaces the old. ease- How far along a movement is when an amount (0 to 1) of its time has passed, on a curve:
ease t as out. Smooth unlessassays linear, in, out, back, elastic or bounce.
Maths
Numbers: rounding, ranges, distance and the trigonometry of angles in degrees.
abs- A number without its sign.
floor- The whole number at or below a number: floor 2.7 is 2, floor -2.1 is -3.
round- The nearest whole number; halves go away from zero: round 2.5 is 3.
ceil- The whole number at or above a number: ceil 2.1 is 3, ceil -2.7 is -2.
sqrt- The square root.
sin- The sine of an angle in degrees.
cos- The cosine of an angle in degrees.
map- Moves a number from one range to another.
clamp- Keeps a number between a low and a high.
dist- The distance between two points.
pi- Half a turn in radians, 3.14159…, for sketches that work in radians.
tau- A whole turn in radians, 6.28318…
true- The value of a condition that holds.
false- The value of a condition that does not hold.
Random and noise
Numbers that differ each time, and noise that changes smoothly. seed makes them repeat.
random- A random number from 0 up to a limit, or
random from 1 to 3between two numbers. pick- A random item from a list.
anywhere- A random point in the window, different each time it is read.
gaussian- A random number clustered around a mean.
seed- Makes every random number from now on repeat the same way.
noise- Smooth random noise from 0 to 1 in one to four dimensions; add
as simplexfor simplex noise. fbm- Layers of noise from 0 to 1, with finer detail added on top.
shuffle- A new list with the same items in a random order:
shuffle colors.
Lists
Many things in order: making, changing and walking through lists.
add- Puts an item at the end of a list:
add p to particles. remove- Takes an item out of a list, or a name out of a table:
remove p from particles,remove "cat" from counts. count- How many items a list has, or names a table has.
item- The item at a place in a list, counting from 1:
item 1 of scores. keep- The items of a list that pass a test:
keep particles [ it.life > 0 ]. skip- The items of a list that do not pass a test.
collect- One new value for each item:
collect particles [ it.size * 2 ]. combine- Folds a list into one value, starting from a value:
combine scores from 0 [ result + it ]. find- The first item that passes a test, or an empty value.
sort- A list in order of what the block gives for each item:
sort particles by [ it.size ]. copy- An independent copy of a list or record, and everything inside it.
Tables
Text names with a value each, in the order they were put.
table- A new, empty table: text names with a value each, kept in the order they were put:
counts = table. put- Gives a name in a table a value:
put counts "cat" 3. A name already there gets the new value. get- The value of a name in a table, or an empty one (0, empty text) when it has none:
get counts "cat". keys- The names in a table, as a list of text, in the order they were put:
for each name in (keys counts) [ ... ].
Collision
Whether shapes touch, where, and what a line meets. Shapes are plain records.
touching- Whether two shapes touch, edges included:
touching ball paddle. contact- Where two shapes touch: a record with point, normal (the way to move the first to part them) and depth, every field 0 when they do not.
hits- The items of a list that touch a shape, in list order:
hits ball bricks. inside- Whether a point is inside a shape or on its edge:
inside mouse paddle. cast- The first item a line meets, from its
fromto itsto: a record with item, point, normal and distance, every field 0 (and no item) when it meets nothing.
Windows
Opening windows, changing them while they are open, and sending values between them.
window- Opens a window of the given size, optionally at a position, and gives it back.
title- Sets the title of the window the code runs in. Another window is changed with
set. fullscreen- Makes the window fill the screen.
set- Changes a window that is open, with the words of
window:set w size 400 300 resizable false. send- Sends a value to a window; it arrives on that window's next frame:
send w 5. width- The width of the window the code runs in, in pixels.
height- The height of the window the code runs in, in pixels.
quit- Closes the sketch.
Teaching verbs
New verbs of your own, and libraries of other people's.
Printing
Writing values to the console, to see what a sketch is doing.
print- Writes a value to the console.