Repository navigation
Free formula
The Custom layer effect (German: Baukasten) normally builds a lighting effect from a motion pattern, a press reaction and a scale. Tick Free formula (Freie Formel) and you replace the pattern with a single math expression that you write yourself. This page documents it exactly.
Jump to the German version: Freie Formel
Your expression is evaluated once per LED, every frame (~25×/second). Its result is a position in the layer's palette:
-
0= the first colour,1= all the way around and back to the first colour (one full loop). - Any real number works; it wraps, so
0.25,1.25and-0.75are the same colour.
How the palette is built from the layer's colours:
| Colour mode of the layer | The loop the result indexes |
|---|---|
| One colour | colour → black → colour |
| Two colours | colour → second colour → colour |
| Gradient (3+ colours) | straight through the gradient and back to the start |
So the formula decides which palette colour a key shows; the palette decides what those colours are. Brightness is still the layer's Brightness slider.
- Add or select a layer (the free formula is a layer effect; it never touches the base effect or the firmware).
- Set its effect to Custom.
- Tick Free formula. The pattern dropdown disappears and a text box appears.
- Type your expression. Under the box a live check shows Formula OK, or the error, or the variable cheat-sheet when it is empty.
The press reaction (none / flash / wave) still works on top of the formula, so you can e.g. flash a key white on press while the formula drives the resting colours.
| Name | Meaning | Range / notes |
|---|---|---|
x |
column position of the LED, in key units | ~0 (left) … ~23 (right) |
y |
row position of the LED, in key units | ~0 (top) … ~6 (bottom) |
t |
time in seconds, always increasing | a large number; only changes over time matter |
d |
distance of the LED from the board centre, in key units |
0 at the centre, ~14 in the corners |
a |
angle of the LED around the centre, in turns |
-0.5 … 0.5 (a full circle = 1) |
seit |
seconds since this key was last pressed |
~0 right after a press, grows; once the press is forgotten (a few seconds) it jumps to a very large number (1e9) |
d and a are polar coordinates around the centre; x/y are the raw position. The board centre is roughly x = 11.6, y = 3.1.
To make anything move, include t. Without t the field stands still (that is exactly what the Still pattern is).
To make a key react to presses, use seit — e.g. seit < 0.3 is true only in the first moments after a press.
Allowed functions: sin cos tan sqrt exp floor ceil atan2 hypot abs min max
Constants: pi tau (tau = 2·pi)
Allowed operators: + - * / // (floor division) % (modulo), comparisons (< > <= >= == !=), and or, and the conditional A if condition else B.
Not allowed (the live check rejects it before it can run): the power operator **, attribute access (.), indexing ([]), names other than the ones above, any function other than those listed, lambdas. Use x*x instead of x**2.
deck.json profiles are meant to be shared. A formula therefore runs in a restricted sandbox: it can only do maths over the variables above, with no access to files, the system, or Python internals. The power operator is blocked so a shared profile cannot smuggle in something like t**9e9 to freeze the program. Opening someone else's profile is safe.
- Invalid formula (red error under the box): the layer quietly falls back to the normal Still pattern until you fix it. Nothing crashes.
- Runtime error while drawing (e.g. a division by zero for some keys): those keys simply go dark for that frame. Again, nothing crashes.
| Formula | What you get |
|---|---|
x/4 - t |
a horizontal colour wave moving left→right |
(x + y)/6 - t |
a diagonal wave |
d/5 - t |
rings spreading out from the centre (like Radial) |
d/5 + t |
rings pulling inward |
a |
a tornado: colours around the centre |
a + d/8 - t |
a spiral |
sin(t) |
the whole board breathes smoothly through the palette |
sin(t) + sin(x/2) |
soft horizontal bands that shimmer |
floor(x)/4 |
hard vertical stripes, one palette step per column |
d/4 - t + sin(a*6)/4 |
rings with 6 petals – a flower |
seit |
keys you pressed recently sit at the palette start and drift away as seit grows |
0 if seit < 0.4 else d/5 - t |
the radial field everywhere, but a just-pressed key snaps to the first colour |
atan2(sin(a*tau), cos(a*tau)) |
(example of using the functions) |
Start from one of these and change the numbers: a bigger divisor = a larger/zoomed pattern, a + t vs - t flips the direction, multiply inside sin(...) for more cycles.
Der Ebeneneffekt Baukasten baut einen Lichteffekt normalerweise aus Muster, Druckreaktion und Skala. Hakst du Freie Formel an, ersetzt du das Muster durch einen selbst geschriebenen mathematischen Ausdruck. Diese Seite dokumentiert ihn genau.
Dein Ausdruck wird für jede LED, jedes Bild (~25×/Sekunde) ausgewertet. Das Ergebnis ist eine Position in der Palette der Ebene:
-
0= die erste Farbe,1= einmal ganz herum und zurück zur ersten Farbe (eine volle Runde). - Jede reelle Zahl geht; es wiederholt sich, also sind
0,25,1,25und-0,75dieselbe Farbe.
Wie die Palette aus den Farben der Ebene entsteht:
| Farbmodus der Ebene | Die Runde, die das Ergebnis adressiert |
|---|---|
| Eine Farbe | Farbe → Schwarz → Farbe |
| Zwei Farben | Farbe → zweite Farbe → Farbe |
| Verlauf (3+ Farben) | geradewegs durch den Verlauf und zurück zum Anfang |
Die Formel bestimmt also die Palettenposition, die Palette bestimmt die Farben. Die Helligkeit regelt weiter der Helligkeitsregler der Ebene.
- Eine Ebene anlegen oder wählen (die freie Formel ist ein Ebeneneffekt; sie rührt weder den Grundeffekt noch die Firmware an).
- Den Effekt auf Baukasten stellen.
- Freie Formel anhaken. Die Muster-Auswahl verschwindet, ein Textfeld erscheint.
- Ausdruck eintippen. Unter dem Feld zeigt eine Live-Prüfung Formel OK, den Fehler, oder – wenn leer – den Variablen-Spickzettel.
Die Druckreaktion (aus / Aufleuchten / Welle) wirkt weiter über der Formel – eine Taste kann also beim Druck weiß aufleuchten, während die Formel die Ruhefarben treibt.
| Name | Bedeutung | Bereich / Hinweise |
|---|---|---|
x |
Spaltenposition der LED, in Tasteneinheiten | ~0 (links) … ~23 (rechts) |
y |
Zeilenposition der LED, in Tasteneinheiten | ~0 (oben) … ~6 (unten) |
t |
Zeit in Sekunden, immer steigend | eine große Zahl; nur Änderungen über die Zeit zählen |
d |
Abstand der LED zur Boardmitte, in Tasteneinheiten |
0 in der Mitte, ~14 in den Ecken |
a |
Winkel der LED um die Mitte, in Umdrehungen |
-0,5 … 0,5 (voller Kreis = 1) |
seit |
Sekunden seit dem letzten Druck dieser Taste |
~0 direkt nach dem Druck, wächst; ist der Druck vergessen (ein paar Sekunden), springt es auf eine sehr große Zahl (1e9) |
d und a sind Polarkoordinaten um die Mitte; x/y die rohe Position. Die Mitte liegt etwa bei x = 11,6, y = 3,1.
Damit sich etwas bewegt, muss t vorkommen. Ohne t steht das Feld still (genau das ist das Muster Ruhend).
Damit eine Taste auf Druck reagiert, nimm seit – z. B. ist seit < 0.3 nur in den ersten Momenten nach einem Druck wahr.
Erlaubte Funktionen: sin cos tan sqrt exp floor ceil atan2 hypot abs min max
Konstanten: pi tau (tau = 2·pi)
Erlaubte Operatoren: + - * / // (Ganzzahl-Division) % (Modulo), Vergleiche (< > <= >= == !=), and or, und das bedingte A if Bedingung else B.
Nicht erlaubt (die Live-Prüfung weist es ab, bevor es laufen kann): der Potenz-Operator **, Attributzugriff (.), Indizierung ([]), andere Namen als die obigen, andere Funktionen als die aufgeführten, Lambdas. Statt x**2 nimm x*x.
deck.json-Profile sind zum Teilen gedacht. Eine Formel läuft deshalb in einer eingeschränkten Sandbox: nur Mathematik über die obigen Variablen, kein Zugriff auf Dateien, System oder Python-Interna. Der Potenz-Operator ist gesperrt, damit ein geteiltes Profil nicht etwas wie t**9e9 einschleusen und das Programm einfrieren kann. Ein fremdes Profil zu öffnen ist sicher.
- Ungültige Formel (roter Fehler unter dem Feld): die Ebene fällt still auf das normale Muster Ruhend zurück, bis du es behebst. Nichts stürzt ab.
- Laufzeitfehler beim Zeichnen (z. B. eine Division durch Null für manche Tasten): diese Tasten bleiben in dem Bild einfach dunkel. Auch hier: kein Absturz.
| Formel | Was dabei herauskommt |
|---|---|
x/4 - t |
eine waagerechte Farbwelle von links nach rechts |
(x + y)/6 - t |
eine diagonale Welle |
d/5 - t |
Ringe, die von der Mitte nach außen laufen (wie Radial) |
d/5 + t |
Ringe, die nach innen ziehen |
a |
ein Tornado: Farben rund um die Mitte |
a + d/8 - t |
eine Spirale |
sin(t) |
das ganze Board atmet weich durch die Palette |
sin(t) + sin(x/2) |
sanfte waagerechte Bänder, die schimmern |
floor(x)/4 |
harte senkrechte Streifen, ein Palettenschritt pro Spalte |
d/4 - t + sin(a*6)/4 |
Ringe mit 6 Blättern – eine Blume |
seit |
kürzlich gedrückte Tasten sitzen am Palettenanfang und driften weg, während seit wächst |
0 if seit < 0.4 else d/5 - t |
überall das Radialfeld, eine gerade gedrückte Taste springt auf die erste Farbe |
Nimm eines davon und ändere die Zahlen: ein größerer Teiler = ein größeres/herausgezoomtes Muster, + t statt - t dreht die Richtung um, ein Faktor in sin(...) bringt mehr Durchläufe.