Loops and values · 3 of 4
Built-in functions
laylight has the usual mathematical functions, and they respect units just like the operators:
| Functions | Notes |
|---|---|
sqrt abs min max floor ceil round pow sign | work on quantities: sqrt(9um * 4um) is 6um, max(1um, 500nm) is 1um |
sin cos tan | take an angle and return a number |
asin acos atan atan2(y, x) | return an angle |
len str | the length of a list; a value as a string |
The constant pi exists too, although with angle units it is rarely needed: 360deg / 8 is 45deg.
Points have parts and arithmetic: p.x, p.y and p.angle read the coordinates and the direction of a point, and p + (1um, 0) moves it (keeping its direction).
define also works inside a block, where it names a value for the rest of the block — here, for one round of the loop:
for i in 0..count {
define a = i * 360deg / count
...
}Exercise
Spread count pads evenly on a circle of radius radius around the origin: pad i goes at the angle i × 360° / count, so that the first one sits on the positive x axis.