Sprout

The standard library: 67 modules, 601 words, written in Sprout. And 2 kits that draw, and 9 wrapped libraries.

Each module is a cell whose fields are its words, there in every program: ease out-cubic 0.5, stats median xs, grid path [g, from, to, open]. The source is in lib/, one file a module, and is worth reading: every word is a few lines.

One way of working runs through all of them. A point, a size, a cell of a grid and a hex are pairs, like 3x4, read with p x and p y, and added and scaled like numbers. A word's inputs come in the same order: what it works on, then how, then the time or the seed. Randomness only ever comes from a seed, through seeded, so a game that rewinds, and a second phone playing along, get the same luck. And every example below shows its answer, which is worked out, and checked, each time the library is built.

Words and numbers format prose integers span measure stats

Apps and data stack calendar finance tabular graph sets fuzzy validate undo csv json lick

Time and motion ease motion arc platform spring keyframes flipbook steer daytime

Touch and sound pad menu focus gesture music

Space vec shape segment spline collide grid automata tilemap runs piece hex iso camera parallax orbit layout matrix geo

Chance seeded dice cards piles reels bag shop

Play combat waves particles rewards story wordplay league economy needs

Colour palette

Of these, 17 were distilled from the 319 TaskIAP games and apps: what they kept writing again and again, written once, small and well, in Sprout: camera, cards, collide, combat, daytime, dice, economy, grid, hex, league, motion, particles, platform, rewards, story, waves, wordplay. A count in each one's opening says how many games needed it.

Built into every value as well: the list, record, text and number words, endless lists, the literals, parse, quote and script. They are in the spec (decisions 99 to 104).

Words and numbers

format

Numbers and text made ready to show.

format commas [n]

a whole number with commas between the thousands

format commas 1234567
-- 1,234,567
format places [n, count]

a number with a fixed number of places after the point

format places [3.14159, 2]
-- 3.14
format percent [x]

a share from 0 to 1 as a percent

format percent 0.256
-- 26%
format ordinal [n]

1st, 2nd, 3rd, 4th ... 11th, 12th, 13th, 21st

format ordinal 22
-- 22nd
format plural [n, word]

a count and a word, with an s when there isn't exactly one

format plural [3, "apple"]
-- 3 apples
format clock [seconds]

seconds as m:ss, or h:mm:ss past an hour

format clock 3725
-- 1:02:05
format wrap [words-text, width]

text broken into lines no longer than width, at spaces

format wrap ["the quick brown fox jumps over the lazy dog", 12]
-- [the quick, brown fox, jumps over, the lazy dog]
format centre [line, width]

text in the middle of a line width wide

format centre ["hi", 6] replace-all [" ", "."]
-- ..hi..
format title [line]

Every Word Capitalized

format title "the sprout standard library"
-- The Sprout Standard Library
format bar [value, most, width]

a bar of blocks, value out of most, width wide

format bar [3, 4, 8]
-- ######..
format short [n]

a number short enough to read at a glance: 1.2K, 3.4M, 5.6B, 7.8T (idle and tycoon games)

format short 1234567
-- 1.2M

prose

Text tools: slugs and cases for names in code and links, initials, cutting text short, lists and numbers written in English, how far apart two words are, palindromes, sentences and syllables.

prose slug [line]

text made fit for a web address: lower case, words joined by hyphens

prose slug "Hello, World! 2026"
-- hello-world-2026
prose camel [line]

text in camel case, as many programming languages name things

prose camel "the high score"
-- theHighScore
prose snake [line]

text in snake case, words joined by underscores

prose snake "The High Score"
-- the_high_score
prose initials [line]

the first letter of each word, in capitals

prose initials "Ada King Lovelace"
-- AKL
prose truncate [line, n]

text cut to at most n letters, ending with … when something was cut

prose truncate ["The quick brown fox", 10]
-- The quick…
prose blend [a, b]

two words blended into one: the first half of one and the last half of the other (a portmanteau)

prose blend ["bite", "kick"]
-- bick
prose blend ["graze", "hide"]
-- grade
prose tidy [line]

extra spaces taken out: trimmed, and one space between words

prose tidy "  far   too    spaced  "
-- far too spaced
prose list-of [items]

items listed in English, with "and" before the last

prose list-of ["tea", "cake", "jam"]
-- tea, cake and jam
prose list-of ["tea", "cake"]
-- tea and cake
prose spell [n]

a whole number written out in English words

prose spell 42
-- forty-two
prose spell 2026
-- two thousand and twenty-six
prose spell 1000105
-- one million one hundred and five
prose distance [a, b]

how many letters must be added, taken away or changed to turn one word into another (Levenshtein distance)

prose distance ["kitten", "sitting"]
-- 3
prose similar [a, b]

how alike two words are, from 0 (nothing alike) to 1 (the same)

prose similar ["night", "nacht"]
-- 0.6
prose palindrome [line]

does text read the same backwards, ignoring case, spaces and marks?

prose palindrome "Never odd or even"
-- true
prose count-of [line, part]

how many times part appears in text, without overlaps

prose count-of ["banana", "an"]
-- 2
prose between [line, opening, closing]

the text between two markers, or false if the first isn't there

prose between ["<b>bold</b> move", "<b>", "</b>"]
-- bold
prose mask [line, n]

all but the last n letters hidden

prose mask ["4111111111111111", 4]
-- ************1111
prose reverse-words [line]

the words in the other order

prose reverse-words "one two three"
-- three two one
prose sentences [line]

text split into sentences

prose sentences "Hi. How are you? Fine!"
-- [Hi., How are you?, Fine!]
prose syllables [word]

about how many syllables a word has (a count of its vowel sounds)

prose syllables "beautiful"
-- 3
prose syllables "table"
-- 2

integers

Whole numbers: common factors and multiples, primes, digits, factorials and choosing, Fibonacci and triangle numbers, Roman numerals and other bases. For number puzzles, quizzes and teaching games.

integers finite [n]

is n a number that ends (not text, not endless, not the answer to 0 / 0)? The words that go round until they reach an answer ask first, so they stop

integers finite 12
-- true
integers finite (1 / 0)
-- false
integers gcd [a, b]

the greatest common divisor: the largest number that divides both

integers gcd [12, 18]
-- 6
integers lcm [a, b]

the least common multiple: the smallest number both divide

integers lcm [4, 6]
-- 12
integers prime [n]

is n a prime (divided only by 1 and itself)?

integers prime 97
-- true
integers prime 91
-- false
integers primes [n]

the primes up to n

