aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-16 15:58:11 +0200
committeruser <user@clank>2026-08-16 15:58:11 +0200
commit72ffc4cc5cc5f9b95d21a115e761de6a632d68a5 (patch)
tree860336fd32f5aa62676eff0fcdbd5e72f214908a /docs
parentsl0ppty: bits (diff)
downloadslosh-72ffc4cc5cc5f9b95d21a115e761de6a632d68a5.tar.gz
slosh-72ffc4cc5cc5f9b95d21a115e761de6a632d68a5.tar.xz
slosh-72ffc4cc5cc5f9b95d21a115e761de6a632d68a5.zip
sl0ppty: sin and cos
128 + sin(t / 4) / 2 a breathe that is actually a sine abs(sin(x * 6 + t / 5)) a wave travelling along a frame abs(sin(dist(x, y, curx, cury) * 20 - t / 4)) / 2 ripples from the cursor Degrees in, -255..255 out. Two decisions, both for the same reason -- this is a language people type into a config file, not one they read a manual for. Degrees because that is what anybody guesses, and 255 because it is the scale every strength here already uses: `128 + sin(t / 4) / 2` is a breathe centred half way up with nothing to rescale, and `abs(sin(...))` is an amount as it stands. Every angle wraps, negative ones included. `t / 4` does not stop at 360 and an expression that died at one turn would be no use for the one thing this is for. A 91-entry table of round(255*sin) at one-degree steps, three quadrants by symmetry, no interpolation -- the argument is an integer and there is nothing between two degrees to interpolate. A table and not a polynomial because `contrib/shadertoy.html` reimplements this language in JavaScript so the preview can run in a browser, and `tests/test_shadertoy.py` compares the two on every expression: identical data with identical reduction cannot drift the way two approximations of one curve would. The JS carries the same 91 numbers. Until now the only oscillator was `abs(t / 6 % 510 - 255)`, a triangle wave written as arithmetic. It works and it looks like what it is -- a ramp with a corner in it. A sine has no corner, which is the whole difference between a pane that pulses and a pane that flickers. Verified: 19 cases in `tests/expr_test.c` (the cardinal angles, quadrant symmetry, wrapping past a turn and below zero, and the breathe idiom); the cross-check now agrees with the compiler on 660 evaluations including generated trig; the repl's completion drift test caught `sin`/`cos` missing from its list before I did, which is what it is for. Then six chains in a real pane -- breathe, travelling wave, clipped crests, plasma, rolling scanlines, cursor ripples -- each measured over eight distinct frames.
Diffstat (limited to 'docs')
-rw-r--r--docs/shaders.md1
1 files changed, 1 insertions, 0 deletions
diff --git a/docs/shaders.md b/docs/shaders.md
index aa332e5..716395a 100644
--- a/docs/shaders.md
+++ b/docs/shaders.md
@@ -65,6 +65,7 @@ shaders {
| | `a ? b : c` — both sides are evaluated, then one is chosen |
| functions | `min(a,b)` `max(a,b)` `abs(a)` `clamp(v,lo,hi)` |
| | `dist(x1,y1,x2,y2)` — counts a row double, because a cell is about twice as tall as it is wide |
+| | `sin(deg)` `cos(deg)` — **degrees** in, −255..255 out, so `128 + sin(t / 4) / 2` is a breathe |
There are no loops and no recursion, on purpose: a config cannot spin and there
is nothing to sandbox. An expression that does not compile drops that one shader