Expressions
Most text fields in Skala can accept expressions as input.
Typing 1 + 2 into the width field of a rectangle results in a width of 3. Typing 20 / 2 results in a width of 10. Numbers can be placed directly next to constants and brackets to multiply them. 2gu is the same as 2 * gu, and 2(a + 1) is the same as 2 * (a + 1).
If an expression results in infinity or not a number (dividing by zero, for example), Skala will let you know and it won’t be used.
Persistent expressions #
If you’d like to keep the expression so it can be edited later, place := at the start. Typing :=20 / 2 still results in 10, but it lets you alter it to be :=20 / 4 some time in the future. If you’ve used calc() in CSS, this is very similar.
Typing := into a field opens a larger expression editor, with a button that inserts constants at the cursor. Press return to accept the expression, or tab to accept it and move to the next field.
Please note most text fields allow persistent expressions, but some do not. The document size fields and the fields in the transform properties tab calculate the result once, and the expression isn’t kept. This is to stop Skala exploding if you type :=width + 1 into the document width field. Font properties, like font size, only accept numbers.
Constants #
Number, boolean, unit, and vector constants can also be used in expressions, as can Skala’s built-in constants, like w, h, and pi. Please refer to the constants page for more information.
Arithmetic operators #
| Operator | Definition |
|---|---|
| + | Addition between x and y. Example: x + y. |
| - | Subtraction between x and y. Example: x - y. |
| * | Multiplication between x and y. Example: x * y. |
| / | Division between x and y. Example: x / y. |
| % | Modulus of x with respect to y. Example: x % y. |
| ^ | x to the power of y. Example: x ^ y. |
Equalities and inequalities #
| Operator | Definition |
|---|---|
| == or = | True only if x is strictly equal to y. Example: x == y. |
| <> or != | True only if x does not equal y. Example: x <> y or x != y. |
| < | True only if x is less than y. Example: x < y. |
| <= | True only if x is less than or equal to y. Example: x <= y. |
| > | True only if x is greater than y. Example: x > y. |
| >= | True only if x greater than or equal to y. Example: x >= y. |
Boolean operations #
Comparisons and boolean operations return 1 for true and 0 for false. Any value other than zero counts as true.
| Operator | Definition |
|---|---|
| and | Logical AND, true only if x and y are both true. Example: x and y. |
| mand | Multi-input logical AND, true only if all inputs are true. Left to right short-circuiting of expressions. Example: mand(x > y, z < w, u or v, w and x). |
| mor | Multi-input logical OR, true if at least one of the inputs are true. Left to right short-circuiting of expressions. Example: mor(x > y, z < w, u or v, w and x). |
| nand | Logical NAND, true only if either x or y is false. Example: x nand y. |
| nor | Logical NOR, true only if the result of x or y is false. Example: x nor y. |
| not | Logical NOT, Negate the logical sense of the input. Example: not(x and y) == x nand y. |
| or | Logical OR, true if either x or y is true. Example: x or y. |
| xor | Logical XOR, true only if the logical states of x and y differ. Example: x xor y. |
| xnor | Logical XNOR, true if the biconditional of x and y is satisfied. Example: x xnor y. |
| & | Similar to AND but with left to right expression short circuiting optimisation. Example: (x & y) == (y and x). |
| | | Similar to OR but with left to right expression short circuiting optimisation. Example: (x | y) == (y or x). |
General purpose functions #
| Operator | Definition |
|---|---|
| abs | Absolute value of x. Example: abs(x). |
| avg | Average of all the inputs. Example: avg(x, y, z, w, u, v) == (x + y + z + w + u + v) / 6. |
| ceil | Smallest integer that is greater than or equal to x. Example: ceil(x). |
| clamp | Clamp x in range between r0 and r1, where r0 < r1. Example: clamp(x, r0, r1). |
| clamp01 | Clamp x in range between 0 and 1. Example: clamp01(x). |
| equal | Equality test between x and y using normalised epsilon. Example: equal(x, y). |
| erf | Error function of x. Example: erf(x). |
| erfc | Complementary error function of x. Example: erfc(x). |
| exp | e to the power of x. Example: exp(x). |
| expm1 | e to the power of x minus 1, where x is very small. Example: expm1(x). |
| floor | Largest integer that is less than or equal to x. Example: floor(x). |
| frac | Fractional portion of x. Example: frac(x). |
| hypot | Hypotenuse of x and y. Example: hypot(x, y) == sqrt(x * x + y * y). |
| iclamp | Inverse-clamp x outside of the range r0 and r1, where r0 < r1. If x is within the range it will snap to a bound. Example: iclamp(x, r0, r1). |
| if | Returns y if x is true, otherwise returns z. Example: if(x, y, z). |
| inrange | In-range returns 1 (true) when x is within the range r0 and r1, where r0 < r1. Example: inrange(x, r0, r1). |
| log | Natural logarithm of x. Example: log(x). |
| log10 | Base 10 logarithm of x. Example: log10(x). |
| log1p | Natural logarithm of 1 + x, where x is very small. Example: log1p(x). |
| log2 | Base 2 logarithm of x. Example: log2(x). |
| logn | Base N logarithm of x, where n is a positive integer. Example: logn(x, 8). |
| max | Largest value of all the inputs. Example: max(x, y, z, w, u, v). |
| min | Smallest value of all the inputs. Example: min(x, y, z, w, u). |
| mod | Modulus of x with respect to y. Example: mod(x, y) == x % y. |
| mul | Product of all the inputs. Example: mul(x, y, z, w, u, v, t) == (x * y * z * w * u * v * t). |
| ncdf | Normal cumulative distribution function. Example: ncdf(x). |
| not_equal | Not-equal test between x and y using normalised epsilon. Example: not_equal(x, y). |
| pow | x to the power of y. Example: pow(x, y) == x ^ y. |
| root | Nth root of x, where n is a positive integer. Example: root(x, 3) == x ^ (1 / 3). |
| round | Round x to the nearest integer. Example: round(x). |
| roundn | Round x to n decimal places, where n > 0 and is an integer. Example: roundn(1.2345678, 4) == 1.2346. |
| sgn | Sign of x, -1 where x < 0, +1 where x > 0, else zero. Example: sgn(x). |
| sqrt | Square root of x, where x >= 0. Example: sqrt(x). |
| sum | Sum of all the inputs. Example: sum(x, y, z, w, u, v, t) == (x + y + z + w + u + v + t). |
| trunc | Integer portion of x. Example: trunc(x). |
Trigonometry functions #
Trigonometry functions work in radians, but Skala’s rotation fields use degrees. Use deg2rad and rad2deg to convert between them — :=sin(deg2rad(30)) returns 0.5.
| Operator | Definition |
|---|---|
| acos | Arc cosine of x expressed in radians. Interval [-1, +1]. Example: acos(x). |
| acosh | Inverse hyperbolic cosine of x expressed in radians. Example: acosh(x). |
| asin | Arc sine of x expressed in radians. Interval [-1, +1]. Example: asin(x). |
| asinh | Inverse hyperbolic sine of x expressed in radians. Example: asinh(x). |
| atan | Arc tangent of x expressed in radians. Example: atan(x). |
| atan2 | Arc tangent of (x / y) expressed in radians. Interval [-pi, +pi]. Example: atan2(x, y). |
| atanh | Inverse hyperbolic tangent of x expressed in radians. Example: atanh(x). |
| cos | Cosine of x. Example: cos(x). |
| cosh | Hyperbolic cosine of x. Example: cosh(x). |
| cot | Cotangent of x. Example: cot(x). |
| csc | Cosecant of x. Example: csc(x). |
| sec | Secant of x. Example: sec(x). |
| sin | Sine of x. Example: sin(x). |
| sinc | Sine cardinal of x. Example: sinc(x). |
| sinh | Hyperbolic sine of x. Example: sinh(x). |
| tan | Tangent of x. Example: tan(x). |
| tanh | Hyperbolic tangent of x. Example: tanh(x). |
| deg2rad | Convert x from degrees to radians. Example: deg2rad(x). |
| deg2grad | Convert x from degrees to gradians. Example: deg2grad(x). |
| rad2deg | Convert x from radians to degrees. Example: rad2deg(x). |
| grad2deg | Convert x from gradians to degrees. Example: grad2deg(x). |
Blending and interpolation #
The mix functions blend from a to b as t goes from 0 to 1. The step functions do the opposite, returning a value between 0 and 1 based on where x sits between a and b. Values of x outside that range are clamped.
| Operator | Definition |
|---|---|
| mixnearest | Nearest interpolation from a to b, controlled by t (0 to 1 range). Example: mixnearest(a, b, t). |
| mixlinear | Linear interpolation from a to b, controlled by t (0 to 1 range). Example: mixlinear(a, b, t). |
| mixcosine | Cosine interpolation from a to b, controlled by t (0 to 1 range). Example: mixcosine(a, b, t). |
| mixhermite3 | Hermite3 interpolation from a to b, controlled by t (0 to 1 range). Example: mixhermite3(a, b, t). |
| mixhermite5 | Hermite5 interpolation from a to b, controlled by t (0 to 1 range). Example: mixhermite5(a, b, t). |
| mixhermite7 | Hermite7 interpolation from a to b, controlled by t (0 to 1 range). Example: mixhermite7(a, b, t). |
| stepnearest | Nearest interpolation between 0 and 1 when a < x < b. Example: stepnearest(a, b, x). |
| steplinear | Linear interpolation between 0 and 1 when a < x < b. Example: steplinear(a, b, x). |
| stepcosine | Cosine interpolation between 0 and 1 when a < x < b. Example: stepcosine(a, b, x). |
| stephermite3 | Hermite3 interpolation between 0 and 1 when a < x < b. Example: stephermite3(a, b, x). |
| stephermite5 | Hermite5 interpolation between 0 and 1 when a < x < b. Example: stephermite5(a, b, x). |
| stephermite7 | Hermite7 interpolation between 0 and 1 when a < x < b. Example: stephermite7(a, b, x). |
Ternary operations #
Ternary operations can be used for conditional expressions. The ternary a ? b : c checks a and returns b if true, or c if false. For example, with a boolean constant called compact, :=compact ? 8 : 16 returns 8 when compact is true, and 16 when it is false. The if function does the same thing: :=if(compact, 8, 16).