integers primes 30
-- [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
integers factors [n]

n as a product of primes, smallest first

integers factors 360
-- [2, 2, 2, 3, 3, 5]
integers divisors [n]

every whole number that divides n, smallest first

integers divisors 12
-- [1, 2, 3, 4, 6, 12]
integers perfect [n]

is n perfect: the sum of its other divisors?

integers perfect 28
-- true
integers digits [n]

the digits of n, the most significant first

integers digits 4096
-- [4, 0, 9, 6]
integers digit-sum [n]

the sum of n's digits

integers digit-sum 4096
-- 19
integers digital-root [n]

the digits added again and again until one is left

integers digital-root 4096
-- 1
integers factorial [n]

n factorial: 1 × 2 × … × n

integers factorial 5
-- 120
integers choose [n, k]

how many ways there are to choose k things from n, in any order

integers choose [5, 2]
-- 10
integers choose [52, 5]
-- 2598960
integers fibonacci [n]

the nth Fibonacci number: 1, 1, 2, 3, 5, 8, each the sum of the two before

integers fibonacci 10
-- 55
integers triangle [n]

the nth triangle number: 1 + 2 + … + n

integers triangle 10
-- 55
integers square [n]

is n a whole number squared?

integers square 49
-- true
integers collatz [n]

how many steps n takes to reach 1, halving when even, else three times plus one

integers collatz 27
-- 111
integers roman [n]

n in Roman numerals

integers roman 2026
-- MMXXVI
integers roman 1994
-- MCMXCIV
integers from-roman [numeral]

the number a Roman numeral stands for

integers from-roman "MCMXCIV"
-- 1994
integers to-base [n, base]

n written in a base from 2 to 36

integers to-base [255, 16]
-- ff
integers to-base [10, 2]
-- 1010
integers from-base [digits-text, base]

the number a text in a base stands for

integers from-base ["ff", 16]
-- 255

span

Ranges written as pairs, low x high (0x10 runs from 0 to 10): keeping a value inside one, where a value sits in one, carrying a value from one range to another, wrapping, snapping and fading. For sliders, health bars, scrolling, volume and anything kept within bounds.

span clamp [value, bounds]

value kept inside bounds

span clamp [12, 0x10]
-- 10
span mix [bounds, t]

the value a share t of the way through bounds (0 is low, 1 is high)

span mix [0x10, 0.25]
-- 2.5
span where [value, bounds]

how far through bounds value is: 0 at low, 1 at high

span where [2.5, 0x10]
-- 0.25
span remap [value, from, to]

value carried from one range to another: the same share of the way through

span remap [5, 0x10, 0x100]
-- 50
span remap [25, 0x100, 1x0]
-- 0.75
span wrap [value, bounds]

value wrapped round inside bounds, as an angle wraps round a circle

span wrap [12, 0x10]
-- 2
span wrap [-1, 0x10]
-- 9
span bounce [value, bounds]

value bounced back and forth between the ends of bounds

span bounce [12, 0x10]
-- 8
span snap [value, step]

value moved to the nearest multiple of step

span snap [7.3, 0.5]
-- 7.5
span nearest [value, choices]

the choice nearest value

span nearest [12, [0, 10, 25]]
-- 10
span holds [bounds, value]

does bounds hold value, ends included?

span holds [0x10, 10]
-- true
span width [bounds]

how wide bounds is

span width 2x7
-- 5
span overlap [a, b]

the part two ranges share, or false if they don't meet

span overlap [0x5, 3x8]
-- 3x5
span overlap [0x2, 3x8]
-- false
span steps [bounds, n]

n + 1 evenly spaced values from low to high

span steps [0x10, 4]
-- [0, 2.5, 5, 7.5, 10]
span fade [value, bounds]

0 below bounds, 1 above, and a smooth climb between (smoothstep)

span fade [2.5, 0x10]
-- 0.15625

measure

Units and conversions between them: lengths, weights, volumes, areas, times, speeds and sizes of data, with temperatures and angles. A unit is a short name such as "km", "mi", "lb", "cup" or "km/h"; cups, pints and gallons are American, "uk-pt" and "uk-gal" British. Each unit is kept as its name, how many of the kind's base unit it is (metres, kilograms, litres, square metres, seconds, metres a second, bytes) and what it measures.

measure convert [value, from, to]

value in one unit turned into another of the same kind (false if they measure different things)

measure convert [10, "km", "mi"]
-- 6.2137119224
measure convert [2, "cup", "ml"]
-- 473.176473
measure convert [1, "kg", "km"]
-- false
measure kind-of [unit]

what a unit measures

measure kind-of "knot"
-- speed
measure units [kind]

the units for one kind of thing, smallest first, for a picker

measure units "length"
-- [mm, cm, m, km, in, ft, yd, mi, nmi]
measure temperature [value, from, to]

a temperature turned from one scale to another: "C", "F" or "K"

measure temperature [100, "C", "F"]
-- 212
measure temperature [-40, "F", "C"]
-- -40
measure degrees [radians]

an angle in radians turned to degrees

measure degrees pi
-- 180
measure radians [angle]

an angle in degrees turned to radians

measure radians 90
-- 1.5707963268
measure bytes [n]

a size in bytes, as people read it

measure bytes 1536
-- 1.5 KB
measure bytes 3221225472
-- 3 GB
measure duration [seconds]

a length of time in hours, minutes and seconds, leaving out what's zero

measure duration 3725
-- 1h 2m 5s
measure duration 7200
-- 2h
measure pace [distance, seconds]

a running pace: minutes and seconds for each km (or mile) at distance covered in seconds

measure pace [5, 1650]
-- 5:30

stats

Numbers that sum up a list of numbers.

stats mean [xs]

the average

stats mean [2, 4, 9]
-- 5
stats median [xs]

the middle value once they are sorted (the average of the two middle ones for an even count)

stats median [7, 1, 3, 9]
-- 5
stats mode [xs]

the value that comes up most often (the first of them, if several tie)

stats mode [3, 1, 3, 2, 1, 3]
-- 3
stats variance [xs]

how spread out the values are: the mean of the squared distances from the mean

stats variance [2, 4, 4, 4, 5, 5, 7, 9]
-- 4
stats spread [xs]

the standard deviation: the square root of the variance

stats spread [2, 4, 4, 4, 5, 5, 7, 9]
-- 2
stats percentile [xs, p]

the value below which a share p of them fall, from 0 to 1 (between two values, part of the way)

stats percentile [[15, 20, 35, 40, 50], 0.4]
-- 29
stats range-of [xs]

the smallest and largest, as a pair

stats range-of [4, 9, 1]
-- 1x9
stats normalize [xs]

each value placed between 0 (the smallest) and 1 (the largest)

stats normalize [10, 15, 20]
-- [0, 0.5, 1]
stats histogram [xs, n]

how many values fall in each of n equal steps from the smallest to the largest

stats histogram [[1, 2, 2, 3, 3, 3, 4], 3]
-- [1, 2, 4]
stats correlation [xs, ys]

how closely two lists rise and fall together, from -1 to 1

stats correlation [[1, 2, 3, 4], [2, 4, 5, 8]]
-- 0.981155781
stats summary [xs]

a record of the usual numbers for a list

stats summary [3, 1, 4, 1, 5, 9, 2, 6]
-- [n : 8, mean : 3.875, median : 3.5, spread : 2.571, smallest : 1, largest : 9]

Apps and data

stack

An app as a stack of cards, after HyperCard: each card a record with a name and its fields, and the stack [cards : [...], at : 1] knows which card is showing. Go to the next or the previous card (round the ends), the first, the last or one by name; find words on any card after this one; put a value into a field of the card showing; and add a card after it. For address books, quizzes, recipes and little databases.

stack card [book]

the card showing

stack card [cards : [[name : "home"], [name : "map"]], at : 2] name
-- map
stack go [book, where]

the stack moved to the "next", "previous", "first" or "last" card, or to the card of that name

stack go [[cards : [[name : "a"], [name : "b"]], at : 2], "next"] at
-- 1
stack go [[cards : [[name : "a"], [name : "b"], [name : "c"]], at : 1], "previous"] at
-- 3
stack go [[cards : [[name : "a"], [name : "b"], [name : "c"]], at : 1], "c"] at
-- 3
stack find [book, words]

the stack moved to the first card after this one, going round, with the words in any of its fields; where it was if none has them

stack find [[cards : [[name : "a", note : "milk"], [name : "b", note : "eggs and ham"]], at : 1], "ham"] at
-- 2
stack put [book, field, value]

the stack with a value put into a field of the card showing

stack card (stack put [[cards : [[name : "a"]], at : 1], "note", "hi"]) note
-- hi
stack add [book, new-card]

the stack with a card added after the one showing, which it then shows

stack add [[cards : [[name : "a"], [name : "c"]], at : 1], [name : "b"]] cards collect [c | c name]
-- [a, b, c]

calendar

Dates for apps: how long months are, leap years, a month laid out in weeks for a calendar view, weeks of the year, ages, how long ago something was, the nth weekday of a month, repeating events and Easter. Dates are Sprout's own (2026-11-20), and weeks start on Monday.

calendar leap [year]

is year a leap year?

calendar leap 2024
-- true
calendar leap 1900
-- false
calendar days-in [year, month]

how many days a month has

calendar days-in [2026, 2]
-- 28
calendar days-in [2024, 2]
-- 29
calendar parts [when]

a date's year, month and day

calendar parts 2026-11-20
-- [year : 2026, month : 11, day : 20]
calendar month-name [m]

the name of a month, from its number

calendar month-name 11
-- November
calendar weekday-number [when]

a date's weekday as a number, Monday 1 to Sunday 7

calendar weekday-number 2026-11-20
-- 5
calendar month [year, m]

the weeks of a month, for a calendar view: lists of seven days, Monday first, false where a day belongs to the month before or after

calendar month [2026, 11] length
-- 6
calendar month [2026, 11] @ 1
-- [false, false, false, false, false, false, 2026-11-01]
calendar week-of [when]

the week of the year a date falls in (ISO weeks: week 1 holds the year's first Thursday)

calendar week-of 2026-11-20
-- 47
calendar quarter [when]

which quarter of the year a date is in

calendar quarter 2026-11-20
-- 4
calendar age [born, today]

how old someone born on one date is on another, in whole years

calendar age [1990-06-15, 2026-11-20]
-- 36
calendar age [1990-12-25, 2026-11-20]
-- 35
calendar ago [seconds]

how long ago something was, in words, from the seconds since it happened (negative seconds are still to come)

calendar ago 7200
-- 2 hours ago
calendar ago 30
-- just now
calendar ago -172800
-- in 2 days
calendar nth-weekday [year, m, day-name, n]

the nth weekday of a month, such as the fourth Thursday of November; n of -1 is the last one

calendar nth-weekday [2026, 11, "Thursday", 4]
-- 2026-11-26
calendar nth-weekday [2026, 5, "Monday", -1]
-- 2026-05-25
calendar next [when, day-name]

the first date after a day that falls on a weekday

calendar next [2026-11-20, "Monday"]
-- 2026-11-23
calendar days [from, to]

every date from one to another, both included

calendar days [2026-11-20, 2026-11-23]
-- [2026-11-20, 2026-11-21, 2026-11-22, 2026-11-23]
calendar workdays [from, to]

how many weekdays, Monday to Friday, there are from one date to another, both included

calendar workdays [2026-11-20, 2026-11-27]
-- 6
calendar every [start, step, from, to]

a repeating event: the dates from start, every step days, that fall from one date to another

calendar every [2026-11-02, 14, 2026-11-01, 2026-12-31]
-- [2026-11-02, 2026-11-16, 2026-11-30, 2026-12-14, 2026-12-28]
calendar easter [year]

the date of Easter Sunday in a year

calendar easter 2026
-- 2026-04-05
calendar easter 2025
-- 2025-04-20
calendar weekend [when]

is a date a Saturday or a Sunday?

calendar weekend 2026-11-21
-- true
calendar week-start [when]

the Monday that starts a date's week

calendar week-start 2026-11-20
-- 2026-11-16
calendar month-end [when]

the last day of a date's month

calendar month-end 2026-02-10
-- 2026-02-28
calendar written [when]

a date written out in full

calendar written 2026-11-20
-- Friday 20 November 2026

finance

Money over time: what a loan costs each month and how it's paid off, savings that compound, how long money takes to double, changes in percent, tax, tips and fair shares, break-even points and what an investment is worth. Rates are shares (0.05 is 5% a year); the answers are numbers, ready for format places.

finance payment [principal, yearly-rate, months]

the monthly payment that pays off a loan over a number of months

finance payment [200000, 0.06, 360] round
-- 1199
finance schedule [principal, yearly-rate, months]

each month of a loan: the interest, what was paid off and what is still owed

finance schedule [1000, 0.12, 3] collect [row | row owed round]
-- [670, 337, 0]
finance grow [principal, yearly-rate, times-a-year, years]

what a sum grows to, compounded times-a-year, after a number of years

finance grow [1000, 0.05, 12, 10] round
-- 1647
finance saved [monthly, yearly-rate, months]

what saving the same each month comes to after a number of months

finance saved [100, 0.06, 120] round
-- 16388
finance doubling [yearly-rate]

how many years money takes to double at a yearly rate

finance doubling 0.07 * 10 round / 10
-- 10.2
finance change [old, new]

the change from old to new, as a share of old

finance change [80, 100]
-- 0.25
finance with-tax [amount, rate]

an amount with tax added

finance with-tax [100, 0.1]
-- 110
finance before-tax [amount, rate]

an amount with tax taken out

finance before-tax [110, 0.1]
-- 100
finance tip [bill, share, people]

what each person pays of a bill with a tip

finance tip [84, 0.15, 3]
-- 32.2
finance split [total, people]

a total shared fairly to the cent, the odd cents going to the first shares

finance split [100, 3]
-- [33.34, 33.33, 33.33]
finance present [amount, yearly-rate, years]

what an amount some years away is worth now

finance present [1000, 0.05, 10] round
-- 614
finance break-even [fixed, price, cost]

how many must be sold to cover fixed costs, at a price, when each costs something to make

finance break-even [5000, 25, 15]
-- 500
finance margin [price, cost]

the share of a price that is profit

finance margin [25, 15]
-- 0.4
finance npv [flows, rate]

what a run of yearly amounts (the first one now) is worth now (net present value)

finance npv [[-1000, 500, 500, 500], 0.1] round
-- 243
finance irr [flows]

the yearly rate at which a run of amounts is worth nothing now (internal rate of return)

finance irr [-1000, 500, 500, 500] * 1000 round / 1000
-- 0.234

tabular

Tables kept as lists of records, one record a row, the way a spreadsheet or a database holds them: a column's values, picking columns, sorting and filtering, totals, counts and averages by group, the top rows, joining two tables, a pivot, and the whole table as aligned text. Columns are named by text, such as "region".

tabular sample

a small table of sales to try these words on

tabular sample length
-- 5
tabular column [rows, name]

the values in one column

tabular column [tabular sample, "sold"]
-- [12, 7, 4, 9, 6]
tabular pick [rows, names]

the rows with only some columns kept

tabular pick [tabular sample, ["item", "sold"]] @ 1
-- [item : tea, sold : 12]
tabular sorted [rows, name]

the rows sorted by a column, smallest first

tabular sorted [tabular sample, "sold"] collect [r | r sold]
-- [4, 6, 7, 9, 12]
tabular sorted-down [rows, name]

the rows sorted by a column, largest first

tabular sorted-down [tabular sample, "sold"] @ 1 item
-- tea
tabular where [rows, name, value]

the rows whose column holds a value

tabular where [tabular sample, "region", "north"] length
-- 2
tabular total [rows, name]

a column added up

tabular total [tabular sample, "sold"]
-- 38
tabular total-by [rows, group-name, value-name]

one column added up for each value of another, as a record

tabular total-by [tabular sample, "region", "sold"]
-- [north : 16, south : 13, east : 9]
tabular count-by [rows, name]

how many rows hold each value of a column, as a record

tabular count-by [tabular sample, "item"]
-- [tea : 2, cake : 2, jam : 1]
tabular average-by [rows, group-name, value-name]

the average of one column for each value of another, as a record

tabular average-by [tabular sample, "item", "sold"]
-- [tea : 9.5, cake : 5, jam : 9]
tabular top [rows, name, n]

the n rows with the largest values in a column

tabular top [tabular sample, "sold", 2] collect [r | r region]
-- [north, east]
tabular group [rows, name]

the rows split up by the value of a column, as a record of lists of rows

tabular group [tabular sample, "region"] north length
-- 2
tabular with-column [rows, name, make]

the rows with a column worked out from each row

tabular with-column [tabular sample, "takings", [r | r sold * (r price)]] collect [r | r takings]
-- [36, 21, 20, 36, 30]
tabular joined [rows, others, name]

each row joined with the rows of another table that hold the same value in a column (rows with no partner are left out)

tabular joined [[[item : "tea", sold : 3]], [[item : "tea", price : 2], [item : "jam", price : 4]], "item"]
-- [[item : tea, sold : 3, price : 2]]
tabular pivot [rows, row-name, column-name, value-name]

a pivot: one column added up, with a row for each value of one column and a column for each value of another

tabular pivot [tabular sample, "region", "item", "sold"]
-- [north : [tea : 12, cake : 4], south : [tea : 7, cake : 6], east : [jam : 9]]
tabular records [names, lists]

rows made from a list of column names and lists of values

tabular records [["name", "age"], [["Ada", 36], ["Alan", 41]]]
-- [[name : Ada, age : 36], [name : Alan, age : 41]]
tabular show [rows]

the table as aligned text: a header, a rule, then a line a row, numbers lined up on the right

tabular show (tabular pick [tabular sample, ["region", "sold"]] take 2)
-- region  sold
-- ------  ----
-- north     12
-- south      7

graph

Things joined by arrows: tasks and the tasks they lead to, rooms and their doors, pages and their links. A graph is a list of edges, each [from, to], or [from, to, cost] when an edge has a cost; a node is any text or number. Find what a node leads to and what leads to it, an order to do things in, the way from one node to another, the cheapest and the longest way, and a loop when there is one.

graph nodes [edges]

every node, in the order the edges first name them

graph nodes [["a", "b"], ["b", "c"], ["a", "c"]]
-- [a, b, c]
graph next [edges, node]

the nodes one arrow on from a node

graph next [[["a", "b"], ["a", "c"], ["b", "c"]], "a"]
-- [b, c]
graph reach [edges, node]

every node a node leads to, near or far, the nearest first (the node itself only when a loop leads back to it)

graph reach [[["a", "b"], ["b", "c"], ["d", "a"]], "a"]
-- [b, c]
graph reached-by [edges, node]

every node that leads to a node, near or far, the nearest first: all it waits on

graph reached-by [[["a", "b"], ["b", "c"], ["d", "a"]], "c"]
-- [b, a, d]
graph starts [edges]

the nodes no arrow leads to: where things can begin

graph starts [["a", "b"], ["c", "b"], ["b", "d"]]
-- [a, c]
graph order [edges]

every node in an order where each comes after all the nodes that lead to it, or false when a loop makes that impossible (an order to do tasks in, to load files in, to learn skills in)

graph order [["dig", "pour"], ["pour", "frame"], ["dig", "drain"]]
-- [dig, pour, drain, frame]
graph order [["a", "b"], ["b", "a"]]
-- false
graph path [edges, from, to]

the way from one node to another in the fewest arrows, as the nodes along it, or false when there's none

graph path [[["a", "b"], ["b", "c"], ["a", "d"], ["d", "e"], ["e", "c"]], "a", "c"]
-- [a, b, c]
graph path [[["a", "b"]], "b", "a"]
-- false
graph cheapest [edges, from, to]

the cheapest way from one node to another along edges with costs: [way, total], or false when there's none

graph cheapest [[["home", "shop", 5], ["shop", "park", 2], ["home", "park", 9]], "home", "park"]
-- [way : [home, shop, park], total : 7]
graph longest [edges, weight]

the longest way through a graph with no loops, each node counting for what weight gives it: [way, total], or false when there's a loop (with each task's days as its weight, a project's critical path)

graph longest [[[1, 2], [2, 4], [1, 3], [3, 4]], [n | n]]
-- [way : [1, 3, 4], total : 8]
graph loop [edges]

a loop in the graph, as the nodes round it, or false when there's none: why there's no order

graph loop [["a", "b"], ["b", "c"], ["c", "b"], ["c", "d"]]
-- [b, c]
graph loop [["a", "b"], ["b", "c"]]
-- false

sets

Lists used as sets, where what matters is which things are in, not their order or how often. Each answer keeps the order of the first list and holds each thing once. And the ways to choose some of the things, or to order them.

sets union [a, b]

every thing in either list

sets union [[1, 2, 3], [3, 4]]
-- [1, 2, 3, 4]
sets both [a, b]

the things in both lists

sets both [[1, 2, 3], [4, 3, 2]]
-- [2, 3]
sets minus [a, b]

the things in the first list that aren't in the second

sets minus [[1, 2, 3, 2], [2]]
-- [1, 3]
sets toggle [items, thing]

the list with a thing taken out when it's in, or added when it isn't (a tag, a selected tile, a crew's members)

sets toggle [["a", "b"], "a"]
-- [b]
sets toggle [["b"], "a"]
-- [b, a]
sets inside [a, b]

is everything in the first list also in the second?

sets inside [[1, 2], [3, 2, 1]]
-- true
sets inside [[1, 4], [3, 2, 1]]
-- false
sets same [a, b]

do two lists hold the same things, in any order?

sets same [[1, 2, 2], [2, 1]]
-- true
sets picks [items, n]

every way to choose n of the things, each in the list's order (hands of cards, teams, pairs to compare)

sets picks [["a", "b", "c"], 2]
-- [[a, b], [a, c], [b, c]]
sets picks [[1, 2], 3]
-- []
sets orders [items]

every order the things can go in (for a puzzle small enough to try them all)

sets orders [1, 2, 3]
-- [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

fuzzy

Finding what someone meant from what they typed. A search matches a name when its letters appear in the name in order; matches score higher for letters side by side and at the starts of words, as a command palette or a file finder ranks them. And the closest spelling, for "did you mean?".

fuzzy score [search, name]

how well a search matches a name: 0 when its letters don't all appear in order, more for runs and word starts

fuzzy score ["sprt", "sprout"]
-- 11
fuzzy score ["xyz", "sprout"]
-- 0
fuzzy best [names, search]

the names a search matches, best first

fuzzy best [["sprout", "spirit", "sport", "parrot"], "sprt"]
-- [sprout, sport, spirit]
fuzzy matches [names, search]

the names a search matches, in their own order

fuzzy matches [["sprout", "spirit", "sport", "parrot"], "pr"]
-- [sprout, spirit, sport, parrot]
fuzzy marks [search, name]

where in a name the letters of a search were found

fuzzy marks ["sprt", "sprout"]
-- [1, 2, 3, 6]
fuzzy highlight [search, name]

a name with the letters a search matched in brackets, to show why it matched

fuzzy highlight ["sprt", "sprout"]
-- [spr]ou[t]
fuzzy closest [names, word]

the name closest in spelling to a word, for "did you mean?", or false when none is within two changes

fuzzy closest [["apple", "banana", "cherry"], "bananna"]
-- banana
fuzzy closest [["apple", "banana", "cherry"], "kiwi"]
-- false

validate

Checks on what people type, before it's used: email and web addresses, card numbers and ISBNs with their check digits, numbers, real dates, phone numbers, colour codes, IP addresses, usernames, lengths and how strong a password is. Each answers true or false, except password-gaps, which says what a password still needs.

validate email [line]

does text look like an email address?

validate email "ada@example.com"
-- true
validate email "ada@example"
-- false
validate luhn [line]

does a card number pass the Luhn check? Spaces and dashes are ignored

validate luhn "4111 1111 1111 1111"
-- true
validate luhn "4111 1111 1111 1112"
-- false
validate isbn [line]

is text an ISBN, 10 or 13 digits long, with the right check digit? Dashes and spaces are ignored

validate isbn "978-0-306-40615-7"
-- true
validate isbn "0-306-40615-2"
-- true
validate isbn "0-306-40615-3"
-- false
validate url [line]

does text look like a web address, http or https, with a host?

validate url "https://taskiap.com/sprout3/"
-- true
validate url "taskiap dot com"
-- false
validate numeric [line]

is text a number?

validate numeric "-3.14"
-- true
validate numeric "3.14.15"
-- false
validate integer [line]

is text a whole number?

validate integer "-42"
-- true
validate integer "4.2"
-- false
validate real-date [line]

is text a real date, written year-month-day?

validate real-date "2024-02-29"
-- true
validate real-date "2026-02-29"
-- false
validate phone [line]

does text look like a phone number: 8 to 15 digits, with spaces, dashes, brackets or a leading +?

validate phone "+61 412 345 678"
-- true
validate colour-code [line]

is text a colour written #rgb or #rrggbb?

validate colour-code "#ff8800"
-- true
validate colour-code "#ff88"
-- false
validate ip [line]

is text an IP address: four numbers from 0 to 255, with dots between?

validate ip "192.168.0.1"
-- true
validate ip "256.1.1.1"
-- false
validate username [line]

is text a username: 3 to 20 letters, digits or underscores, starting with a letter?

validate username "ada_99"
-- true
validate username "9lives"
-- false
validate filled [line]

is something filled in: not empty and not only spaces?

validate filled "  "
-- false
validate fits [line, bounds]

is text's length within bounds, a pair of fewest x most?

validate fits ["Ada", 3x20]
-- true
validate password-gaps [secret]

what a password still needs to be strong, in words; nothing when it's strong

validate password-gaps "hunter2"
-- [at least 12 characters, a capital letter, a symbol]
validate password-gaps "Correct-Horse-7"
-- []
validate strong [secret]

is a password strong, needing nothing more?

validate strong "Correct-Horse-7"
-- true

undo

Going back. A history is a list of earlier states, the newest first, as a puzzle, an editor or a drawing keeps them: push the state before each change, and go back one step at a time.

undo push [history, state, most]

the history with a state put on top, keeping at most most of them

undo push [[2, 1], 3, 10]
-- [3, 2, 1]
undo push [[2, 1], 3, 2]
-- [3, 2]
undo peek [history]

the state that going back would give (false when there's none)

undo peek [3, 2, 1]
-- 3
undo peek []
-- false
undo pop [history]

the history without the state on top

undo pop [3, 2, 1]
-- [2, 1]
undo can [history]

is there anything to go back to?

undo can []
-- false
undo back [history, current]

one step back from the state now: [state, history], the state now kept when there's nothing to go back to

undo back [[3, 2, 1], 9]
-- [state : 3, history : [2, 1]]
undo back [[], 9]
-- [state : 9, history : []]

csv

Tables in text, one row a line and commas between the values. The first line names the columns. Values that look like numbers become numbers. A value in double quotes can hold commas, and "" inside it is one quote, as spreadsheets write them. (A value can't run over more than one line.)

csv cell-value [t]

one value from text: a number if it looks like one

csv fields [line]

one line's values: split at the commas outside quotes, with the quotes taken off

csv fields "Ada,\"Lovelace, Countess\",36"
-- [Ada, Lovelace, Countess, 36]
csv read [csv-text]

the rows as records, named by the first line

csv read "name,age\nAda,36\nAlan,41"
-- [[name : Ada, age : 36], [name : Alan, age : 41]]
csv read "name,note\nAda,\"first, and \"\"best\"\"\""
-- [[name : Ada, note : first, and "best"]]
csv quoted [value]

one value as CSV writes it: in quotes when it holds a comma, a quote or a line break, with its quotes doubled

csv quoted "a, \"b\""
-- "a, ""b"""
csv write [records]

records as text, a line per record, with the first record's fields as the columns

csv write [[name : "Ada", age : 36], [name : "Alan", age : 41]]
-- name,age
-- Ada,36
-- Alan,41
csv write [[name : "Lovelace, Ada", age : 36]]
-- name,age
-- "Lovelace, Ada",36

json

JSON text read into records and lists, and written back. null reads as false; dates, money and other kinds are written as their text.

json read

records and lists from JSON text (put \[ for a [ inside Sprout text)

json read "{\"a\": 1, \"b\": \[true, null]}"
-- [a : 1, b : [true, false]]
json write

a value as JSON text

json write [name : "Ada", due : 2026-11-20, tags : ["x"]]
-- {"name":"Ada","due":"2026-11-20","tags":["x"]}
json pretty

the same, set out on several lines

json pretty [a : 1]
-- {
--   "a": 1
-- }

lick

Little trees of data written as an indented outline, after the data language of _why's Potion. Each line is a name and its words (a word that is a number reads as one); the lines indented under it are its kids.

lick read

an outline into a list of nodes, each [name, words, kids]

lick read "garden\n  pip 9\n  bud 2" @ 1 kids @ 2
-- [name : bud, words : [2], kids : []]
lick write

nodes back into an outline, two spaces a level

lick write (lick read "a\n  b c")
-- a
--   b c

Time and motion

ease

Easing curves for animation. Each takes t, from 0 to 1, and gives a value that starts at 0 and ends at 1. Use one to move something smoothly: x : ease out-cubic (motion progress [2, elapsed]) * 300, or motion tween.

ease linear [t]

straight along, at one speed

ease linear 0.25
-- 0.25
ease in-quad [t]

starts slow, speeds up

ease in-quad 0.5
-- 0.25
ease out-quad [t]

starts fast, slows down

ease out-quad 0.5
-- 0.75
ease in-out-quad [t]

slow at both ends

ease in-out-quad 0.25
-- 0.125
ease in-cubic [t]

starts slower still

ease in-cubic 0.5
-- 0.125
ease out-cubic [t]

arrives gently: the usual choice for things that slide into place

ease out-cubic 0.5
-- 0.875
ease in-out-cubic [t]

slow at both ends, more so than in-out-quad

ease in-out-cubic 0.75
-- 0.9375
ease out-back [t]

goes a little past the end, then settles back

ease out-back 0.8
-- 1.04645056
ease out-elastic [t]

springs past the end and wobbles to a stop

ease out-elastic 0.3
-- 0.875
ease out-bounce [t]

bounces like a dropped ball

ease out-bounce 0.9
-- 0.988125
ease smooth [t]

a soft S-curve, slow at both ends

ease smooth 0.25
-- 0.15625
ease ping-pong [t]

t from 0 to 1 and back again, for things that go to and fro

ease ping-pong 1.25
-- 0.75

motion

How things move and how a game feels: how far through something is, tweens, glides, shake, bobbing, gravity and bounces. A body is [at, speed], both pairs (where it is, and how far it goes a second). Each word works from the time or the step, so a game can rewind and replay. Distilled from the TaskIAP games: 112 of the 319 ease things about, 57 have gravity, 55 shake the screen.

motion progress [length, elapsed]

how far through something length seconds long is, from 0 to 1, elapsed seconds in

motion progress [2, 1.5]
-- 0.75
motion tween [a, b, start, length, curve, now]

a value (or a point) going from a to b over length seconds from start, shaped by an easing curve: where it is at now

motion tween [0, 100, 1, 2, ease out-quad, 1.5]
-- 43.75
motion tween [0x0, 10x20, 0, 2, ease linear, 1]
-- 5x10
motion approach [value, target, rate, dt]

a value stepped toward target by at most rate a second, never past it

motion approach [0, 10, 4, 0.5]
-- 2
motion glide [value, target, share, dt]

a value (or a point) gliding toward target, closing share of the gap every second, whatever the frame rate: for cameras and health bars

motion glide [0, 100, 0.9, 0.1] round
-- 21
vec round (motion glide [0x0, 100x50, 0.9, 0.1])
-- 21x10
motion shake [trauma, most, now]

screen shake from trauma (0 to 1): an offset of up to most pixels at time now, smooth rather than jittery

vec round (motion shake [0.5, 12, 3.2])
-- 0x-2
motion calm [trauma, rate, dt]

trauma after dt seconds, falling away at rate a second

motion calm [0.8, 1.5, 0.2]
-- 0.5
motion bob [height, per-second, now]

a gentle up and down of height, per-second times a second (pickups, idle characters, menus): the offset at now

motion bob [0.1, 1, 0.25]
-- 0.1
motion pulse [per-second, now]

a beat between 0 and 1, per-second times a second (blinking, glowing)

motion pulse [1, 0.25]
-- 1
motion fall [body, g, dt]

a body after falling for dt seconds under gravity g (down is y growing)

motion fall [[at : 0x0, speed : 2x0], 10, 0.5]
-- [at : 1x2.5, speed : 2x5]
motion bounce [body, size, bounciness]

a body kept inside a box of size, bouncing off its walls and keeping bounciness (0 to 1) of its speed

motion bounce [[at : 12x5, speed : 3x0], 10x10, 0.8]
-- [at : 10x5, speed : -2.4x0]
motion drag [speed, share, dt]

a speed after dt seconds of friction, keeping share of itself every second

motion drag [10, 0.5, 1]
-- 5
motion jump-speed [height, g]

how fast to jump to rise to height under gravity g

motion jump-speed [2, 9.8] round
-- 6

arc

Things thrown through the air, a ball at a hoop, a grenade, a leaping frog: where one is along its flight from one point to another, how far through the flight it is, the speed to throw at to land on a spot, and where a thing already flying comes down. Points are pairs, y counts down the screen, and gravity pulls down (a number above 0).

arc point [origin, target, height, t]

where a thing is at fraction t (0 to 1) of its flight from origin to target, rising height above the straight line at the middle

arc point [0x100, 100x100, 40, 0.5]
-- 50x60
arc point [0x100, 100x50, 40, 1]
-- 100x50
arc progress [span, began, now]

how far through a flight of some length it is now, from when it began: 0 before, 1 once it has landed

arc progress [0.8, 2, 2.4]
-- 0.5
arc progress [0.8, 2, 5]
-- 1
arc launch [origin, target, height, gravity]

the speed to throw at, across and up, to land on a target from origin, rising height above origin, under gravity

arc launch [0x100, 80x100, 100, 200]
-- 40x-200
arc landing [origin, speed, gravity, ground]

where a thing thrown from origin at a speed comes back down to the ground (a height on the screen), to run to where a loose ball will land

arc landing [0x100, 40x-200, 200, 100]
-- 80x100

platform

How the hero of a platform game runs and jumps, the way the good ones feel: speeding up and slowing down, gravity with a top falling speed, a jump cut short when the button is let go, a jump still allowed a moment after running off a ledge (coyote time), and a press a moment before landing still counting (the jump buffer). step does a whole frame of it through tilemap move, which keeps the hero out of the walls. Distilled from Sprig and Headstrong.

platform run [speed-x, way, top, accel, brake, dt]

the speed across after a frame of running one way (-1, 0 or 1): speeding up by accel toward top, else slowing by brake

platform run [0, 1, 100, 800, 1000, 0.1]
-- 80
platform run [90, 0, 100, 800, 1000, 0.05]
-- 40
platform run [95, 1, 100, 800, 1000, 0.1]
-- 100
platform fall [speed-y, holding, pull, cut, top, dt]

the speed down after a frame of falling: gravity pulls, a rise is cut to cut when the button isn't held, and it never falls faster than top (up is minus)

platform fall [-300, true, 900, -110, 270, 0.1]
-- -210
platform fall [-300, false, 900, -110, 270, 0.1]
-- -20
platform fall [250, true, 900, -110, 270, 0.1]
-- 270
platform coyote [left-over, grounded, span, dt]

coyote time: how long a jump is still allowed after leaving the ground, full again while standing on it

platform coyote [0.05, false, 0.08, 0.02]
-- 0.03
platform coyote [0, true, 0.08, 0.02]
-- 0.08
platform buffer [left-over, pressed-now, span, dt]

the jump buffer: how long a press of jump is remembered, so pressing just before landing still jumps

platform buffer [0, true, 0.12, 0.02]
-- 0.12
platform buffer [0.1, false, 0.12, 0.02]
-- 0.08
platform jumps [coyote-left, buffer-left]

does the hero jump now: a press remembered while the ground is under foot, or only just left

platform jumps [0.05, 0.1]
-- true
platform jumps [0, 0.1]
-- false
platform feel

how a hero feels, to change with with: its box, the map's tile and which characters are solid or one-way, running (top speed, speeding up on the ground and in the air, braking), jumping (speed, gravity, the cut, the top fall speed) and the two windows

platform feel jump
-- 340
platform step [hero, way, pressed-now, holding, map, how, dt]

a hero for one frame: running one way (-1, 0 or 1), jumping when jump was pressed (held for higher), falling, and moved through the map; gives the hero with at, speed, ground, coyote-left, buffer-left and jumped (did it jump now?)

platform step [[at : 0x2, speed : 0x0, ground : true, coyote-left : 0.08, buffer-left : 0], 0, true, true, ["....", "####"], platform feel, 0.02] jumped
-- true
platform step [[at : 0x2, speed : 0x0, ground : true, coyote-left : 0.08, buffer-left : 0], 1, false, false, ["....", "####"], platform feel, 0.1] speed
-- 80x0

spring

Things that move like they're on a spring: they overshoot, wobble and settle, which makes buttons, cameras and characters feel alive. A spring's state is [at, speed]; at and target can be numbers or pairs. Step it each frame with the time that passed.

spring step [state, target, stiffness, damping, dt]

a spring's state after dt seconds pulled toward target: stiffness pulls harder, damping calms it

spring step [[at : 0, speed : 0], 10, 100, 10, 0.01]
-- [at : 0.1, speed : 10]
spring step [[at : 0x0, speed : 0x0], 10x0, 100, 10, 0.01]
-- [at : 0.1x0, speed : 10x0]
spring follow [state, target, smooth-time, dt]

a state after dt seconds closing on target as fast as it can without overshooting, taking about smooth-time seconds (a critically damped spring, for cameras and pointers)

spring follow [[at : 0, speed : 0], 10, 0.5, 0.1] at * 100 round / 100
-- 0.62
spring resting [state, target, tolerance]

has a spring come to rest: near its target and hardly moving?

spring resting [[at : 9.99, speed : 0.01], 10, 0.05]
-- true
spring critical [stiffness]

the damping that settles a spring of this stiffness fastest without a wobble

spring critical 100
-- 20
spring wobble [amplitude, frequency, decay, t]

a wobble that dies away: amplitude at the start, frequency times a second, fading at decay a second, t seconds in

spring wobble [1, 2, 3, 0.125]
-- 0.6872892788
spring stretch [speed, most]

squash and stretch from speed: narrower and taller the faster something moves, up to 30%, as a scale across x down

spring stretch [-300, 600]
-- 0.85x1.15

keyframes

Values set at moments, and everything between worked out: the timelines of cutscenes, title screens, moving platforms and lighting. Keys are [time, value] pairs in time order; values can be numbers or pairs, or any value for held and crossed.

keyframes at [track, t]

the value at time t, straight between track, held before the first and after the last

keyframes at [[[0, 0], [1, 10], [3, 50]], 2]
-- 30
keyframes at [[[0, 0x0], [2, 10x20]], 1]
-- 5x10
keyframes eased [track, curve, t]

the value at time t, shaped between track by an easing curve

keyframes eased [[[0, 0], [1, 100]], ease in-quad, 0.5]
-- 25
keyframes duration [track]

the time of the last key

keyframes duration [[0, 0], [1, 10], [3, 50]]
-- 3
keyframes looped [track, t]

the value at time t, starting over at the end

keyframes looped [[[0, 0], [2, 10]], 3]
-- 5
keyframes ping-pong [track, t]

the value at time t, playing forward then back

keyframes ping-pong [[[0, 0], [2, 10]], 3]
-- 5
keyframes held [track, t]

the value of the last key at or before time t, with nothing between (states, sprites, lines of text)

keyframes held [[[0, "idle"], [1, "run"], [2, "jump"]], 1.5]
-- run
keyframes crossed [track, from, to]

the values of track passed from one time to another, for sounds and events on a timeline

keyframes crossed [[[1, "boom"], [2, "flash"]], 0.9, 1.5]
-- [boom]

flipbook

Animation by frames, as sprites flick through a sheet of pictures: which frame shows now, looping, once, back and forth, where a frame sits in a sprite sheet, which way to face and which row of a sheet to use for a direction. Frames count from 1.

flipbook frame [count, fps, now]

the frame showing now, looping through count frames at fps a second

flipbook frame [8, 12, 1.25]
-- 8
flipbook once [count, fps, start, now]

the frame showing now when played once from start, then held on the last

flipbook once [5, 10, 2, 2.35]
-- 4
flipbook done [count, fps, start, now]

has playing once from start finished?

flipbook done [5, 10, 2, 2.6]
-- true
flipbook swing [count, fps, now]

the frame showing now, playing forward then back (1, 2, 3, 4, 3, 2, 1, ...)

range 8 collect [k | flipbook swing [4, 1, k - 1]]
-- [1, 2, 3, 4, 3, 2, 1, 2]
flipbook pick [frames, fps, now]

the frame showing now from a list of frames

flipbook pick [["walk1", "walk2", "walk3"], 8, 0.5]
-- walk2
flipbook sheet-cell [index, columns]

where a frame sits on a sprite sheet with some columns, across x down

flipbook sheet-cell [7, 4]
-- 3x2
flipbook sheet-rect [index, columns, frame-size]

the box a frame takes on a sprite sheet, [at, size]

flipbook sheet-rect [7, 4, 32x32]
-- [at : 64x32, size : 32x32]
flipbook facing [speed-x, was]

which way to face from speed across: 1 right, -1 left, and the way it was when standing still

flipbook facing [-40, 1]
-- -1
flipbook direction [angle, n]

which of n directions an angle points (1 is right, then clockwise on screen), to pick a row of a sheet

flipbook direction [pi / 2, 4]
-- 2

steer

Steering for things that move by themselves: chasing, fleeing, arriving gently, heading off a target, wandering, and the three rules of a flock (keep apart, line up, stay together). A body is [at, speed], both pairs, as in motion. Each word gives a push to add to speed; apply adds it.

steer seek [body, target, top]

the push toward a target at up to top speed

steer seek [[at : 0x0, speed : 0x0], 10x0, 5]
-- 5x0
steer flee [body, threat, top]

the push away from a threat

steer flee [[at : 0x0, speed : 0x0], 10x0, 5]
-- -5x0
steer arrive [body, target, top, slow]

the push toward a target that slows down within slow of it, to stop there

steer arrive [[at : 0x0, speed : 0x0], 5x0, 10, 20]
-- 2.5x0
steer pursue [body, quarry, top]

the push toward where a moving quarry will be

vec round (steer pursue [[at : 0x0, speed : 0x0], [at : 10x0, speed : 0x5], 10])
-- 9x4
steer wander [body, top, now, seed]

a push that drifts this way and that over time, for things that wander

vec round (steer wander [[at : 0x0, speed : 0x0], 10, 0, 7])
-- 3x10
steer separate [body, others, radius]

the push away from others closer than radius, stronger the closer they are

steer separate [[at : 0x0, speed : 0x0], [[at : 2x0, speed : 0x0]], 5]
-- -0.5x0
steer align [body, others, radius]

the push to match the speed of others within radius

steer align [[at : 0x0, speed : 0x0], [[at : 2x0, speed : 4x0]], 5]
-- 4x0
steer cohere [body, others, radius, top]

the push toward the middle of others within radius

vec round (steer cohere [[at : 0x0, speed : 0x0], [[at : 4x0, speed : 0x0], [at : 0x4, speed : 0x0]], 5, 10])
-- 7x7
steer flock [body, others, radius, top]

the three flocking pushes together: keep apart, line up, stay together

vec round (steer flock [[at : 0x0, speed : 0x0], [[at : 2x0, speed : 0x4]], 5, 10])
-- 3x4
steer apply [body, push, most, dt]

a body after dt seconds of a push, its speed kept under most

steer apply [[at : 0x0, speed : 0x0], 10x0, 5, 0.5]
-- [at : 2.5x0, speed : 5x0]

daytime

Time in a game world: the hour, day and night, the light and sky, weekdays, seasons, and the stages things grow through. Distilled from the TaskIAP games: 59 of the 319 have days and nights or weather, 30 seasons, 18 crops.

daytime hour [day-length, start-hour, now]

the hour (0 up to 24) at now seconds, when a day lasts day-length seconds and starts at start-hour

daytime hour [120, 6, 90]
-- 0
daytime part [h]

the part of the day an hour falls in: night, dawn, day or dusk

daytime part 18.5
-- dusk
daytime light [h]

how light it is at an hour, from 0 at night to 1 by day, rising through dawn and falling through dusk

daytime light 6
-- 0.5
daytime sky [h]

the sky's colour at an hour: deep blue at night, orange at dawn and dusk, blue by day

daytime sky 12
-- #6fa8e8
daytime season [day, length]

the season of a day (day 1 the first of spring), seasons lasting length days

daytime season [40, 28]
-- summer
daytime weekday [day]

the weekday of a day (day 1 a Monday)

daytime weekday 10
-- Wed
daytime stage [planted, lengths, now]

which stage something has reached, planted at planted, when its stages last lengths seconds each: 1 at first, one more than the number of stages once it's ready (a crop, a building, a cake in the oven)

daytime stage [0, [10, 10, 10], 25]
-- 3
daytime grown [planted, lengths, now]

has it grown through all its stages?

daytime grown [0, [10, 10, 10], 25]
-- false

Touch and sound

pad

The buttons of a handheld as a game reads them: which way the arrows point, and whether a button is in. The buttons are a record like the frame's input held, pressed and released (decision 121): [left : true, one : true]. Read held buttons to walk and pressed ones to step through a menu, so that one press moves one place.

pad way [buttons]

which way the arrows point, as a pair across and down

pad way [left : true, down : true]
-- -1x1
pad way [one : true]
-- 0x0
pad across [buttons]

the arrows across alone: -1, 0 or 1, for a game that only goes left and right

pad across [right : true]
-- 1
pad upward [buttons]

the arrows up and down alone: -1 up, 1 down

pad upward [up : true]
-- -1
pad either [buttons]

is button one or button two in? ("press 1 or 2")

pad either [two : true]
-- true
pad either [left : true]
-- false
pad any-in [buttons]

is any button or arrow in at all?

pad any-in []
-- false

focus

Boxes on a screen that a finger taps or the arrows move between, so a menu, a shop or a board works by touch and by keys alike. A box is a record with at (its top left) and size, both pairs; places count from 1.

focus hit [boxes, point]

the place of the first box that holds a point, 0 when none does

focus hit [[[at : 0x0, size : 10x10], [at : 20x0, size : 10x10]], 25x5]
-- 2
focus hit [[[at : 0x0, size : 10x10]], 50x50]
-- 0
focus middle [box]

the middle of a box

focus middle [at : 10x20, size : 10x4]
-- 15x22
focus step [boxes, place, way]

the place moved by a step of the arrows: across goes to the next box or the one before, round the ends; up and down go to the nearest box above or below, staying put when there is none

focus step [[[at : 0x0, size : 10x10], [at : 20x0, size : 10x10], [at : 0x30, size : 10x10]], 1, 1x0]
-- 2
focus step [[[at : 0x0, size : 10x10], [at : 20x0, size : 10x10], [at : 0x30, size : 10x10]], 2, 0x1]
-- 3
focus step [[[at : 0x0, size : 10x10], [at : 0x30, size : 10x10]], 1, pair [0, -1]]
-- 1
focus step [[[at : 0x0, size : 10x10], [at : 20x0, size : 10x10]], 1, pair [-1, 0]]
-- 2
focus ring [boxes, place, grow]

the box drawn round a place, a little bigger, for a cursor

focus ring [[[at : 10x10, size : 20x10]], 1, 2]
-- [at : 8x8, size : 24x14]

gesture

Reading fingers and sticks: swipes, taps, long presses and double taps, pinches and twists, flicks, a stick's direction and its dead zone. Points are pairs on screen, across x down (y grows downward).

gesture swipe [from, to, least]

the way a finger swiped from one point to another, "left", "right", "up" or "down", or false when it moved less than least

gesture swipe [100x100, 40x110, 30]
-- left
gesture swipe [100x100, 105x90, 30]
-- false
gesture stick-direction [v, dead]

which of eight ways a stick points, or false inside the dead zone

gesture stick-direction [0.7x-0.7, 0.2]
-- up-right
gesture dead-zone [v, dead]

a stick's push with a dead zone in the middle, so a resting thumb doesn't drift, growing smoothly from the edge of it to 1

gesture dead-zone [0.6x0, 0.2]
-- 0.5x0
gesture tap [moved, held]

was a touch a tap: held briefly without moving far?

gesture tap [3, 0.12]
-- true
gesture long-press [moved, held]

was a touch a long press: held still for half a second or more?

gesture long-press [4, 0.8]
-- true
gesture double-tap [last-tap, now]

is a tap now the second of a double tap?

gesture double-tap [10.1, 10.32]
-- true
gesture pinch [before, after]

how much two fingers pinched: the new gap between them over the old one (above 1 spreads apart)

gesture pinch [[0x0, 100x0], [0x0, 150x0]]
-- 1.5
gesture twist [before, after]

how far two fingers turned, in radians

gesture twist [[0x0, 100x0], [0x0, 0x100]]
-- 1.5707963268
gesture flick [from, to, seconds]

the speed of a flick, from where a finger was to where it let go, over the seconds between

gesture flick [0x0, 30x-12, 0.1]
-- 300x-120

music

Notes, scales and chords, and keeping time: the frequency of a note for beep, notes by name ("C4", "F#3", "Bb5") or by MIDI number (A4 is 69), scales and chords from a root, transposing, and beats, bars and snapping times to the beat.

music midi [note]

the MIDI number of a note name

music midi "A4"
-- 69
music midi "C#4"
-- 61
music name-of [m]

the name of a MIDI number, with sharps

music name-of 61
-- C#4
music frequency [note]

the frequency of a note, by name or MIDI number, in hertz (for beep)

music frequency "A4"
-- 440
music frequency "C4"
-- 261.6255653006
music frequency 81
-- 880
music scale [root, kind]

the notes of a scale from a root: major, minor, pentatonic, minor-pentatonic, blues or chromatic

music scale ["C4", "major"]
-- [C4, D4, E4, F4, G4, A4, B4]
music scale ["A3", "minor-pentatonic"]
-- [A3, C4, D4, E4, G4]
music chord [root, kind]

the notes of a chord from a root: major, minor, seventh, major-seventh, minor-seventh, diminished, augmented or sus4

music chord ["G3", "seventh"]
-- [G3, B3, D4, F4]
music transpose [note, steps]

a note moved up (or down) some semitones

music transpose ["E4", 3]
-- G4
music interval [a, b]

how many semitones from one note up to another

music interval ["C4", "G4"]
-- 7
music beat [bpm]

how long one beat lasts at a tempo, in seconds

music beat 120
-- 0.5
music beat-at [bpm, now]

which beat it is now, counting from 1

music beat-at [120, 2.6]
-- 6
music bar-beat [bpm, per-bar, now]

which bar and which beat in it it is now, as bar x beat

music bar-beat [120, 4, 2.6]
-- 2x2
music quantize [time, bpm, division]

a time snapped to the nearest step of a beat cut into division parts

music quantize [1.13, 120, 4]
-- 1.125
music track [line, step]

a line of music written as text turned into notes. Each word is one step of step beats: a note name ("E5"), "-" holding the note before for another step, "." a rest, or another word (a drum, such as "kick") kept as it is; "|" between bars is skipped. Gives [beat, note, beats] for each note, the note as a MIDI number

music track ["C4 - E4 . | kick", 0.5]
-- [[0, 60, 1], [1, 64, 0.5], [2, kick, 0.5]]
music melody [notes, bpm]

notes one beat apart as [time, frequency], ready to play with beep

music melody [["A4", "A5"], 120]
-- [[0, 440], [0.5, 880]]

Space

vec

Two-dimensional vectors, written as pairs like 3x4. Pairs already add, take away, multiply and divide. These are the other things a game needs: length, direction, angle, rotation.

vec of [x, y]

a vector from two numbers

vec of [3, 4]
-- 3x4
vec from-angle [angle]

a vector one long, pointing at an angle (in radians)

vec from-angle 0
-- 1x0
vec size [v]

how long a vector is

vec size 3x4
-- 5
vec unit [v]

the same direction, one long

vec unit 3x4
-- 0.6x0.8
vec angle [v]

the angle a vector points at, in radians

vec angle 0x1
-- 1.5707963268
vec rotate [v, turn]

turned round by an angle, in radians

vec rotate [1x0, 1.5707963267948966]
-- 0x1
vec dot [a, b]

how much two vectors point the same way

vec dot [1x0, 0x1]
-- 0
vec distance [a, b]

the distance between two points

vec distance [0x0, 3x4]
-- 5
vec mix [a, b, t]

part of the way from a to b: t of 0 is a, 1 is b

vec mix [0x0, 10x20, 0.5]
-- 5x10
vec limit [v, most]

no longer than most, in the same direction

vec limit [30x40, 5]
-- 3x4
vec reflect [v, n]

bounced off a surface facing the way of n (n one long)

vec reflect [1x-1, 0x1]
-- 1x1
vec perpendicular [v]

turned a quarter to the left

vec perpendicular 1x0
-- 0x1
vec round [v]

a vector with both parts rounded (for a point on screen, or a cell)

vec round 1.4x2.6
-- 1x3
vec toward [from, to, step]

a point moved toward another by at most step, never past it

vec toward [0x0, 10x0, 4]
-- 4x0
vec aim [from, to, speed]

the velocity that heads from one point to another at speed (a shot aimed at a player)

vec aim [0x0, 3x4, 10]
-- 6x8
vec fan [v, n, spread]

n copies of a velocity fanned out across an angle (radians), for a spread of shots

vec fan [10x0, 3, pi] collect [v | vec round v]
-- [0x-10, 10x0, 0x10]
vec wrap-angle [turn]

an angle (radians) brought round to between -pi and pi, so two headings can be compared

vec wrap-angle 7
-- 0.7168146928
vec angle-gap [from, to]

the shortest turn from one heading to another, in radians from -pi to pi

vec angle-gap [3, -3]
-- 0.2831853072
vec turn-toward [from, to, step]

a heading turned toward another by at most step, the short way round (a turret tracking, a ship steering)

vec turn-toward [0, 2, 0.5]
-- 0.5
vec turn-toward [3, -3, 0.5]
-- 3.2831853072

shape

The points of shapes, as lists of pairs, ready to draw or test. Nothing here draws: draw a shape's edges with line, as in shape edges (shape polygon [180x240, 50, 6]) each [[a, b] | line [a x, a y, b x, b y, "#fff"]]

shape circle [c, r, n]

n points evenly round a circle at centre c (a pair) with radius r

shape circle [0x0, 10, 4] collect [p | p x round]
-- [10, 0, -10, 0]
shape polygon [c, r, sides]

a regular polygon with n sides, its first corner straight up

shape polygon [0x0, 10, 3] length
-- 3
shape star [c, outer, inner, n]

a star with n points, between radius outer and inner

shape star [0x0, 10, 5, 5] length
-- 10
shape box [corner, size]

the four corners of a box from its top-left corner and its size (both pairs)

shape box [0x0, 4x2]
-- [0x0, 4x0, 4x2, 0x2]
shape edges [points]

the sides of a closed shape: each point with the next, the last with the first, as [a, b]

shape edges [0x0, 1x0, 0x1] length
-- 3
shape move [points, by]

the shape moved by a pair

shape move [[0x0, 1x1], 5x5]
-- [5x5, 6x6]
shape turn [points, c, angle]

the shape turned round centre c by an angle in radians

shape turn [[1x0], 0x0, 3.141592653589793] collect [p | p x round]
-- [-1]
shape grow [points, c, times-bigger]

the shape grown or shrunk round centre c

shape grow [[2x2], 1x1, 3]
-- [4x4]
shape area [points]

the area inside a closed shape

shape area (shape box [0x0, 4x2])
-- 8
shape centre [points]

the middle of the points

shape centre (shape box [0x0, 4x2])
-- 2x1
shape bounds [points]

the smallest box round the points, as [top-left, bottom-right]

shape bounds [3x1, 0x4, 2x2]
-- [0x1, 3x4]
shape holds [points, p]

is point p inside the closed shape?

shape holds [shape box [0x0, 4x2], 1x1]
-- true

segment

Straight lines between two points, a segment written [from, to] with both ends pairs: how long, the middle, the nearest point to something, where two segments cross, which side a point is on. For lasers, walls, line of sight, cutting and ropes.

segment size [seg]

how long a segment is

segment size [0x0, 3x4]
-- 5
segment middle [seg]

the middle of a segment

segment middle [0x0, 4x2]
-- 2x1
segment along [seg, t]

the point a share t of the way along a segment

segment along [[0x0, 10x0], 0.25]
-- 2.5x0
segment closest [seg, p]

the point on a segment nearest to p

segment closest [[0x0, 10x0], 3x5]
-- 3x0
segment closest [[0x0, 10x0], pair [-4, 2]]
-- 0x0
segment distance-to [seg, p]

how far p is from a segment

segment distance-to [[0x0, 10x0], 3x5]
-- 5
segment cross [one, two]

where two segments cross, or false if they don't

segment cross [[0x0, 4x4], [0x4, 4x0]]
-- 2x2
segment cross [[0x0, 1x1], [2x0, 3x1]]
-- false
segment crosses [one, two]

do two segments cross?

segment crosses [[0x0, 4x4], [0x4, 4x0]]
-- true
segment side [seg, p]

which side of a segment's line p is on: 1 one way, -1 the other, 0 on the line

segment side [[0x0, 10x0], 5x5]
-- 1
segment side [[0x0, 10x0], 5x0]
-- 0
segment angle [seg]

the direction a segment points, as an angle in radians

segment angle [0x0, 0x5]
-- 1.5707963268
segment normal [seg]

a segment's normal: one long, square to it

segment normal [0x0, 10x0]
-- 0x1
segment points [seg, n]

n + 1 points evenly along a segment, both ends included

segment points [[0x0, 10x0], 2]
-- [0x0, 5x0, 10x0]

spline

Curves from points: Bézier curves pulled toward their control points, smooth curves through every point, and paths of straight legs, with how long a path is, where you are a distance along it and which way you face. For enemies on rails, camera moves, roads and drawing. Points are pairs.

spline bezier [points, t]

the point t of the way along a Bézier curve (any number of control points)

spline bezier [[0x0, 5x10, 10x0], 0.5]
-- 5x5
spline through [points, t]

the point t of the way along a smooth curve through every point (Catmull-Rom)

spline through [[0x0, 10x10, 20x0], 0.5]
-- 10x10
vec round (spline through [[0x0, 10x10, 20x0], 0.25])
-- 4x6
spline path-length [points]

how long a path of straight legs is

spline path-length [0x0, 3x4, 3x10]
-- 11
spline at-distance [points, d]

the point d along a path of straight legs (the end, past its length)

spline at-distance [[0x0, 10x0, 10x10], 15]
-- 10x5
spline heading [points, d]

which way a path faces d along it, as an angle in radians

spline heading [[0x0, 10x0, 10x10], 15]
-- 1.5707963268
spline nearest-point [points, p]

the point on a path nearest to p

spline nearest-point [[0x0, 10x0, 10x10], 12x4]
-- 10x4
spline curve [points, n]

n + 1 points along a Bézier curve, for drawing it

spline curve [[0x0, 5x10, 10x0], 2]
-- [0x0, 5x5, 10x0]
spline smooth [points, n]

n + 1 points along a smooth curve through every point, for drawing it

spline smooth [[0x0, 10x10, 20x0], 4] length
-- 5
spline simplify [points, tolerance]

a path with the points that hardly change its shape taken out (Ramer-Douglas-Peucker), none moving it more than tolerance

spline simplify [[0x0, 1x0.1, 2x0, 3x0.1, 4x0], 0.5]
-- [0x0, 4x0]
spline simplify [[0x0, 1x0, 2x0, 2x1, 2x2], 0.1]
-- [0x0, 2x0, 2x2]

collide

Does this touch that? A point is a pair; a box is [at, size] (at its top-left corner) and a circle [at, r] (at its centre). Distilled from the TaskIAP games: 30 of the 319 test what runs into what, and a tap on a button is the same question.

collide boxes [a, b]

do two boxes overlap?

collide boxes [[at : 0x0, size : 10x10], [at : 5x5, size : 10x10]]
-- true
collide circles [a, b]

do two circles overlap?

collide circles [[at : 0x0, r : 5], [at : 8x0, r : 5]]
-- true
collide in-box [p, b]

is a point inside a box? (a tap on a button)

collide in-box [3x4, [at : 0x0, size : 10x10]]
-- true
collide in-circle [p, c]

is a point inside a circle?

collide in-circle [3x4, [at : 0x0, r : 5]]
-- false
collide circle-box [c, b]

does a circle touch a box? (a ball and a brick)

collide circle-box [[at : 12x5, r : 3], [at : 0x0, size : 10x10]]
-- true
collide wrap-around [p, size]

a point gone off one edge of a screen of size, back on the other

collide wrap-around [pair [105, -3], 100x100]
-- 5x97

grid

Boards of cells: a list of rows, each a list of cells, and a cell found by a pair, across x down (1x1 is the top left). Read and change cells, find neighbours, regions and the shortest way through; and the moves of board and puzzle games: rows of three, pieces falling into gaps, 2048 slides, straight lines and what can be seen from where. An empty cell is false. Distilled from the TaskIAP games: 96 of the 319 are played on tiles, 53 match or merge them.

grid make [size, value]

a grid of size (across x down) with every cell holding value

grid make [3x2, 0]
-- [[0, 0, 0], [0, 0, 0]]
grid size [g]

how big a grid is, across x down

grid size [[1, 2, 3], [4, 5, 6]]
-- 3x2
grid inside [g, c]

is a cell on the grid?

grid inside [grid make [3x2, 0], 3x3]
-- false
grid at [g, c]

what's in a cell (false off the grid)

grid at [[[1, 2], [3, 4]], 2x1]
-- 2
grid put [g, c, value]

the grid with one cell changed

grid put [grid make [3x2, 0], 2x1, 9]
-- [[0, 9, 0], [0, 0, 0]]
grid beside [g, c]

the four cells beside one (above, right, below, left) that are on the grid

grid beside [grid make [3x3, 0], 1x1]
-- [2x1, 1x2]
grid around [g, c]

the eight cells round one that are on the grid

grid around [grid make [3x3, 0], 2x2] length
-- 8
grid count-around [g, c, value]

how many of the eight cells round one hold value (Life, minesweeper)

grid count-around [[[1, 1, 0], [0, 0, 0], [0, 1, 1]], 2x2, 1]
-- 4
grid cells [g]

every cell with where it is, as [cell, value]

grid cells [[1, 2], [3, 4]]
-- [[1x1, 1], [2x1, 2], [1x2, 3], [2x2, 4]]
grid map [g, change]

a new grid made by a cell given each cell and its value

grid map [[[1, 2], [3, 4]], [c v | v * 10]]
-- [[10, 20], [30, 40]]
grid region [g, c]

the cells joined to one through cells of the same value

grid region [[[1, 1, 0], [0, 1, 0], [0, 1, 1]], 1x1] length
-- 5
grid fill [g, c, value]

the grid with the region at a cell changed to value (flood fill)

grid fill [[[1, 1, 0], [0, 1, 0]], 1x1, 7]
-- [[7, 7, 0], [0, 7, 0]]
grid path [g, from, to, open]

the shortest way from one cell to another, stepping only on cells whose value passes open (false if there's none)

grid path [[[0, 0, 0], [1, 1, 0], [0, 0, 0]], 1x1, 1x3, [v | v = 0]] length
-- 7
grid show [g]

the grid as lines of text, one a row

grid show [[1, 2], [3, 4]]
-- 1 2
-- 3 4
grid runs [g]

the cells in runs of three or more alike, across or down (match-three)

grid runs [[1, 1, 1, 2], [3, 2, 3, 2], [3, 2, 1, 2]] length
-- 6
grid fall [g]

the grid with its pieces fallen into the gaps below them, the gaps risen to the top

grid fall [[1, 2], [false, 3], [4, false]]
-- [[false, false], [1, 2], [4, 3]]
grid slide [row]

a row slid toward its start, 2048-style: alike neighbours merge, each only once; [row, points], points being what the merges made

grid slide [2, 2, 4, false]
-- [row : [4, 4, false, false], points : 4]
grid turn [g]

the grid turned a quarter clockwise (turn, slide, turn back: a slide any way)

grid turn [[1, 2], [3, 4]]
-- [[3, 1], [4, 2]]
grid ray [from, to]

the cells on the straight line from one cell to another, both ends included (aiming, beams, line of sight)

grid ray [1x1, 4x2]
-- [1x1, 2x1, 3x2, 4x2]
grid sees [g, from, to, wall]

can one cell be seen from another, with no wall on a cell between?

grid sees [[[0, 0, 0], [0, 1, 0], [0, 0, 0]], 1x2, 3x2, 1]
-- false
grid seen [g, from, r, wall]

the cells within r of one that can be seen from it (fog of war lifting round a player)

grid seen [grid make [5x5, 0], 3x3, 1, 1] length
-- 5
grid next-step [g, from, to, open]

the next cell on the shortest way from one cell to another through cells whose value passes open (the cell itself when it's there, or when there's no way): one step for a chaser

grid next-step [[[0, 0, 0], [1, 1, 0], [0, 0, 0]], 1x1, 1x3, [v | v = 0]]
-- 2x1
grid away-step [g, from, threat, open]

the open cell beside one that is farthest from a threat, in a straight line (the cell itself when none is open): one step for something fleeing

grid away-step [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], 2x2, 1x1, [v | v = 0]]
-- 3x2

automata

Worlds of cells that all change at once by simple rules: Life and its cousins, caves grown from noise, and the one-row patterns of rule 30 and rule 90. A world is a grid, a list of rows, of true (alive, or rock) and false.

automata step [world, born, stay]

the next turn of a world: an empty cell comes alive when its count of live neighbours is in born, and a live one lives on when its count is in stay (Life is born [3], stay [2, 3]); beyond the edge counts as empty

automata step [[[false, true, false], [false, true, false], [false, true, false]], [3], [2, 3]]
-- [[false, false, false], [true, true, true], [false, false, false]]
automata caves [size, fill, turns, seed]

a cave map of size grown from noise: each cell starts as rock (true) by the chance fill, then each turn a cell is rock when 5 of the 8 round it are rock (4 if it is rock already); beyond the edge counts as rock, and the border stays rock (the caves of a roguelike)

automata caves [10x7, 0.42, 2, 7] collect [cells | cells collect [rock | rock ["#"] else ["."]] join ""]
-- [##########, ###.....##, ##......##, ##......##, ##......##, ##.###..##, ##########]
automata next-row [cells, rule]

the next row of a one-row world by an elementary rule from 0 to 255: each cell looks at itself and the cells either side (beyond the ends counts as empty); rule 90 draws Sierpinski's triangle, and rule 30 looks random

automata next-row [[false, false, true, false, false], 90]
-- [false, true, false, true, false]
automata next-row [[false, false, true, false, false], 30]
-- [false, true, true, true, false]

tilemap

Levels drawn as text, a character a tile, as platform and maze games build them. Read the tile at a point, find where each kind of tile is, clear the markers once their things are made, and move a body through the map without passing into walls, landing on one-way platforms from above. A map is a list of rows of text; cells are pairs across x down from 1x1; tile is a tile's size in pixels; a body is [at, speed], at being the top left of a box.

tilemap char-at [map, p, tile]

the character at a pixel point, a space off the map

tilemap char-at [["..#", "###"], 40x20, 16]
-- #
tilemap char-at [["..#", "###"], 40x-5, 16] = " "
-- true
tilemap to-cell [p, tile]

the cell a pixel point is in

tilemap to-cell [40x20, 16]
-- 3x2
tilemap to-pixel [cell, tile]

the top left pixel of a cell

tilemap to-pixel [3x2, 16]
-- 32x16
tilemap size-of [map, tile]

how big a map is, in pixels

tilemap size-of [["....", "####"], 16]
-- 64x32
tilemap find [map, ch]

every cell holding a character

tilemap find [[".o..", "#o##"], "o"]
-- [2x1, 2x2]
tilemap clear [map, marks]

the map with some characters turned to "." (the markers for things made from the map)

tilemap clear [[".o.g", "####"], "og"]
-- [...., ####]
tilemap solid [map, p, tile, chars]

is a pixel point inside a tile whose character is one of chars?

tilemap solid [["....", "####"], 20x18, 16, "#"]
-- true
tilemap touches [map, at, size, tile, chars]

does a box at a point touch a tile whose character is one of chars (thorns, water, a door)?

tilemap touches [["..^.", "####"], 28x2, 12x12, 16, "^"]
-- true
tilemap move [body, size, map, tile, solids, platforms, dt]

a body moved for dt seconds through the map without passing into tiles whose characters are in solids, landing on those in platforms only from above. Gives the body with ground (standing on something), wall (1 or -1 when it hit one going right or left, else 0) and ceiling

tilemap move [[at : 0x10, speed : 0x60], 12x12, ["....", "####"], 16, "#", "=", 0.1] at
-- 0x4
tilemap move [[at : 18x0, speed : 100x0], 12x12, ["..#.", "####"], 16, "#", "=", 0.1] wall
-- 1
tilemap move [[at : 0x2, speed : 0x60], 12x12, ["....", "==..", "####"], 16, "#", "=", 0.1] ground
-- true
tilemap drop-ahead [map, at, size, dir, tile, ground]

would a box standing at a point walk off an edge going one way (1 right, -1 left)? For walkers that turn back

tilemap drop-ahead [["....", "##.."], 20x4, 12x12, 1, 16, "#="]
-- true

runs

A well of cells for falling-block and matching games, kept as rows of text, one letter a cell and "." for an empty one: ["..r.", "rrgg"]. Find the runs of one letter long enough to pop, empty them, and let what is loose fall, while the letters named as fixed stay where they are. Places are pairs, across then down, counting from 1x1 at the top left.

runs cell-at [rows, place]

the cell at a place, "." past the edges

runs cell-at [["ab", "cd"], 2x1]
-- b
runs cell-at [["ab", "cd"], 3x1]
-- .
runs put [rows, place, cell]

the rows with one cell put at a place

runs put [["ab", "cd"], 1x2, "x"]
-- [ab, xd]
runs open [rows, places]

are all these places inside the rows and empty? (can a piece go there)

runs open [["..", "r."], [1x1, 2x2]]
-- true
runs open [["..", "r."], [1x2]]
-- false
runs open [["..", "r."], [0x1]]
-- false
runs find [rows, least]

the places in runs of at least least cells of the same letter, across or down, each place once, row by row

runs find [["rrrr", "g..."], 4]
-- [1x1, 2x1, 3x1, 4x1]
runs find [["r.", "r.", "r."], 3]
-- [1x1, 1x2, 1x3]
runs find [["rr.r", "...."], 3]
-- []
runs clear [rows, places]

the rows with these places emptied

runs clear [["ab", "cd"], [1x1, 2x2]]
-- [.b, c.]
runs settle [cells, fixed]

one column of cells, top to bottom, with every loose cell dropped onto whatever holds it up: the bottom, another cell, or a fixed letter, which stays where it is

runs settle [["a", ".", "R", "b", "."], "R"]
-- [., a, R, ., b]
runs fall [rows, fixed]

the rows with every loose cell fallen as far as it goes; the letters in fixed stay put

runs fall [["a.", "..", ".b"], ""]
-- [.., .., ab]
runs fall [["a.", "R.", ".."], "R"]
-- [a., R., ..]
runs fall [[".a", "b.", "R.", ".."], "R"]
-- [.., b., R., .a]
runs count [rows, letters]

how many cells in the rows are one of these letters

runs count [["R.r", "G.."], "RGB"]
-- 2

piece

The pieces of a block puzzle and the board they go on. A board is a grid (rows of values, 0 for an empty square); a piece is its cells, pairs counted from 0x0 at its top left, written as rows of text with # for a cell. See where a piece fits, put it on, find the rows and columns that are full and clear them. Places on the board count from 1, as in grid.

piece cells [lines]

a piece's cells from rows of text, # for a cell and anything else for none

piece cells ["##", "#."]
-- [0x0, 1x0, 0x1]
piece size [bits]

how many columns across and rows down a piece takes

piece size [0x0, 1x0, 0x1]
-- 2x2
piece fits [board, bits, at]

does the piece go on the board with its top left at a place: all inside, all on empty squares?

piece fits [grid make [3x3, 0], [0x0, 1x0], 2x1]
-- true
piece fits [grid make [3x3, 0], [0x0, 1x0], 3x1]
-- false
piece fits [[[0, 5, 0]], [0x0], 2x1]
-- false
piece put [board, bits, at, value]

the board with the piece put on at a place, its squares set to value

piece put [grid make [3x2, 0], [0x0, 1x0, 1x1], 1x1, 7]
-- [[7, 7, 0], [0, 7, 0]]
piece spots [board, bits]

every place where the piece fits, row by row

piece spots [grid make [2x2, 0], [0x0, 1x0]]
-- [1x1, 1x2]
piece anywhere [board, bits]

does the piece fit anywhere on the board?

piece anywhere [[[1, 0], [0, 1]], [0x0, 1x0]]
-- false
piece anywhere [[[1, 0], [0, 0]], [0x0, 1x0]]
-- true
piece full-lines [board]

the rows and the columns with no empty square left

piece full-lines [[1, 1], [0, 1]]
-- [rows : [1], columns : [2]]
piece full-count [board]

how many lines are full, rows and columns together

piece full-count [[1, 1], [1, 0]]
-- 2
piece clear [board, lines]

the board with some rows and columns emptied, as full-lines gives them

piece clear [[[1, 1], [0, 1]], [rows : [1], columns : [2]]]
-- [[0, 0], [0, 0]]
piece cleared [board, lines]

the squares a clear empties, as places, each once

piece cleared [[[1, 1], [0, 1]], [rows : [1], columns : [2]]]
-- [1x1, 2x1, 2x2]
piece turn [bits]

the piece turned a quarter round clockwise, still counted from 0x0

piece turn [0x0, 1x0, 2x0]
-- [0x0, 0x1, 0x2]
piece turn [0x0, 0x1, 1x1]
-- [1x0, 0x0, 0x1]
piece filled [board]

how many squares of the board are filled

piece filled [[1, 0], [0, 3]]
-- 2

hex

Grids of hexagons, the board of strategy games. A hex is a pair q x r in axial coordinates (the third, s, is 0 - q - r), pointed upward. Distilled from the TaskIAP games: 23 of the 319 play on hexes.

hex around [h]

the six hexes round one

hex around 0x0
-- [1x0, 1x-1, 0x-1, -1x0, -1x1, 0x1]
hex steps [a, b]

how many steps from one hex to another

hex steps [0x0, pair [2, -1]]
-- 2
hex within [h, n]

every hex within n steps of one

hex within [0x0, 2] length
-- 19
hex to-screen [h, size]

where a hex's centre is on screen, for hexes size from centre to corner

vec round (hex to-screen [1x1, 10])
-- 26x15
hex snap [h]

the nearest whole hex to fractional axial coordinates

hex snap 0.6x0.7
-- 0x1
hex from-screen [p, size]

the hex under a point on screen (a tap), for hexes size from centre to corner

hex from-screen [26x15, 10]
-- 1x1

iso

Isometric views, the diamond tiles of city builders and tactics games. A cell is a pair, across x down the map; a tile is the size of its diamond on screen, such as 64x32. Turn cells into screen points and back, draw in the right order and find a tile's corners.

iso to-screen [cell, tile]

the middle of a cell's tile on screen

iso to-screen [2x1, 64x32]
-- 32x48
iso from-screen [p, tile]

the cell under a point on screen

iso from-screen [32x48, 64x32]
-- 2x1
iso from-screen [40x52, 64x32]
-- 2x1
iso depth [cell]

how far back a cell is: draw smaller first

iso depth 2x1
-- 3
iso order [cells]

cells in the order to draw them, back to front

iso order [3x3, 1x1, 2x1]
-- [1x1, 2x1, 3x3]
iso diamond [cell, tile]

the four corners of a cell's tile on screen: top, right, bottom, left

iso diamond [0x0, 64x32]
-- [0x-16, 32x0, 0x16, -32x0]
iso raised [cell, tile, height]

a point raised above a cell's tile by height pixels, for walls, trees and stacked blocks

iso raised [2x1, 64x32, 10]
-- 32x38

camera

A view that follows. A camera is the point in the world at the middle of the screen, a pair: it glides after its target with a dead zone, stays inside the world, and turns points between the world and the screen. Distilled from the TaskIAP games: 32 of the 319 have a camera that moves.

camera follow [cam, target, share, dead, dt]

the camera's next place, following target: still while the target is within dead of it, else closing share of the gap beyond that every second

vec round (camera follow [0x0, 100x0, 0.9, 10, 0.1])
-- 19x0
camera keep-in [cam, screen, world]

the camera moved so a screen of size stays inside a world of size

camera keep-in [pair [5, 300], 100x80, 400x320]
-- 50x280
camera on-screen [cam, p, screen]

where a world point lands on a screen of size

camera on-screen [100x100, 130x90, 320x240]
-- 190x110
camera to-world [cam, p, screen]

the world point under a point on the screen (where a tap landed)

camera to-world [100x100, 190x110, 320x240]
-- 130x90

parallax

Layers that scroll at their own speeds, as far things go by slowly and near things fast: where a layer is for a camera, the copies of a repeating layer that cover the screen, where a thing in the world shows, and whether it shows at all. A depth of 1 moves with the world, 0.5 at half its speed, 0 not at all.

parallax offset [camera, depth]

how far a layer at depth has moved when the camera has moved so far

parallax offset [200, 0.5]
-- 100
parallax to-screen [world-x, camera, depth]

where a thing in the world shows on the screen, on a layer at depth

parallax to-screen [300, 100, 1]
-- 200
parallax to-screen [300, 100, 0.5]
-- 250
parallax on-screen [world-x, wide, camera, screen]

does a thing at world-x, so wide, show on a screen so wide for the camera?

parallax on-screen [300, 16, 100, 256]
-- true
parallax on-screen [90, 16, 100, 256]
-- true
parallax on-screen [70, 16, 100, 256]
-- false
parallax copies [camera, depth, spacing, screen]

the places across the screen of a layer drawn again every spacing pixels, one more at each side so nothing pops in

parallax copies [100, 0.5, 64, 256]
-- [-114, -50, 14, 78, 142, 206]
parallax copies [0, 1, 128, 256]
-- [-128, 0, 128, 256]
parallax piece-at [world-x, size]

which piece of a stretch laid out in pieces so wide a place in the world falls in, counting from 1

parallax piece-at [70, 32]
-- 3
parallax letter-at [plan, world-x, size]

the letter of a plan (a stretch written a letter a piece, like "..h.._..") under a place in the world, or "." past its end

parallax letter-at ["..h_", 70, 32]
-- h
parallax letter-at ["..h_", 500, 32]
-- .

orbit

Things going round: the point on a circle at a turn, the turn a point is at, which way is out and which way is along, whether a point is on a ring, the short way between two turns and how far apart they are, and where a turning thing has got to. Turns run from 0 to 1 the way a clock's hand goes on a screen, y down: 0 is right, a quarter is down. For orbit hoppers, clocks, radial menus, planets and anything on a wheel.

orbit point [centre, radius, turn]

the point on a circle round a centre at a turn

orbit point [100x100, 50, 0.25]
-- 100x150
orbit turn-of [centre, p]

the turn a point is at round a centre, from 0 up to 1

orbit turn-of [100x100, 100x150]
-- 0.25
orbit turn-of [0x0, -1x0]
-- 0.5
orbit outward [centre, p]

the unit pair pointing out from the centre through a point

orbit outward [0x0, 0x10]
-- 0x1
orbit along [turn, spin]

the unit pair along a circle at a turn, going round the way spin goes (1 the clock's way, -1 the other)

orbit along [0, 1]
-- 0x1
orbit near [p, centre, radius, slack]

is a point on a ring, within slack of it?

orbit near [0x48, 0x0, 50, 4]
-- true
orbit near [0x40, 0x0, 50, 4]
-- false
orbit gap [from, to]

the short way from one turn to another, between -0.5 and 0.5

orbit gap [0.9, 0.1]
-- 0.2
orbit gap [0.1, 0.9]
-- -0.2
orbit apart [from, to, radius]

how far apart two turns are round a ring of a radius, the short way, as a distance

orbit apart [0, 0.25, 4]
-- 6.2831853072
orbit spun [turn, spin, seconds]

where a thing going round has got to after some seconds at spin turns a second, from 0 up to 1

orbit spun [0.75, 0.5, 1]
-- 0.25
orbit spun [0.1, -0.5, 1]
-- 0.6

layout

Placing boxes on a screen, for menus, cards, buttons and HUDs. A box is [at, size], where at is its top left corner and size its width x height, both pairs, as in collide. Cut a box into columns, rows, a grid or shares, inset it, centre or pin something inside it, fit a picture in it, letterbox a game in a window and find which box a tap fell in.

layout box [corner, extent]

a box from its top left corner and its size

layout box [0x0, 320x240]
-- [at : 0x0, size : 320x240]
layout inset [b, margin]

a box with a margin taken off every side

layout inset [layout box [0x0, 100x50], 10]
-- [at : 10x10, size : 80x30]
layout columns [b, n, gap]

a box cut into n columns with gaps between

layout columns [layout box [0x0, 320x40], 3, 10] collect [c | c at x]
-- [0, 110, 220]
layout rows [b, n, gap]

a box cut into n rows with gaps between

layout rows [layout box [0x0, 100x100], 2, 10] @ 2
-- [at : 0x55, size : 100x45]
layout split [b, shares, gap]

a box cut across into widths in proportion to shares, with gaps between

layout split [layout box [0x0, 400x50], [1, 2, 1], 0] collect [c | c size x]
-- [100, 200, 100]
layout stack [b, heights, gap]

a box stacked with rows of the given heights, from the top, with gaps between

layout stack [layout box [0x0, 200x300], [40, 100], 10] @ 2
-- [at : 0x50, size : 200x100]
layout cells [b, counts, gap]

a box cut into a grid, counts across x down, row by row

layout cells [layout box [0x0, 300x200], 3x2, 0] @ 4
-- [at : 0x100, size : 100x100]
layout tiles [b, n, gap]

n boxes for n things, in as square a grid as fits (cards, thumbnails, levels)

layout tiles [layout box [0x0, 300x300], 5, 0] collect [t | t at]
-- [0x0, 100x0, 200x0, 0x150, 100x150]
layout centre [b, inner]

a box of a size, centred in another

layout centre [layout box [0x0, 320x240], 100x50]
-- [at : 110x95, size : 100x50]
layout place [b, inner, where]

a box of a size pinned inside another: where says how far across x down, 0x0 the top left, 1x1 the bottom right

layout place [layout box [0x0, 320x240], 40x20, 1x0]
-- [at : 280x0, size : 40x20]
layout fit [shape-size, b]

the biggest box of a shape that fits inside another, centred (a picture shown whole)

layout fit [16x9, layout box [0x0, 400x400]]
-- [at : 0x87.5, size : 400x225]
layout cover [shape-size, b]

the smallest box of a shape that covers another, centred (a picture filling it, cropped)

layout cover [16x9, layout box [0x0, 400x400]] size x round
-- 711
layout letterbox [game, window]

how to show a game made for one screen size in a window of another: the scale and where its corner goes

layout letterbox [320x240, 1280x800]
-- [scale : 3.3333333333, at : 106.6666666667x0]
layout hit [boxes, p]

which box a point falls in, by its place in the list, or false

layout hit [layout columns [layout box [0x0, 300x50], 3, 0], 150x25]
-- 2

matrix

Grids of numbers kept as lists of rows: multiplying, turning over, determinants, inverses and solving equations; and moves, turns and scales in 2D as 3x3 matrices that chain together and carry points.

matrix identity [n]

the n x n identity matrix

matrix identity 2
-- [[1, 0], [0, 1]]
matrix transpose [m]

a matrix with its rows and columns swapped

matrix transpose [[1, 2, 3], [4, 5, 6]]
-- [[1, 4], [2, 5], [3, 6]]
matrix multiply [a, b]

one matrix times another

matrix multiply [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
-- [[19, 22], [43, 50]]
matrix apply [m, v]

a matrix times a list of numbers

matrix apply [[[1, 2], [3, 4]], [1, 1]]
-- [3, 7]
matrix determinant [m]

the determinant of a square matrix

matrix determinant [[4, 7], [2, 6]]
-- 10
matrix determinant [[2, 0, 1], [1, 3, 2], [1, 1, 2]]
-- 6
matrix inverse [m]

the inverse of a square matrix, or false if it has none

matrix inverse [[4, 7], [2, 6]]
-- [[0.6, -0.7], [-0.2, 0.4]]
matrix solve [m, v]

the numbers that make m times them give v: equations solved together, or false

matrix solve [[[2, 1], [1, 3]], [3, 5]]
-- [0.8, 1.4]
matrix move [offset]

a 2D move by an offset

matrix point [matrix move 10x5, 1x1]
-- 11x6
matrix turn [angle]

a 2D turn by an angle in radians, about 0x0

matrix point [matrix turn (pi / 2), 1x0]
-- 0x1
matrix scale [factors]

a 2D scale, across x down

matrix point [matrix scale 2x3, 1x1]
-- 2x3
matrix then [steps]

moves, turns and scales chained into one, the first done first

matrix point [matrix then [matrix scale 2x2, matrix move 10x0], 1x1]
-- 12x2
matrix point [m, p]

a point carried by a 2D matrix

matrix point [matrix then [matrix turn (pi / 2), matrix move 5x0], 2x0]
-- 5x2

geo

Places on Earth, each a pair of latitude x longitude in degrees (south and west negative): how far apart, which way, where you end up, halfway, the nearest place, and a flat map in kilometres around a point. Distances are in km on a round Earth, close enough for maps and games.

geo distance [a, b]

the distance between two places, in km

geo distance [51.5074x-0.1278, 48.8566x2.3522] round
-- 344
geo bearing [a, b]

the compass bearing to set off on from one place to reach another, in degrees from north

geo bearing [51.5074x-0.1278, 48.8566x2.3522] round
-- 148
geo destination [from, heading, km]

where you end up going km from a place on a bearing

vec round (geo destination [0x0, 90, 111.19])
-- 0x1
geo midpoint [a, b]

the place halfway between two others

vec round (geo midpoint [0x0, 0x90])
-- 0x45
geo to-xy [p, origin]

a place as km east x km north of an origin, on a flat map (good for a city, not a continent)

vec round (geo to-xy [51.5x0.1, 51.5x0])
-- 7x0
geo compass [heading]

a bearing as one of the eight compass points

geo compass 148
-- SE
geo written [p]

a place written out with N, S, E and W

geo written 51.5074x-0.1278
-- 51.5074° N, 0.1278° W
geo within [a, b, km]

are two places within km of each other?

geo within [51.5074x-0.1278, 48.8566x2.3522, 300]
-- false
geo nearest [places, p]

the nearest of some places to p

geo nearest [[48.8566x2.3522, 40.7128x-74.006], 51.5074x-0.1278]
-- 48.8566x2.3522

Chance

seeded

Random choices you can repeat. Each one takes a seed (any number): the same seed always gives the same answer, on every machine, and a game that rewinds gets the same luck back. Use a different seed for each choice, such as the frame number, or a thing's number times 10 plus which choice it is.

seeded number [seed]

a number from 0 up to 1

seeded number 42
-- 0.0565482103
seeded between [low, high, seed]

a number from low up to high

seeded between [10, 20, 42]
-- 10.5654821033
seeded whole [low, high, seed]

a whole number from low to high, both included

seeded whole [1, 6, 42]
-- 1
seeded chance [p, seed]

true with chance p (from 0 to 1)

seeded chance [0.5, 42]
-- false
seeded pick [items, seed]

one item of a list

seeded pick [["rock", "paper", "scissors"], 42]
-- rock
seeded shuffle [items, seed]

the list in a shuffled order

seeded shuffle [[1, 2, 3, 4, 5], 42]
-- [2, 3, 5, 4, 1]
seeded bell [mean, spread, seed]

a number from a bell curve: usually near mean, spread out by spread

seeded bell [100, 15, 42] round
-- 99
seeded in-circle [r, seed]

a point inside a circle of radius r round 0x0, spread evenly

seeded in-circle [10, 42] x round
-- -2
seeded weighted [items, weights, seed]

n choices from a list, by their weights: [items, weights, seed]

seeded weighted [["common", "rare"], [9, 1], 42]
-- common
seeded triangle [low, likely, high, seed]

a number from low to high, most often near likely: a three-point guess at how long a task will take

seeded triangle [2, 3, 8, 42]
-- 6.3817927252
seeded triangle [5, 5, 5, 42]
-- 5

dice

Rolls you can repeat with a seed, written the way tabletop games write them (2d6+3), and the odds of every total. Distilled from the TaskIAP games: 66 of the 319 roll dice.

dice rolls [n, sides, seed]

the faces of n dice with sides sides

dice rolls [3, 6, 7]
-- [1, 5, 5]
dice roll [notation, seed]

the total of a roll written as 2d6+3, d20 or 3d8-1

dice roll ["2d6+3", 7]
-- 9
dice odds [n, sides]

the chance of each total with n dice of sides sides, as [total, chance]

dice odds [2, 6] @ 6
-- [7, 0.1666666667]
dice at-least [n, sides, target]

the chance of rolling target or more with n dice of sides sides

dice at-least [2, 6, 10]
-- 0.1666666667
dice advantage [seed]

a d20 rolled with advantage: two rolled, the higher kept

dice advantage 7
-- 17

cards

A deck of playing cards, shuffled with a seed, dealt and scored. A card is [rank : 1 to 13, suit : "♠"], an ace being 1 and a king 13. Distilled from the TaskIAP games: 96 of the 319 deal cards of some kind.

cards suits

the four suits

cards suits
-- [♠, ♥, ♦, ♣]
cards deck

the 52 cards, in order

cards deck length
-- 52
cards shuffled [seed]

the 52 cards in an order set by seed (the same seed, the same order)

cards shuffled 7 take 2
-- [[rank : 13, suit : ♦], [rank : 10, suit : ♠]]
cards deal [cards-in, n]

the first n cards dealt off a pile, and the pile that's left: [hand, pile]

cards deal [cards deck, 2] hand
-- [[rank : 1, suit : ♠], [rank : 2, suit : ♠]]
cards faces

the ranks as they're written, ace to king

cards faces @ 12
-- Q
cards name [card]

how a card is written: A♠, 10♥, Q♦

cards name [rank : 12, suit : "♥"]
-- Q♥
cards red [card]

is the card red?

cards red [rank : 1, suit : "♦"]
-- true
cards blackjack [hand]

a blackjack hand's best total: an ace counts 11 unless that would go over 21

cards blackjack [[rank : 1, suit : "♠"], [rank : 13, suit : "♥"]]
-- 21
cards poker [hand]

the poker hand five cards make, by name

cards poker [[rank : 3, suit : "♠"], [rank : 3, suit : "♥"], [rank : 9, suit : "♦"], [rank : 9, suit : "♣"], [rank : 9, suit : "♠"]]
-- full house

piles

The cards of a deckbuilder: the stock (the pile you draw from), a hand and a discard pile, kept as [stock, hand, discard]. Draw cards (the discard pile is shuffled back into the stock by seed when it runs out), play them, and put the hand away at the end of a turn. Any values can be cards.

piles fresh [deck, seed]

a deck shuffled into the stock, with an empty hand and discard pile

piles fresh [["bite", "kick", "hide"], 7] stock length
-- 3
piles draw [p, n, seed]

n cards drawn into the hand, the discard pile shuffled back into the stock when it runs out

piles draw [[stock : ["a", "b"], hand : [], discard : ["c"]], 3, 7] hand length
-- 3
piles draw [[stock : ["a", "b"], hand : [], discard : ["c"]], 2, 7] hand
-- [a, b]
piles play [p, k]

the card at a place in the hand played: out of the hand and onto the discard pile

piles play [[stock : [], hand : ["a", "b"], discard : []], 2]
-- [stock : [], hand : [a], discard : [b]]
piles exhaust [p, k]

the card at a place in the hand removed for good (it goes to no pile)

piles exhaust [[stock : [], hand : ["a", "b"], discard : []], 1] hand
-- [b]
piles end-turn [p]

the whole hand put on the discard pile, at the end of a turn

piles end-turn [stock : [], hand : ["a", "b"], discard : ["c"]]
-- [stock : [], hand : [], discard : [c, a, b]]
piles all-cards [p]

every card, whichever pile it is in

piles all-cards [stock : ["a"], hand : ["b"], discard : ["c"]]
-- [a, b, c]

reels

A slot machine's grid and what it pays. A grid is a list of rows, each a list of symbols; a place is a pair, the column across and the row down, from 1x1. Symbols are drawn by their weights from a seed, so a run that rewinds gets the same luck. The paylines are the rows, the columns and the diagonals; a win is a line whose first symbols are alike, at least so many of them, and a table of pays gives what each is worth.

reels spin [symbols, weights, size, seed]

a grid of symbols, size across and down, each drawn by its weight from the seed

reels spin [["a", "b"], [1, 0], 3x2, 7]
-- [[a, a, a], [a, a, a]]
reels spin [["a", "b", "c"], [1, 1, 1], 4x2, 9] collect [r | r length]
-- [4, 4]
reels at [grid, place]

the symbol at a place

reels at [[["a", "b"], ["c", "d"]], 2x1]
-- b
reels lines [size]

the paylines of a grid of a size: each row, each column, and every diagonal as long as the grid is tall, falling to the right and rising to the right; each line is its kind and its places, in order from where it starts

reels lines 3x3 length
-- 8
reels lines 5x3 length
-- 14
reels lines 2x2 @ 5
-- [kind : diagonal, places : [1x1, 2x2]]
reels wins [grid, lines, length]

the wins on some lines: each line whose first symbols are alike, at least length of them, with its kind, the symbol, how many are alike and their places

reels wins [[["a", "a", "a", "b"]], reels lines 4x1, 3]
-- [[kind : row, symbol : a, alike : 3, places : [1x1, 2x1, 3x1]]]
reels wins [[["a", "b", "a"], ["b", "a", "b"], ["a", "b", "a"]], reels lines 3x3, 3] collect [w | w kind]
-- [diagonal, diagonal]
reels tally [grid, symbol]

how many of a symbol are anywhere on the grid

reels tally [[["a", "b"], ["b", "b"]], "b"]
-- 3
reels pay [found, table]

the coins some wins pay from a table of each symbol's pays by how many are alike (a symbol not in it pays nothing)

reels pay [[[kind : "row", symbol : "a", alike : 3, places : []]], [a : [0, 0, 5, 10, 20]]]
-- 5
reels pay [[[kind : "row", symbol : "z", alike : 4, places : []]], [a : [0, 0, 5, 10, 20]]]
-- 0
reels same [grid]

is the whole grid one symbol? (a jackpot)

reels same [[["a", "a"], ["a", "a"]]]
-- true
reels stopped [began, count, gap, now]

how many reels have stopped, count of them stopping one after another gap seconds apart from a spin that began then

reels stopped [10, 5, 0.25, 10.9]
-- 3
reels stopped [10, 5, 0.25, 10.1]
-- 0
reels stopped [10, 5, 0.25, 20]
-- 5
reels blur [symbols, column, row, now]

the symbol a still-rolling reel shows at a row, flicking past quickly

reels blur [["a", "b", "c"], 2, 1, 0.5]
-- a

bag

The symbols a player owns in a slot game whose reels they build. A bag is a list of symbol names; a pull draws a grid from it by seed, each symbol as likely as its share of the bag. Symbols are added, scrapped and gilded; a gilded symbol is its name with "+" after it ("pearl+") and still counts as its kind.

bag kind [symbol]

a symbol's kind, gilded or not

bag kind "pearl+"
-- pearl
bag kind "fish"
-- fish
bag gilded [symbol]

is a symbol gilded?

bag gilded "pearl+"
-- true
bag draw [owned, size, seed]

a grid of symbols, size across and down, each drawn from the bag by the seed

bag draw [["a"], 3x2, 7]
-- [[a, a, a], [a, a, a]]
bag draw [["a", "b", "c"], 4x2, 9] collect [r | r length]
-- [4, 4]
bag add [owned, symbol]

the bag with a symbol added

bag add [["a"], "b"]
-- [a, b]
bag scrap [owned, name]

the bag with one symbol of a kind taken out, a plain one before a gilded one

bag scrap [["a", "b", "a+"], "a"]
-- [b, a+]
bag scrap [["b", "a+"], "a"]
-- [b]
bag scrap [["b"], "a"]
-- [b]
bag gild [owned, name]

the bag with one plain symbol of a kind gilded

bag gild [["a", "b", "a"], "a"]
-- [a+, b, a]
bag gild [["a+"], "a"]
-- [a+]
bag counts [owned]

how many of each kind the bag holds, gilded ones with their kind

bag counts ["a", "b", "a+"]
-- [a : 2, b : 1]
bag odds [owned, name]

the share of the bag that is a kind, from 0 to 1

bag odds [["a", "b", "a+", "c"], "a"]
-- 0.5
bag odds [[], "a"]
-- 0
bag gilt-count [owned, name]

how many of a kind are gilded

bag gilt-count [["a+", "a", "a+"], "a"]
-- 2

shop

The shop between the rounds of a roguelike. Offers are drawn from a pool by rarity with a seed, none twice; prices grow with depth, rerolls cost more each time, things sell back for half, and coins held earn interest. An offer is a record with a rarity: "common", "uncommon", "rare" or "legendary".

shop weight [rarity]

how often a rarity comes up against the others

shop weight "rare"
-- 10
shop weight "junk"
-- 0
shop draw [pool, seed]

one offer from a pool, drawn by its rarity's weight from the seed

shop draw [[[name : "a", rarity : "legendary"]], 4] name
-- a
shop offers [pool, many, seed]

some offers from a pool, none twice, each drawn by its rarity's weight from the seed

shop offers [[[name : "a", rarity : "common"], [name : "b", rarity : "rare"]], 2, 5] length
-- 2
shop offers [[[name : "a", rarity : "common"]], 3, 5] length
-- 1
shop offers [[[name : "a", rarity : "common"], [name : "b", rarity : "common"]], 2, 5] collect [o | o name] sort
-- [a, b]
shop price [cost, level, rate]

a price grown with depth: the base cost and a share more for each level down, rounded

shop price [10, 5, 0.1]
-- 15
shop reroll [base, rolls, step]

what the next reroll costs: the base, and step more for each reroll already bought

shop reroll [3, 2, 2]
-- 7
shop sell [cost]

what a thing bought for a price sells back for: half, rounded down

shop sell 25
-- 12
shop interest [coins, per, cap]

interest on coins held: one for each so many, up to a cap

shop interest [47, 10, 5]
-- 4
shop interest [470, 10, 5]
-- 5
shop rarer [a, b]

the rarer of two rarities

shop rarer ["common", "rare"]
-- rare

Play

combat

The numbers of a fight: damage through armour, critical hits, health, experience and levels, cooldowns and damage over time. Distilled from the TaskIAP games: 57 of the 319 count hit points, 33 roll critical hits.

combat damage [attack, armour]

damage after armour: each point takes a share off and none takes it all (100 armour halves it)

combat damage [40, 100]
-- 20
combat strike [amount, odds, times, seed]

a hit that may be critical: [amount, crit], critical with chance (0 to 1) and then times as hard

combat strike [10, 0.25, 2, 7]
-- [amount : 10, crit : false]
combat health [now-health, change, most]

health after a change (less than 0 is damage), kept between 0 and most

combat health [40, -55, 100]
-- 0
combat hits-to-down [hp, each]

how many hits of each it takes to bring down hp

combat hits-to-down [100, 30]
-- 4
combat xp-for [level]

the experience it takes to reach level (each level asks a little more than the one before)

combat xp-for 5
-- 800
combat level-of [xp]

the level that experience has reached

combat level-of 900
-- 5
combat level-progress [xp]

how far through its level experience is, from 0 to 1 (for an experience bar)

combat level-progress 900
-- 0.3144654088
combat ready [last, every, now]

is something last used at last, and taking every seconds to recover, ready again at now?

combat ready [2, 1, 3.1]
-- true
combat cooling [last, every, now]

how much of a cooldown is left, from 1 (just used) to 0 (ready): for a cooldown dial

combat cooling [2, 1, 2.5]
-- 0.5
combat over-time [per-second, length, start, now]

damage over time (poison, fire, bleeding): the total done by now, per-second for length seconds from start

combat over-time [5, 3, 10, 11.5]
-- 7.5
combat turn-order [fighters]

who goes first: fighters, fastest first, by their speed

combat turn-order [[name : "orc", speed : 3], [name : "elf", speed : 7]] @ 1 name
-- elf

waves

Rounds of enemies that grow harder: how many come, how tough they are, how quickly, where from, and when the boss comes. Distilled from the TaskIAP games: 33 of the 319 spawn enemies, 27 in waves, 25 with a boss.

waves size [n, first, growth]

how many come in wave n: first in wave 1, and growth times as many each wave after

waves size [5, 4, 1.3]
-- 11
waves toughness [n]

how tough each one is in wave n, as a share of the first wave's (it climbs gently)

waves toughness 10
-- 2.08
waves gap [n, slowest, fastest]

the seconds between arrivals in wave n: quicker each wave, never quicker than fastest

waves gap [20, 2, 0.4]
-- 0.4
waves boss [n, every]

is wave n a boss wave (every every-th one)?

waves boss [10, 5]
-- true
waves spawn-point [k, total, centre, radius, seed]

where the k-th of total arrives: spaced evenly round a ring of radius about centre, the ring turned by seed

vec round (waves spawn-point [1, 4, 160x120, 200, 7])
-- 275x283

particles

Sparks, dust and confetti as records [at, speed, born, life, colour] (at and speed are pairs), burst from a point with a seed (so a replay bursts the same), moved a step at a time, faded and gone. Distilled from the TaskIAP games: 29 of the 319 throw confetti, 18 more spray particles.

particles burst [from, n, speed, life, colours, now, seed]

n particles bursting from a point at up to speed, living life seconds, coloured from colours, from now

particles burst [100x100, 3, 80, 1.5, [#ffd166, #ff7ab2], 12, 7] length
-- 3
particles step [ps, gravity, dt, now]

the particles after dt seconds: moved, falling under gravity, and those past their life gone

particles step [particles burst [0x0, 4, 50, 1, [#ffd166], 0, 7], 200, 0.1, 0.5] length
-- 4
particles fade [p, now]

how much of a particle is left at now, from 1 (new) to 0 (gone): for its size, or how see-through it is

particles fade [[born : 1, life : 2], 2]
-- 0.5

rewards

What brings players back: streaks, stars, grades, best scores, achievements, and saved progress kept up to date. Distilled from the TaskIAP games: 118 of the 319 save progress, 42 count streaks, 25 award achievements.

rewards streak-points [base, streak]

points for a right answer on a streak: each one in a row adds a tenth more, up to double

rewards streak-points [100, 4]
-- 130
rewards day-streak [streak, last-day, today]

a daily streak brought up to today (days are numbers): kept on the same day, one more the next day, back to 1 after a gap

rewards day-streak [6, 41, 42]
-- 7
rewards stars [score, marks]

stars for a score: one for each mark it reaches

rewards stars [720, [300, 600, 900]]
-- 2
rewards grade [share]

a letter grade for a share right (0 to 1)

rewards grade 0.83
-- B
rewards top [scores, score, n]

a best-scores table with a new score in its place, kept to the top n

rewards top [[900, 500, 200], 600, 3]
-- [900, 600, 500]
rewards earned [rules, stats, have]

the achievements just earned: rules are [name, test] pairs, each test given the stats; have holds those earned

rewards earned [[["First steps", [s | s steps >= 1]], ["Marathon", [s | s steps >= 1000]]], [steps : 12], []]
-- [First steps]
rewards restore [defaults, saved]

saved progress brought up to date: every field the defaults have, with the saved value where there is one (and whatever the defaults no longer have, left behind)

rewards restore [[sound : true, speed : 1, level : 1], [speed : 2, colour : "red"]]
-- [sound : true, speed : 2, level : 1]

story

Branching scenes and talk. A story is a record of scenes; a scene is [text, choices], and a choice is [label, to], or [label, to, needs] when it needs a flag set first. Flags are a list of names. Distilled from the TaskIAP story and dating games: 31 of the 319 offer choices.

story open [tale, scene, flags]

the choices open in a scene, given the flags set

story open [[start : [text : "A door.", choices : [["Open it", "hall"], ["Pick the lock", "vault", "lockpick"]]]], "start", []] length
-- 1
story go [choices, k]

the scene a choice leads to

story go [[["Open it", "hall"]], 1]
-- hall
story flag [flags, name]

flags with name set (once)

story flag [["met-guard"], "has-key"]
-- [met-guard, has-key]
story typed [text, per-second, elapsed]

text typing itself out at per-second letters a second: what shows after elapsed seconds

story typed ["Hello there", 10, 0.5]
-- Hello
story typed-all [text, per-second, elapsed]

has all the text typed out yet?

story typed-all ["Hello", 10, 0.4]
-- false

wordplay

Guessing games and letters: the marks a guess earns, anagrams, scrambles and hidden words. Distilled from the TaskIAP word games (DECAWORDLE among them): 25 of the 319 have you guess words.

wordplay marks [guess, answer]

the marks a guess earns against the answer, letter by letter: G in the right place, Y in the word but elsewhere, - not in it. Letters are counted, so two Es guessed against one E mark only one of them

wordplay marks ["SPEED", "ABIDE"]
-- --Y-Y
wordplay anagram [a, b]

are two words made of the same letters?

wordplay anagram ["listen", "silent"]
-- true
wordplay scramble [word, seed]

a word with its letters mixed up by seed (and not left as it was, if another try can help it)

wordplay scramble ["planet", 7]
-- lnaetp
wordplay hide [word, guessed]

a word with the letters not yet guessed hidden

wordplay hide ["planet", "aep"]
-- p_a_e_
wordplay solved [word, guessed]

has every letter of the word been guessed?

wordplay solved ["planet", "planetx"]
-- true
wordplay vowels [word]

how many vowels a word has

wordplay vowels "sprout"
-- 2

league

Seasons of games between teams: who plays whom, the table, ratings and the chance of winning. Distilled from the TaskIAP games: 48 of the 319 run a league or a schedule, 24 rate their players.

league rounds [teams]

every team meets every other once, in rounds where each plays once (the circle method); with an odd number, one rests

league rounds ["A", "B", "C", "D"]
-- [[[A, D], [B, C]], [[A, B], [C, D]], [[A, C], [D, B]]]
league table [results]

the table from results, each [home, away, home goals, away goals]: 3 points a win and 1 a draw, best first

league table [["A", "B", 2, 1], ["B", "C", 0, 0], ["C", "A", 1, 3]] @ 1
-- [team : A, played : 2, won : 2, drawn : 0, lost : 0, points : 6, difference : 3]
league chance [a, b]

the chance that a side rated a beats one rated b (400 points apart is ten to one)

league chance [1600, 1400]
-- 0.7597469266
league rate [a, b, result, k]

both ratings after a game a scored result in (1 a win, 0.5 a draw, 0 a loss), moving by up to k

league rate [1600, 1400, 0, 32] collect [r | r round]
-- [1576, 1424]
league bracket [n]

a knockout's first round for n seeds (a power of two): best against worst, the top two kept apart till the final

league bracket 8
-- [[1, 8], [4, 5], [2, 7], [3, 6]]

economy

The arithmetic of shops, tycoons and incremental games: prices that climb, how many you can afford, earnings while away, wandering markets, and starting over for a bonus. Distilled from the TaskIAP games: 45 of the 319 earn while you wait, 41 have prices and markets, 35 a shop of upgrades.

economy price [base, growth, owned]

the price of the next one when owned are owned already and each costs growth times the one before (1.15 is usual)

economy price [10, 1.15, 5] round
-- 20
economy price-of-many [base, growth, owned, n]

the price of the next n together

economy price-of-many [10, 1.15, 5, 10] round
-- 408
economy how-many [cash, base, growth, owned]

how many more cash can buy

economy how-many [500, 10, 1.15, 5]
-- 11
economy away [per-second, cap-hours, seconds]

what was earned while away: per-second for the seconds gone, but no more than cap-hours of it

economy away [2.5, 1, 7200]
-- 9000
economy prestige [lifetime]

the bonus for starting over, from everything ever earned: a square root, so each one comes slower

economy prestige 4000000
-- 2
economy wander [now-price, fair, swing, seed]

a market price's next step: wandering by up to swing (0.1 is 10%) and pulled gently back toward fair

economy wander [100, 100, 0.1, 7] round
-- 108

needs

What a pet, a plant or a person in a care game needs, as levels from 0 to 100 that fade as time goes by and are filled by looking after them. The levels are a record ([food : 80, water : 60]); the rates say how much each one drops a second. For virtual pets, farm animals, gardens and survival games.

needs fade [levels, rates, dt]

each level dropped by its rate for dt seconds, kept between 0 and 100 (a level with no rate keeps still)

needs fade [[food : 80, water : 60], [food : 2, water : 4], 5]
-- [food : 70, water : 40]
needs fade [[food : 3, water : 60], [food : 2], 5]
-- [food : 0, water : 60]
needs fill [levels, name, amount]

one level filled by an amount (or emptied by a negative one), kept between 0 and 100

needs fill [[food : 80, water : 60], "food", 30]
-- [food : 100, water : 60]
needs fill [[food : 80, water : 60], "water", -25]
-- [food : 80, water : 35]
needs lowest [levels]

the most urgent need: the name of the lowest level

needs lowest [food : 80, water : 60, clean : 70]
-- water
needs under [levels, line]

the names of the levels under a line, lowest first, to warn about

needs under [[food : 80, water : 20, clean : 35], 40]
-- [water, clean]
needs care [levels]

how well looked after, all told: the average of the levels, rounded

needs care [food : 90, water : 60, clean : 71]
-- 74
needs mood [levels]

a word for how it feels: HAPPY, OK or SAD from the average, or what it needs most when one level is very low

needs mood [food : 90, water : 80]
-- HAPPY
needs mood [food : 50, water : 45]
-- OK
needs mood [food : 90, water : 10]
-- WATER?

Colour

palette

Colours made from hue, saturation and lightness, colours mixed along a line, and a few sets that go together.

palette hsl [hue, sat, light]

a colour from hue (0 to 360), saturation and lightness (0 to 1)

palette hsl [30, 0.8, 0.55]
-- #e88c30
palette along [stops, t]

a colour part of the way along a list of colours: t of 0 is the first, 1 the last

palette along [[#000000, #ff0000, #ffffff], 0.75]
-- #ff8080
palette wheel [n, sat, light]

n colours evenly round the colour wheel

palette wheel [4, 0.7, 0.5]
-- [#d92626, #80d926, #26d9d9, #8026d9]
palette grey [level]

a grey from 0 (black) to 1 (white)

palette grey 0.5
-- #808080
palette warm

warm colours, for fire and sunsets

palette warm length
-- 5
palette cool

cool colours, for water and night

palette cool @ 3
-- #1f6f8b
palette soft

soft colours that sit well together

palette soft @ 1
-- #f4b6c2

Kits

Modules that draw. A kit is written in Sprout like the modules above, but it draws with the game's own drawing words, so it comes along with a game that names it: ui banner ["GO", 40, 8, #ffffff]. Each example shows what it draws on a SPROUT·8 screen, 256 pixels across and 192 down, and that is checked each time the library is built too.

retro ui

retro

The look of a 1990 sunset: a sky in stacked bands, a sun cut by stripes, palm trees, a sea of moving waves, a grid floor running off to the horizon and neon signs. A kit (decision 122): it draws with the game's own words, so it comes along when a game names it. Pair it with parallax for layers that scroll at their own speeds.

retro bands [top, height, colours]

a sky in stacked bands of colour, top to bottom, from top down height pixels, across the whole screen

retro bands [0, 30, [#000055, #550055, #aa0055]]
-- draws rect [0, 0, 256, 10, #000055], rect [0, 10, 256, 10, #550055], rect [0, 20, 256, 10, #aa0055]
retro sun [at, size, colour, stripes, back]

a sun cut across its lower half by stripes of the sky behind it, each one wider than the one above

retro sun [100x50, 8, #ffff55, 2, #aa0055]
-- draws circle [100, 50, 8, #ffff55], rect [92, 52, 16, 1, #aa0055], rect [92, 55, 16, 2, #aa0055]
retro palm [at, size, trunk, leaves]

a palm tree standing on at, size pixels high: a trunk leaning as it rises and five fronds drooping from the top

retro palm [20x100, 16, #550000, #005500]
-- draws rect [20, 96, 3, 5, #550000], rect [21, 92, 3, 5, #550000], rect [22, 88, 3, 5, #550000], rect [23, 84, 3, 5, #550000], line [25, 84, 15, 88, #005500], line [25, 85, 15, 89, #005500], line [25, 84, 17, 82, #005500], line [25, 85, 17, 83, #005500], line [25, 84, 26, 80, #005500], line [25, 85, 26, 81, #005500], line [25, 84, 33, 83, #005500], line [25, 85, 33, 84, #005500], line [25, 84, 34, 88, #005500], line [25, 85, 34, 89, #005500]
retro sea [top, height, deep, foam, speed, now]

a sea between top and top + height with lines of foam drifting along it, so many pixels a second, now

retro sea [100, 8, #0055aa, #55ffff, 10, 0]
-- draws rect [0, 100, 256, 8, #0055aa], rect [37, 102, 6, 1, #55ffff], rect [101, 102, 6, 1, #55ffff], rect [165, 102, 6, 1, #55ffff], rect [229, 102, 6, 1, #55ffff], rect [10, 106, 6, 1, #55ffff], rect [74, 106, 6, 1, #55ffff], rect [138, 106, 6, 1, #55ffff], rect [202, 106, 6, 1, #55ffff]
retro grid-floor [top, back, lines, rows, now]

a grid floor from top to the bottom of the screen, lines rushing toward you as the floor moves along, now

retro grid-floor [180, #000055, #ff55aa, 3, 0]
-- draws rect [0, 180, 256, 12, #000055], line [0, 180, 255, 180, #ff55aa], line [0, 181, 255, 181, #ff55aa], line [0, 185, 255, 185, #ff55aa], line [128, 180, -128, 192, #ff55aa], line [128, 180, 0, 192, #ff55aa], line [128, 180, 128, 192, #ff55aa], line [128, 180, 256, 192, #ff55aa], line [128, 180, 384, 192, #ff55aa]
retro neon [word, at, glow, frame, now]

a neon sign: a word lit in one colour inside a frame of another, flickering off now and then

retro neon ["OPEN", 40x30, #ff55aa, #55ffff, 0]
-- draws rect [20, 22, 40, 16, #55ffff], rect [21, 23, 38, 14, #000000], text [OPEN, 40, 30, 8, #ff55aa]

ui

The drawing a game does again and again: titles with a shadow, prompts that blink, boxes, meters, menus, a strip of words along the top, talk typed out a letter at a time, words that rise from where something happened, and wipes between scenes. A kit (decision 122): it draws with the game's own drawing words, so it comes along when a game names it. The middle of the screen is W / 2, whatever the screen.

ui banner [line, y, size, colour]

a line of words across the middle with a shadow one pixel down and right

ui banner ["GO", 40, 8, #ffffff]
-- draws text [GO, 129, 41, 8, #000000], text [GO, 128, 40, 8, #ffffff]
ui blink [line, y, colour, now]

a prompt across the middle that shows for half of every second, as on a title screen

ui blink ["PRESS 1", 180, #ffffff, 0.25]
-- draws text [PRESS 1, 128, 180, 8, #ffffff]
ui blink ["PRESS 1", 180, #ffffff, 0.75]
-- draws nothing
ui panel [at, size, edge, fill]

a box: an edge two pixels wide and a fill inside it

ui panel [10x20, 40x30, #ffffff, #000000]
-- draws rect [10, 20, 40, 30, #ffffff], rect [12, 22, 36, 26, #000000]
ui meter [at, size, amount, most, fill, back]

a bar filled as far as amount goes toward most, for life, time left or a shot's power

ui meter [10x10, 40x4, 3, 4, #ff0000, #555555]
-- draws rect [10, 10, 40, 4, #555555], rect [10, 10, 30, 4, #ff0000]
ui choices [items, picked, at, lit, dim]

a list of choices down the screen from at, twelve pixels apart, the chosen one lit and pointed at

ui choices [["PLAY", "QUIT"], 1, 100x80, #ffff55, #aaaaaa]
-- draws text [>, 92, 80, 8, #ffff55], text [PLAY, 100, 80, 8, #ffff55, left], text [QUIT, 100, 92, 8, #aaaaaa, left]
ui strip [start-words, middle-words, end-words, ink, back]

a strip along the top of the screen, with words at the left, in the middle and at the right

ui strip ["HP 9", "FLOOR 2", "BEST 4", #000000, #ffffff]
-- draws rect [0, 0, 256, 12, #ffffff], text [HP 9, 4, 6, 8, #000000, left], text [FLOOR 2, 128, 6, 8, #000000], text [BEST 4, 252, 6, 8, #000000, right]
ui talk [line, began, now]

a line of talk in a box along the bottom, typed out at 24 letters a second from when it began, three rows at most

ui talk ["HELLO THERE", 0, 0.1]
-- draws rect [4, 144, 248, 44, #ffffff], rect [6, 146, 244, 40, #000000], text [HE, 12, 154, 8, #ffffff, left]
ui talked [line, began, now]

has a line of talk that began then finished typing?

ui talked ["HELLO", 0, 1]
-- true
ui float [line, at, colour, began, now]

words that rise from where something happened for a second, like +2 over a basket

ui float ["+2", 100x80, #ffff55, 1, 1.5]
-- draws text [+2, 100, 70, 8, #ffff55]
ui wipe [amount, colour]

a wipe between scenes: bars close in from both sides as amount goes from 0 to 1, and open again from 1 to 2

ui wipe [0.5, #000000]
-- draws rect [0, 0, 64, 192, #000000], rect [192, 0, 64, 192, #000000]

Wrapped libraries

Popular JavaScript libraries, each a module like the ones above. A library is loaded only when a program names it, from this site, so nothing is fetched unless it is used.

chroma simplex mathjs date-fns fuse nlp tone zzfx turf

chroma · chroma.js, BSD licence

Colour scales, colour-blind-safe palettes, contrast for reading, and mixing that looks even to the eye.

chroma scale

a colour part of the way along a list of colours, mixed in Lab so the steps look even: [colours, t]

chroma scale [[#fafa6e, #2a4858], 0.5]
-- #939c68
chroma steps

n colours evenly along a list of colours: [colours, n]

chroma steps [[#fafa6e, #2a4858], 4]
-- [#fafa6e, #b5ba6b, #727e63, #2a4858]
chroma brewer

n colours from a ColorBrewer palette by name, such as Viridis, YlGnBu, Spectral or Set2: [name, n]

chroma brewer ["Viridis", 5]
-- [#440154, #3f4a8a, #26838f, #6cce5a, #fee825]
chroma contrast

the WCAG contrast between two colours: 4.5 or more is easy to read

chroma contrast [#ffffff, #5fa8d3]
-- 2.62
chroma readable

black or white, whichever reads better on a colour

chroma readable #5fa8d3
-- #000000
chroma mix

two colours mixed in Lab: [a, b, t]

chroma mix [#ff0000, #0000ff, 0.5]
-- #ca0088
chroma named

a colour by its CSS name

chroma named "tomato"
-- #ff6347
chroma temperature

the colour of light at a temperature in kelvin

chroma temperature 3500
-- #ffc38a
chroma darken

a colour darker by an amount (1 is a lot)

chroma darken [#5fa8d3, 1]
-- #2579a2
chroma brighten

a colour brighter by an amount

chroma brighten [#1f6f8b, 1]
-- #579dbb
chroma saturate

a colour more saturated by an amount

chroma saturate [#9a978d, 2]
-- #a5984c
chroma luminance

how bright a colour is to the eye, from 0 to 1

chroma luminance #5fa8d3
-- 0.351

simplex · simplex-noise, MIT licence

Smooth noise: values that drift gently from place to place, for terrain, clouds, wobble and wandering. The same input always gives the same value.

simplex noise

smooth noise at x, y, from -1 to 1

simplex noise [0.5, 1.25]
-- 0.842928755
simplex noise3

smooth noise at x, y, z (z is often time, for noise that moves)

simplex noise3 [0.5, 1.25, 2]
-- -0.1275317057
simplex fractal

noise in several layers, big shapes with small detail on top: [x, y, layers]

simplex fractal [0.5, 1.25, 4]
-- 0.6178597606
simplex seeded

noise from its own seed, for a different world: [seed, x, y]

simplex seeded [7, 0.5, 1.25]
-- 0.3908489984

mathjs · math.js, Apache 2.0 licence

Math written as text: expressions, units and conversions, exact fractions, matrices and equations, derivatives and simplifying.

mathjs evaluate

an expression written as text: units, functions and all

mathjs evaluate "sqrt(3^2 + 4^2) * 2 cm to inch"
-- 3.937007874 inch
mathjs convert

an amount in another unit, as a number: [amount, unit]

mathjs convert ["60 mi/h", "km/h"]
-- 96.56064
mathjs fraction

exact fractions, as text

mathjs fraction "1/3 + 1/6"
-- 1/2
mathjs solve

x for a set of linear equations A x = b: [A, b]

mathjs solve [[[2, 1], [1, 3]], [3, 5]]
-- [0.8, 1.4]
mathjs multiply

two matrices (or a matrix and a vector) multiplied

mathjs multiply [[[1, 2], [3, 4]], [5, 6]]
-- [17, 39]
mathjs inverse

the inverse of a square matrix

mathjs inverse [[4, 7], [2, 6]]
-- [[0.6, -0.7], [-0.2, 0.4]]
mathjs determinant

the determinant of a square matrix

mathjs determinant [[4, 7], [2, 6]]
-- 10
mathjs derivative

the derivative of an expression, as text: [expression, variable]

mathjs derivative ["x^3 + 2x", "x"]
-- 3 * x ^ 2 + 2
mathjs simplify

an expression made simpler, as text

mathjs simplify "2x + 3x - x"
-- 4 * x

date-fns · date-fns, MIT licence

Dates written for people: formatting with a pattern, how long ago, parsing, weeks and months. Takes and gives Sprout dates like 2026-11-20.

date-fns format

a date as text, by a pattern (EEEE is the day's name, d the day, MMMM the month, yyyy the year)

date-fns format [2026-11-20, "EEEE d MMMM yyyy"]
-- Friday 20 November 2026
date-fns distance

how far apart two dates are, in words

date-fns distance [2026-11-20, 2027-02-14]
-- 3 months
date-fns parse

a date from text, by a pattern: [text, pattern]

date-fns parse ["20/11/2026", "dd/MM/yyyy"]
-- 2026-11-20
date-fns week

the ISO week number of a date

date-fns week 2026-11-20
-- 47
date-fns days-in-month

how many days the month of a date has

date-fns days-in-month 2028-02-01
-- 29
date-fns start-of-month

the first day of the month of a date

date-fns start-of-month 2026-11-20
-- 2026-11-01
date-fns end-of-month

the last day of the month of a date

date-fns end-of-month 2026-11-20
-- 2026-11-30
date-fns is-leap-year

is the year of a date a leap year?

date-fns is-leap-year 2028-01-01
-- true

fuse · Fuse.js, Apache 2.0 licence

Fuzzy search: find what was meant even when it is misspelt. Works on lists of text, or of records (searching every text field).

fuse search

the items that match, best first: [items, query]

fuse search [["apple", "banana", "pineapple", "grape"], "aple"]
-- [apple, grape, pineapple]
fuse best

the one item that matches best, or false

fuse best [[[name : "Ada"], [name : "Alan"], [name : "Grace"]], "grase"]
-- [name : Grace]
fuse scored

each match with how close it is, from 0 (exact) to 1

fuse scored [["sprout", "spout", "trout"], "sprot"]
-- [[item : sprout, score : 0.2], [item : spout, score : 0.4]]

nlp · compromise, MIT licence

English, understood a little: the nouns, verbs, people and places in text, plurals, tenses and numbers written as words.

nlp nouns

the nouns in some text

nlp nouns "The quick fox jumps over the lazy dogs"
-- [The quick fox, over the lazy dogs]
nlp verbs

the verbs in some text

nlp verbs "She sells shells and he sang"
-- [sells, sang]
nlp people

the people named in some text

nlp people "Ada Lovelace wrote to Charles Babbage"
-- [Ada Lovelace, Charles Babbage]
nlp places

the places named in some text

nlp places "From Paris to New York by way of Iceland"
-- [Paris, New York, Iceland]
nlp sentences

text split into sentences

nlp sentences "It rained. Then it stopped! Did it?"
-- [It rained., Then it stopped!, Did it?]
nlp plural

a noun made plural

nlp plural "goose"
-- geese
nlp singular

a noun made singular

nlp singular "mice"
-- mouse
nlp past

text put in the past tense

nlp past "she walks to the shop"
-- she walked to the shop
nlp future

text put in the future tense

nlp future "she walks to the shop"
-- she will walk to the shop
nlp numbers

the numbers in some text, even written as words

nlp numbers "five apples and twenty-two pears"
-- [5, 22]

tone · Tone.js, MIT licence · in the browser only

Music in the browser: notes, chords and drums. These are effects, like beep: in update they happen after the frame, and never again on rewind.

tone play

a note for a time, both as text: [note, length]. Lengths are like 8n (an eighth) or 0.5 (seconds)

tone chord

several notes at once: [notes, length]

tone drum

a drum: kick, snare or hat

tone frequency

a note's frequency in hertz

zzfx · ZzFX, MIT licence · in the browser only

Tiny 8-bit sound effects made on the spot from a list of numbers (the Zuper Zmall Zound Zynth, by Frank Force), with ready-made ones for games. These are effects, like beep: in update they happen after the frame, and never again on rewind.

zzfx play

a sound from ZzFX's own numbers: [volume, randomness, frequency, attack, sustain, release, shape, ...]

zzfx preset

a ready-made sound by name: coin, jump, hit, hurt, explode, power, laser, blip, select or step; or [name, pitch] to play it higher (2) or lower (0.5)

zzfx names

the names of the ready-made sounds

turf · Turf, MIT licence

Geography on a round Earth: distances, bearings, areas and points along a route. A point is [longitude, latitude]; a line or a polygon is a list of points.

turf distance

the distance between two points, in km

turf distance [[-0.1276, 51.5072], [2.3522, 48.8566]] round
-- 344
turf bearing

the direction from one point to another, in degrees from north

turf bearing [[-0.1276, 51.5072], [2.3522, 48.8566]] round
-- 148
turf destination

the point some km away in a direction: [point, km, bearing]

turf destination [[0, 0], 111.195, 90]
-- [0.999999, 0]
turf midpoint

the point halfway between two points

turf midpoint [[0, 0], [10, 0]]
-- [5, 0]
turf length

the length of a line of points, in km

turf length [[0, 0], [1, 0], [1, 1]] round
-- 222
turf area

the area inside a polygon of points, in square km

turf area [[0, 0], [1, 0], [1, 1], [0, 1]] round
-- 12364
turf along

the point some km along a line: [points, km]

turf along [[[0, 0], [0, 10]], 111.195]
-- [0, 0.999999]
turf inside

is a point inside a polygon? [point, polygon]

turf inside [[0.5, 0.5], [[0, 0], [1, 0], [1, 1], [0, 1]]]
-- true