Function

@p, @P

Pick one of the arguments at random. @P does the same but never returns the value it picked last time at the same place.

Syntax

  • @p(<value>, ...)
  • @p(<value> x<count>, ...)
  • @p(<index>: <value>, ...)
  • @p([<range>])
  • @p(<value>, <value>, ..., <end>)
  • @p(<value>, <value>, ...)
  • @p(--<variable>)
  • @p()
  • @P(<value>, ...)

A value can be anything, including other function calls. Wrap it in quotes or parentheses if it contains a comma. The picks follow the doodle's seed.

Picking at random

Each cell picks again:

@grid: 5 / 60vmin _1px;
background: @p(#000, #e6437d, #ebbf4d);

Characters in brackets expand to a list, as in [a-z] or [0-9a-f]:

@grid: 5 / 60vmin _1px;
background: #000;
color: #fff;
@content: @p([A-Z]);

... fills in the steps between two values, so 1, 3, ..., 11 is 1, 3, 5, 7, 9, 11. At the end of the list it goes on to one value per cell, so on a 5×5 grid @p(1, 2, ...) picks from 1 to 25:

@grid: 5 / 60vmin _1px;
background: #000;
color: #fff;
@content: @p(1, 2, ...);

A value followed by x and a count is listed that many times, so one pick can be likelier than the others:

@grid: 6 / 60vmin _1px;
background: @p(#000 x3, #e6437d, #ebbf4d);

Picking by index

An expression before a colon picks the value at that position, counting from 1 and wrapping around. It reads the cell names i, x, y and the rest, and custom properties without their --, so the pick follows the cell instead of the seed:

@grid: 7 / 60vmin _1px;
background: @p(x + y: #000, #e6437d, #ebbf4d);

A single value after the colon is the list to pick from, as in @pn: a range, a custom property, or a function that returns a list, such as @palette:

@grid: 7 / 60vmin _1px;
background: @p(x + y: @palette(4));

From a variable

A custom property holding a comma-separated list gives one candidate per item:

@grid: 6 / 60vmin _1px;
--colors: #cc063e, #fd9407, #e2d9c2, #10898b;
background: @p(--colors);
@shape: @p(circle, hexagon);

Without repeats

@P skips the value it picked at the same place in the cell before, however many times it is listed, so neighbouring cells differ in a one-dimensional grid:

@grid: 1x12 / 60vmin;
background: @P(#000, #e6437d, #ebbf4d);

@p() with no arguments picks again from the arguments of the previous @p or @P, and @P() also skips the value picked just before it. @lp repeats the last picked value.

Reference

FormNotes
<index>: …wraps around as in @pn, and only the value picked is evaluated. @P doesn't take an index.
[…]single characters and ranges, such as [0-9a-f] or [A-Z0-9]
...steps by the gap between the two values before it, up to the value after it: a, c, ..., i is a, c, e, g, i. At the end it goes on to one value per cell, or per step inside @m. Reads numbers with the same unit, or single characters. Every pick function takes it.
x<count>after a value, lists it that many times: a x3, b is a, a, a, b. Every pick function takes it.
--variableread when the doodle is generated
@p.cycle(…)picks from what @cycle or @mirror returns
@pickan older name for @p, and takes the index too

See also