# Fluxion > Fluxion (https://osmansiddiquer.github.io/Fluxion/) is a free, browser-based grapher for differential equations, functions, implicit curves, polar and parametric curves, inequalities (shaded regions) and points, with user functions, repeats, keyframed animation and styling for drawings, plus a sandboxed JavaScript Script mode for drawings and animation that can read the graph's ODE solutions. AI agents can make a graph for their user by building a URL: the link opens straight to the plot, and the link itself is the shareable result. No API key, no backend, nothing to install. Base URL: `https://osmansiddiquer.github.io/Fluxion/` The graph lives in the URL fragment (after `#`), so it never reaches a server. There are three ways to write it: 1. **Params (no code needed)**: `#expr=...&expr=...&xmin=...`. Best for hand-written links. 2. **JSON spec**: `#spec=`. Full control, still writable by hand. 3. **Compressed JSON spec**: `#z=`. Shortest links; needs code (snippets below). Give the user the link (e.g. as a markdown link). Opening it shows the graph, which they can then edit, animate and re-share. ## Quick start A sine curve: https://osmansiddiquer.github.io/Fluxion/#expr=y=sin(x) A damped oscillator `y'' = -0.3y' - sin(y)` with y(0) = 2, y'(0) = 0, plotted for 0 ≤ t ≤ 20: https://osmansiddiquer.github.io/Fluxion/#expr=y''=-0.3y'-sin(y)&ic=2,0&xmin=0&xmax=20 Logistic growth with sliders for the rate `r0` and capacity `K`: https://osmansiddiquer.github.io/Fluxion/#expr=P'=r0*P*(1-P/K)&ic=0.5&color=green&expr=r0=0.8&min=0&max=3&expr=K=4&min=1&max=8&xmin=-1&xmax=12&ymin=-1&ymax=5 A circle, the region inside it above the x-axis, and a point: https://osmansiddiquer.github.io/Fluxion/#expr=x^2+y^2=9&expr=x^2+y^2<9%26y>0&color=blue&expr=(1,2)&label=P An animation: a slider `a` that plays on open, driving a Lissajous curve whose colour cycles, and a filled disc that pulses (grid, markers and panels off for a clean canvas): https://osmansiddiquer.github.io/Fluxion/#expr=a=0&min=0&max=2pi&anim=loop&autoplay=1&expr=(3cos(t),2sin(3t+a))&width=3&colorexpr=hsv(57*a,0.8,0.85)&expr=((1+0.3sin(2a))*cos(t),(1+0.3sin(2a))*sin(t))&fill=1&opacity=0.35&width=0&fillcolor=hsv(57*a+180,0.6,1)&grid=off&markers=off&panels=none A built-in demo (see "Built-in examples" for the list): https://osmansiddiquer.github.io/Fluxion/#example=mandala ## Writing params links - Start with the base URL, then `#`, then `key=value` pairs joined by `&`. - Each `expr=` adds one expression (one row in the app). Options such as `color`, `ic`, `min` apply to the **most recent** `expr`. - Use the fragment (`#`), not a query string (`?`). In the fragment `+` means plus. (A `?expr=` query also works, but there `+` means a space, so you must write `%2B`.) - Percent-encode only what's needed: a space as `%20` (or just leave spaces out; they are never required), `&` inside an expression as `%26`, `#` as `%23`, `%` as `%25`. Everything else (`= ' ( ) ^ * / , < >`) may be written as is. - Keys are case-insensitive. Unknown keys are ignored (with a warning) rather than breaking the link. ### Per-expression params (apply to the latest `expr`) | param | meaning | example | | --- | --- | --- | | `color` | palette name (`red`, `blue`, `green`, `purple`, `orange`, `black`, `pink`, `teal`) or hex without `#` | `color=teal`, `color=ff8800` | | `hidden` | hide the curve (`1`/`0`) | `hidden=1` | | `ic` | ODE initial conditions at t0: `y(t0),y'(t0),...` (one value per order) | `ic=2,0` | | `t0` | ODE initial time (default 0) | `t0=1` | | `min`, `max`, `step` | slider range and step for a variable such as `k=2` | `min=0&max=5&step=0.1` | | `anim`, `speed` | slider play mode (`loop`, `bounce`, `once`) and speed (1 = a full sweep in about 4 s; 0.0001 to 100) | `anim=bounce` | | `thetamin`, `thetamax` | θ range for polar curves and polar regions (default 0 to 2pi) | `thetamax=6pi` | | `label`, `labeldir`, `size`, `drag` | point label (LaTeX), its direction (`n ne e se s sw w nw`), marker radius 2 to 14, drag mode (`auto off x y both`) | `label=P&labeldir=ne` | | `width`, `style` | line width in px (0 hides the line) and dash style (`solid`, `dashed`, `dotted`) | `width=3&style=dashed` | | `fill`, `opacity` | fill a closed curve or polygon (`1`/`0`) and the fill opacity 0 to 1 | `fill=1&opacity=0.3` | | `colorexpr`, `fillcolor` | line / fill colour as an expression over sliders: `hsv(h,s,v)`, `hsl(h,s,l)`, `rgb(r,g,b)`, `rgba(r,g,b,a)`, or hex without `#` | `colorexpr=hsv(57*a,0.8,0.9)` | | `autoplay` | start a slider playing when the link opens (`1`/`0`); pair with `anim` | `anim=loop&autoplay=1` | | `samples` | the expression's own sample count, 8 to 20000 (see "Animation & performance") | `samples=96` | | `dots` | polylines: show (`1`) or hide (`0`) the vertex dots | `dots=0` | | `blend` | blend mode: `normal`, `add`, `screen`, `multiply`, `overlay`, `lighten`, `darken` | `blend=add` | | `glow`, `blur` | glow / blur radius in px, 0 to 50 | `glow=12` | | `layer` | draw on the layer row `name = layer(...)` of that name | `layer=far` | | `field` | ODE: slope field / vector field + nullclines on (`1`) or off (`0`); default: slope fields off, the phase plane's vector field on | `field=1` | | `phase` | ODE: draw the system (or a 2nd-order equation as y, y') in the phase plane (`1`) | `phase=1` | | `axes` | ODE phase plane of a 3+-D system: the two state variables to plot | `axes=x,z` | | `family` | slider: draw 7 ghost solutions for values across `min`..`max` (`1`/`0`) | `family=1` | | `solver` | ODE integrator: `rk4` (default, fixed step), `auto` (adaptive RK45, switches to an implicit method when stiff), `rk45`, `euler` | `solver=auto` | | `steps`, `h` | ODE: draw the steps of `euler`, `heun` or `rk4` with step size `h` (0.001 to 100, default 0.5) over the solution | `steps=euler&h=0.25` | | `conditions`, `bc` | 2nd-order ODE: `conditions=boundary` solves y(a) = alpha, y(b) = beta by shooting, with `bc=a,alpha,b,beta` | `conditions=boundary&bc=0,0,1,2` | ### Graph params | param | meaning | example | | --- | --- | --- | | `xmin`, `xmax` | horizontal range (default -8 to 8) | `xmin=0&xmax=20` | | `ymin`, `ymax` | vertical centre/range, see "Viewport" below | `ymin=-2&ymax=2` | | `panels` | cross-section side panels: `none`, `right`, `bottom`, `both` (default both) | `panels=none` | | `markers` | `off` hides extrema/intercept/intersection dots | `markers=off` | | `sigfigs` | significant figures in labels, 1 to 12 (default 3) | `sigfigs=4` | | `grid` | `off` hides the grid lines and axes, for drawings | `grid=off` | | `equilibria` | `off` hides ODE equilibria (shown by default) | `equilibria=off` | | `aspect` | letterbox the plot to this width / height ratio | `aspect=2.39`, `aspect=16/9` | | `fps` | fixed, deterministic playback rate (1 to 240) | `fps=24` | | `time`, `frame` | open paused at this time (s) or frame (at `fps`, default 30); may follow any link | `frame=120` | | `example` | open a built-in example instead of an expression list (see "Built-in examples") | `example=cube` | | `script` | a Script mode program (JavaScript, percent-encoded; see "Script mode") | `script=circle(0,0,2)` | Numbers may be constants: `2pi`, `pi/2`, `sqrt(2)`, `-e`. ## Expression syntax Write plain text, not LaTeX. The horizontal axis is `x` (also called `t`), the vertical axis is `y`. Each block below is one complete graph, shown with what Fluxion understands each line as. Every block is checked by Fluxion's test suite. ### Functions ```fluxion y = sin(x) # function x^2 - 1 # function y = 3sin(2x) + e^(-x/4) # function y = ln(x) # function y = sqrt(abs(x)) # function y = |x - 1| + 2 # function P' = P(1 - P) # ode y = sin^2(x) # function y = arctan(x) # function y = floor(x) # function y = 1/(x - 1) # function ``` ### Piecewise functions and restrictions ```fluxion y = {x < 0: -x, x < 2: x^2} # function y = {x < 0: -x, x^2} # function y = {x > 1} # function y = x > 3 ? -x : x # function y = x^2 {0 < x < 2} # function y = sin(x) {-pi <= x <= pi} {y > 0} # function r = theta {0 < theta < pi} # polar (cos(t), sin(t)) {t < pi} # parametric x^2 + y^2 = 4 {y > 0} # implicit x^2 + y^2 < 9 {x > 0} # inequality ``` - Desmos-style braces. `{c1: a, c2: b, d}` is `a` where `c1` holds, else `b` where `c2` holds, else `d`; without the trailing else value it is undefined (not drawn) where no condition holds. `{c}` alone is 1 where `c` holds and undefined elsewhere. The ternary `c ? a : b` is the same thing. - Conditions: `<`, `<=`, `>`, `>=`, `=` (equality), `!=`, chains (`0 < x < 2`, `-1 <= x <= 1`), `and`, `or`. They may use sliders: `y = x {x < a}`. - Braces after an expression restrict where it's drawn; several braces combine with AND (`y = x^2, 0 < x < 2` also works). Functions use x (and `y` for their own value); polar curves `theta` (or `r`, `x`, `y`); parametric curves `t`; implicit curves and regions `x` and `y`; ODEs draw their solution only inside, e.g. `y' = y {0 < t < 3}`. - Piecewise values work anywhere an expression does: user functions `f(x) = {x < 0: 0, x}`, derived values, ODE right sides `y' = {t < 1: 1, 0}` (the step splits where the condition switches), nested braces. Edges and jumps are located exactly: a restricted curve ends on its bound and pieces are never joined by a vertical line. A bare expression means `y = ...`. Implicit multiplication works: `2x`, `3sin(x)`, `pi x`. Available functions: `sin cos tan sec csc cot`, inverses `asin`/`arcsin` (also `sin^-1(x)`) etc., hyperbolic `sinh cosh tanh` and inverses, `sqrt cbrt nthRoot(x, n) exp ln log` (`log` is natural; `log10`, `log2`, `log(x, b)`), `abs sign floor ceil round mod(x, m) min max hypot atan2 gamma factorial` (`x!`). Constants: `pi` (or `π`), `e`, `tau`, `phi`. Powers: `x^2`, `e^(-x)`, `2^-x`. ### Differential equations (ODEs) ```fluxion y' = -y # ode dy/dt = t - y # ode y'' = -y # ode y'' + 0.4y' + 4y = 0 # ode d^2u/dt^2 = -sin(u) # ode ``` - The independent variable is the horizontal axis, `t` (also called `x`). An ODE written only in x uses x: `dy/dx = x + y` and `y' = x*y` both work. If a row uses both x and t, t is the variable and x must be a slider. In a system, `x` can be an unknown (`x' = y`). - Any name can be the unknown function: `y`, `u`, `P`, `theta` (or `θ`). - Orders 1 to 10. Derivatives: `y'`, `y''`, `y'''`, `dy/dt`, `d^2y/dt^2`, `dy/dx`, `d^2y/dx^2`. The equation may be in any form that is linear in the highest derivative (`y'' + 0.4y' + 4y = 0` is fine). - Fluxion solves numerically (fixed-step RK4 by default; see `solver`) forward and backward from t0 across the whole visible x-range. - Initial conditions: type them after a comma (`y'' = -y, y(0) = 1, y'(0) = 0`) or on their own row (`y(0) = 1`), or set `ic` (params: `ic=2,0`; JSON: `"ic": [2, 0]`) as `[y(t0), y'(t0), ...]` and optionally `t0` (default 0). Typed conditions win over `ic`/`t0`. If you give none, Fluxion uses `y(t0) = 1` and zero for the higher derivatives. ```fluxion dy/dx = x + y, y(0) = 0 # ode y' = x*y # ode y'' = -y, y(0) = 1, y'(0) = 0 # ode ``` ```fluxion y' = -y + 2 # ode y(1) = a # condition a = 3 # variable ``` **Step and impulse forcing.** `H(t - a)` (also `u(t - a)` or `heaviside(t - a)`) is the unit step: 0 before a, 1 from a on. `delta(t - a)` is the Dirac impulse: it can't be plotted, so the solver applies it as a jump of the highest derivative at t = a (`y'' + y = delta(t - 1)` kicks y' by 1 at t = 1; a first-order `y' = -y + 2delta(t - 1)` makes y jump by 2). The argument must be linear in t; `delta(2(t - 1))` has weight 1/2. Steps and impulses split the integration step exactly where they act. ```fluxion y' = -y + H(t - 1), y(0) = 0 # ode y'' + 0.4y' + 4y = 2delta(t - 2) + u(t - 6) # ode ``` **Boundary-value problems (2nd order).** One condition at each end, `y(a) = alpha, y(b) = beta` (or `y'(b) = beta`), is solved by shooting on y'(a): typed after a comma or on their own row, or with `"conditions": "boundary", "bc": [a, alpha, b, beta]`. If every slope fits (an eigenvalue case such as `y'' = -y, y(0) = 0, y(pi) = 0`) the row reports "not unique"; if none does, "no solution". ```fluxion y'' = -y, y(0) = 0, y(pi/2) = 2 # ode ``` ```fluxion y'' = -lambda*y # ode y(0) = 0, y(1) = 1 # condition lambda = 2 # variable ``` **Numerics.** `solver` picks the integrator: `rk4` (default: fixed step, about one step per sample across the view), `auto` (Dormand–Prince RK45 with error control and dense output; switches to an implicit Rosenbrock method when the problem is stiff, e.g. `y' = -1000(y - cos(t))`), `rk45` (adaptive only) and `euler` (forward Euler, to compare). For teaching, `"steps": "euler"` (or `heun`, `rk4`) with `"h": 0.5` draws the method's discrete steps as dots over the accurate solution; tracing a step shows its global error |y_h - y|. Euler's error is O(h), Heun's O(h^2), RK4's O(h^4). ```json { "expressions": [{ "expr": "y' = y", "ic": [1], "steps": "euler", "h": 0.5 }, { "expr": "y' = -1000*(y - cos(t))", "solver": "auto", "ic": [0] }], "viewport": { "xmin": -1, "xmax": 3 } } ``` Coupled systems are written as one expression per equation; Fluxion detects the coupling and solves them together. Each unknown is plotted against t. (Shared t0 comes from the first equation.) ```fluxion x' = y # ode y' = -x - 0.2y # ode ``` ```fluxion x' = 10*(y - x) # ode y' = x*(28 - z) - y # ode z' = x*y - 8/3*z # ode ``` #### Using a solution elsewhere: y(T) Once a row defines an ODE in y, `y(T)` is the value of its solution at T, and `y'(T)` (up to the equation's order, e.g. `y''(T)` for a 2nd-order one) its derivatives. The value is the drawn solution: typed conditions, `ic`/`t0`, boundary values, `solver` and step / delta forcing all apply, and it works for any T, inside the view or not (up to 2000 from t0). Calls work in points and point variables, functions (`f = y(t)^2`, `y = 2*y(x)`), parametric curves (`(x(t), y(t))` of a system is its phase curve), derived values (live badge), regions and colour expressions. In a system each unknown is callable: `x(T)`, `z'(T)`. - Animate a slider `T` (`"anim": "loop"`, `"autoplay": true`) and `(T, y(T))` rides the curve; `(0, y(T))` moves a ball up and down. - Rows such as `y(0) = 2` (alone or after the ODE's comma) are still conditions, not evaluations. - A function you define with the same name (`w(s) = s^2` next to `w' = -w`) wins over the solution; `u(t - 1)` stays the unit step. - An ODE's own equation (or its conditions) can't read a solution value (`y'' = -y + y(1)` is an error); use the variable itself. ```fluxion y'' = -4*y, y(0) = 3, y'(0) = 0 # ode T = 1 # variable (T, y(T)) # points B = (0, y(T)) # pointvar E = y'(T)^2/2 + 2*y(T)^2 # function f = y(t)^2/3 # function ``` ```fluxion x' = -y, x(0) = 2 # ode y' = x, y(0) = 0 # ode (x(t), y(t)) # parametric ``` A ball on a damped spring, moved by the solution while T plays: https://osmansiddiquer.github.io/Fluxion/#expr=y''=-4y-0.2y',y(0)=3,y'(0)=0&expr=T=0&min=0&max=12&anim=loop&speed=0.33&autoplay=1&expr=(T,y(T))&color=red&size=12&xmin=-1&xmax=12 The `spring-ball` example hangs the ball from a coil spring (a parametric curve through `y(T)`) and shows the energy: https://osmansiddiquer.github.io/Fluxion/#example=spring-ball #### The qualitative picture: fields, phase plane, equilibria, families Fluxion shows these automatically when they apply; the options below turn them on or off. - **Slope field**: a first-order equation `y' = f(t, y)` can draw faint tangent segments of f on a grid behind its solution: off by default, `"field": true` (params `field=1`) turns it on. - **Phase plane**: `"phase": true` (params `phase=1`) on a 2-D system (`x' = ...`, `y' = ...`) or a 2nd-order equation (read as `y`, `y'`) plots the trajectory in state space: the axes become the state variables, a normalised vector field and the dashed nullclines (where each rate is 0) are drawn, and the solution is integrated over t0 - 30 .. t0 + 30. The side panels still show each component against t. For a 3-D system such as Lorenz, `"phaseAxes": ["x", "z"]` (params `axes=x,z`) picks the two variables. Only that system is drawn in state coordinates; other expressions keep their usual meaning (x across, y up), so `y = x` is a line in the same plane. In the phase plane the field is drawn at t = t0, and only by default when the system doesn't use t. - **Equilibria** of autonomous equations (no `t`) are marked and classified: for one first-order equation against t, as dashed lines y = c (stable, unstable or semi-stable from the sign of f on either side; higher-order equations show theirs only in the phase plane); in the phase plane, as points classified by the Jacobian's eigenvalues (node, saddle, spiral, centre, degenerate; filled = stable, hollow = unstable, half-filled = saddle). Hide them with `"features": {"equilibria": false}` (params `equilibria=off`). - **Extra solutions**: `"extraICs": [[t0, y0, ...], ...]` (the whole state at t0) adds solutions drawn thinner in the same colour, without new rows. In the app, shift-click the plot to add one and drag the ring at (t0, y0) to move the initial condition. JSON only (no params form). - **Families**: `"family": true` on a slider (params `family=1`) draws 7 ghost curves for values spread across its `min`..`max`, for every function and ODE that uses it, in a pale-to-full ramp of each curve's colour. A logistic equation with its slope field, equilibria y = 0 (unstable) and y = 1 (stable), and two extra solutions: https://osmansiddiquer.github.io/Fluxion/#spec=%7B%22expressions%22:%5B%7B%22expr%22:%22y'%20=%20y*(1%20-%20y)%22,%22ic%22:%5B0.1%5D,%22field%22:true,%22extraICs%22:%5B%5B0,1.6%5D,%5B0,-0.05%5D%5D%7D%5D,%22viewport%22:%7B%22xmin%22:-4,%22xmax%22:6%7D%7D A predator-prey (Lotka-Volterra) phase portrait: a saddle at the origin, a centre at (1, 1), closed orbits: https://osmansiddiquer.github.io/Fluxion/#expr=x'=x*(1-y)&phase=1&ic=2&expr=y'=y*(x-1)&ic=1&xmin=-1&xmax=4 The damped pendulum in the phase plane, and a family over the damping: https://osmansiddiquer.github.io/Fluxion/#expr=c=0.3&min=0&max=1.5&family=1&expr=y''=-sin(y)-c*y'&ic=2,0&phase=1&xmin=-7&xmax=7 ```json { "expressions": [ { "expr": "x' = x*(1 - y)", "phase": true, "ic": [2], "extraICs": [[0, 1.5, 1], [0, 3, 1]] }, { "expr": "y' = y*(x - 1)", "ic": [1] } ], "viewport": { "xmin": -1, "xmax": 5 }, "features": { "equilibria": true } } ``` ### Sliders (variables) Any `name = number` becomes a slider that other expressions can use. Every name you use must be defined (or be `x`, `y`, `t`, `r`, `theta`, or a constant). ```fluxion k = 2 # variable w = 2pi # variable y = k*sin(w*x) # function y' = -k*y # ode ``` Set the slider range with `min`, `max`, `step` (default range: -10 to 10, widened to include the value). ### Implicit curves Any other equation in x and y is drawn as the curve where it holds. ```fluxion x^2 + y^2 = 9 # implicit x = 2 # implicit x = y^2 - 3 # implicit x^2/9 + y^2/4 = 1 # implicit y^2 = x^3 - x # implicit ``` ### Polar curves `r = f(theta)`; write `theta` or `θ`. The default sweep is 0 to 2pi; set `thetamin`/`thetamax` (params) or `thetaMin`/`thetaMax` (JSON) for spirals. ```fluxion r = 2 + 2cos(theta) # polar r = θ/2 # polar r = sin(4θ) # polar ``` ### Inequalities (shaded regions) Use `<`, `>`, `<=`, `>=` (or `≤`, `≥`). Chains like `1 < y < 2` work, and `&` joins conditions (write it as `%26` inside a params link). Polar regions use `r` and `theta`. ```fluxion y < sin(x) # inequality x^2 + y^2 <= 9 & y > 0 # inequality -1 < x < 1 # inequality r < 1 + cos(θ) # inequality ``` ### Points and segments ```fluxion (1, 2) # points [(0, 0), (1, 1), (2, 4)] # points ((0, 0), (2, 1), (4, 0)) # points A = (a, 1) # pointvar a = 2 # variable B = (-1, -2) # pointvar (A, B) # points ``` `(x, y)` is a point, `[(...), (...)]` a list of points, `((...), (...), ...)` a connected polyline, `A = (x, y)` a named point (draggable when its coordinates are sliders), and `(A, B)` the segment between two named points. Points accept `label`, `labeldir`, `size` and `drag`. `A.x` and `A.y` are the coordinates of a named point `A`, usable in any expression: other points (in any order; a cycle is an error), functions, derived values, parametric/implicit/polar curves, regions, restrictions, user functions, colour expressions and ODE equations. They follow A when it is dragged or animated, also when A's coordinates call an ODE solution like `X(T)`. ```fluxion a = 2 # variable A = (a, 1) # pointvar B = (A.x + 1, A.y) # pointvar ((A.x, 0), (B.x, B.y)) # points y = (x - A.x)^2 + A.y # function d = sqrt(A.x^2 + A.y^2) # function (A.x + cos(t), A.y + sin(t)) # parametric y < A.y {x < A.x} # inequality ``` A point riding on an ODE solution, with a circle around it: https://osmansiddiquer.github.io/Fluxion/#expr=X''=-1.8X-0.5X'&ic=4,0&expr=T=0&min=0&max=20&autoplay=1&expr=center=(X(T)+4,2)&expr=(center.x+0.5cos(t),center.y+0.5sin(t))&expr=y=center.y&xmin=-2&xmax=12 ### Parametric curves, definitions and repeats (drawings and animation) `(x(t), y(t))` is a parametric curve; `t` runs over `thetaMin`..`thetaMax` (default 0 to 2pi). ```fluxion (3cos(t), 2sin(t)) # parametric (cos(3t), sin(2t)) # parametric ``` `f(u, v) = ...` defines a function you can call anywhere (a one-parameter `f(x) = ...` is also drawn). `name = expression` without `y` is a derived value that updates live. Order doesn't matter. ```fluxion a = 1 # variable f(u) = u^2 - a # fndef y = f(x) - 1 # function b = 2a + 1 # function y = b # function ``` `body for k = a..b` draws any curve, point, polygon or region once per value of `k` (`for i = 0..3, j = 0..3`, `for k = 0..10 step 2`, at most 2000 copies; a repeated region is the union). ```fluxion (cos(t) + 3k, sin(t)) for k = -1..1 # repeat (k, k^2/4) for k = -4..4 # repeat (x - 3k)^2 + y^2 < 1 for k = -1..1 # repeat ``` Animation: give a slider `"anim"` and `"autoplay": true`, then drive everything from it. `keys(T, t0, v0, t1, v1, ...)` is a keyframe track (held before the first and after the last key; `skeys` eases each span); also `lerp(a, b, u)`, `clamp(x, lo, hi)`, `smoothstep(e0, e1, x)`, `ease(u)`, `step(x)`, `pulse(x, a, b)`, 2D rotation `rotx(x, y, angle)`/`roty(x, y, angle)`, and 3D projection `projx(x, y, z, yaw, pitch, dist)`/`projy(...)` (dist = camera distance; 0 = orthographic). ```fluxion T = 1 # variable s = skeys(T, 0, 1, 2, 3) # function (s*cos(t), s*sin(t)) # parametric (rotx(2, 0, T), roty(2, 0, T)) # points ``` Style options (JSON spec): `lineWidth` (px, 0 hides the line), `lineStyle` (`solid`, `dashed`, `dotted`), `fill` and `fillOpacity` for closed shapes, and `colorExpr` / `fillColor`: colour expressions over sliders, `rgb(r, g, b)` (0 to 255), `rgba(r, g, b, a)`, `hsv(h, s, v)`, `hsl(h, s, l)` (h in degrees, the rest 0 to 1) or `"#rrggbb"`. Set `"features": {"grid": false}` for a clean canvas. A rotating 3D cube: ```json { "expressions": [ { "expr": "a = 0", "min": 0, "max": "2pi", "anim": "loop", "speed": 0.5, "autoplay": true }, "X(p, q, w) = 3projx(p, q, w, a, 0.5, 6)", "Y(p, q, w) = 3projy(p, q, w, a, 0.5, 6)", { "expr": "((X(-1,-1,k), Y(-1,-1,k)), (X(1,-1,k), Y(1,-1,k)), (X(1,1,k), Y(1,1,k)), (X(-1,1,k), Y(-1,1,k)), (X(-1,-1,k), Y(-1,-1,k))) for k = -1..1 step 2", "lineWidth": 3, "fill": true, "fillOpacity": 0.15, "colorExpr": "hsv(57*a, 0.7, 0.85)" }, { "expr": "((X(i,j,-1), Y(i,j,-1)), (X(i,j,1), Y(i,j,1))) for i = -1..1 step 2, j = -1..1 step 2", "lineWidth": 3, "lineStyle": "dashed", "color": "blue" } ], "viewport": { "xmin": -8, "xmax": 8 }, "features": { "grid": false }, "panels": { "right": false, "bottom": false } } ``` ### Common mistakes Each line shows something that fails, then what to write instead. (The suite checks that the left side fails and the right side works.) ```pitfalls y' = x*t*y => y' = t^2*y y'' = y, y(0) = 1, y(0) = 2 => y'' = y, y(0) = 1, y'(0) = 2 y = sin(πx) => y = sin(pi*x) y = P(2) => y = P*2 ; P = 3 y = k*x for k = 1..n => y = k*x for k = 1..3 y = a*x^2 => y = a*x^2 ; a = 1 y = sin x => y = sin(x) y = x^2 if x > 0 => y = x^2 {x > 0} y = {x < 0: -x, 0: x} => y = {x < 0: -x, x} y = A_x => A = (1, 2) ; y = A.x ``` - `πx` is read as one name, `pix`. Put an operator or a space between: `pi*x`, `pi x`, `2pi`. - A bracket after a slider, after `x`/`t`, or after an ODE's own variable inside its equation multiplies, Desmos-style: `a(x + 1)`, `x(x + 1)`, `P' = P(1 - P)`. Elsewhere `name(…)` is a call: a user function, a built-in, or an ODE solution value like `y(2)` (so an undefined `P(2)` is an unknown function). - Functions need parentheses: `sin(x)`, not `sin x`. - Absolute value: `|x|` or `abs(x)`. For piecewise definitions use braces, `y = {x < 0: 0, x}`, and restrict with a trailing `{0 < x < 2}`. Every piece but the last needs a condition. - Don't reuse built-in names (`e`, `pi`, `tau`, `phi`, `i`, `t`, `x`, `y`, `r`, `theta`) as slider names. - A point's coordinates are `A.x` and `A.y` (not `A_x`, which is a separate name). Only a named point has them: `k.x` on a slider is an error. - LaTeX is converted when it can be, but plain text is more reliable. ## Script mode (JavaScript drawings and animation) For drawings, diagrams and animation, a graph can carry a **script**: JavaScript using Fluxion's drawing API, drawn on the same axes as the expressions (so pan and zoom still work). The app has a Graph | Script switch; a link with a script opens in Script mode, with the code in an editor beside the canvas. Scripts run in a sandbox (a Web Worker in an opaque-origin iframe, no network): they can draw, nothing else. Prefer a script over expression rows for anything with many shapes, colour, motion or 3D. The script is the body of one function, run top to bottom. It re-runs every frame (animates) when its code mentions `time` or `frame` outside comments and quoted strings, or when it calls `loop()` or `clip(...).play()`; otherwise it runs once per edit. Every name below is built in; no imports. Coordinates are graph units, sizes in style objects are pixels. - Shapes: `circle(x, y, r)`, `ellipse(x, y, rx, ry)`, `rect(x, y, w, h)` (bottom-left corner), `polygon(points)`, `polyline(points)`, `line(x1, y1, x2, y2)`, `arrow(x1, y1, x2, y2)`, `point(x, y)`, `arc(x, y, r, a0, a1)` (clockwise when a1 < a0), `text(s, x, y)`, `label(s, x, y)`, `path().moveTo(x, y).lineTo(x, y).quadTo(cx, cy, x, y).bezierTo(c1x, c1y, c2x, c2y, x, y).arc(cx, cy, r, a0, a1, ccw?).close()` (a first `lineTo` acts as `moveTo`), `curve(t => [x, y], t0 = 0, t1 = 2π)`, `plot(x => y)` (across the visible x-range; values over 50 view-heights off screen leave a gap, which breaks most asymptotes), `background(color)`. Points are `[[x, y], ...]`, a flat `[x0, y0, x1, y1, ...]` or `{ x, y }` objects; a `NaN` point breaks the line. Every shape takes a style object as its last argument; `curve` needs its t-range first. - Style: `{ color, fill, width, dash, opacity, cap, join }`. `color` is the outline (alias `stroke`; `null`, `false` or `"none"` for none). `fill` is a colour, a gradient, `true` (the outline colour) or `"none"`; fill only means no outline. `width` defaults to 2 px. `dash` is `"dashed"`, `"dotted"` or a px pattern like `[8, 4]`. `opacity` 0 to 1. `cap` is `"round"` (default), `"butt"` or `"square"`; `join` is `"round"` (default), `"miter"` or `"bevel"`. - Shape-specific style keys: `radius` (rect corner, graph units), `head` (arrow head px, default 10 + 1.5 × width), `size` (point radius px, default 4; text px, default 16, label 13), `stroke` on a point (an outline round the dot), `samples` (curve default 240, plot 600; clamped to 2 to 5000), `closed: true` (curve), and `x`, `y`, `width`, `height` (clip centre and size in graph units). - Text options (`text` and `label`): `size`, `bold: true`, `align` (`"left"`, `"center"`, `"right"`), `baseline` (`"top"`, `"middle"`, `"bottom"`, `"alphabetic"`), `font` (`"sans"`, `"serif"`, `"mono"`), `halo: true`; `color` is the text colour. `text` defaults to centred and middle; `label` to left / bottom with a halo, beside a point. Numbers print to 6 significant figures; text turns with `rotate`. - Gradients (as a `fill`): `linearGradient(x0, y0, x1, y1, colors)` / `radialGradient(x, y, r, colors)`. `colors` is a list spread evenly or `[offset, color]` pairs, up to 16 stops. The coordinates follow the current transform. - Colour: CSS strings, `rgb(r, g, b, a?)` (0 to 255), `hsv(h, s, v, a?)`, `hsl(h, s, l, a?)` (h in degrees), `mix(c1, c2, t)`, `alpha(c, a)`. `mix` and `alpha` also read `"hsv(...)"` / `"hsl(...)"` / `"rgb(...)"` strings. - Transforms: `group({ translate: [x, y], rotate, scale, origin: [x, y] }, () => { ... })` (`scale` a number or `[sx, sy]`; shapes are scaled, then rotated, both around `origin`, then translated), `group(() => { ... })` without options, or `push()`, `translate(x, y)`, `rotate(angle, cx?, cy?)`, `scale(sx, sy?)`, `pop()`. - Animation: `time` (seconds), `frame` (`floor(time * 60)`), `loop(seconds)`, `lerp(a, b, t)`, `clamp(x, lo = 0, hi = 1)`, `map(x, a, b, c, d)`, `ease(t, "inOut" | "in" | "out" | "linear")` (default `"inOut"`), `smoothstep(e0, e1, x)`, `keyframes(t, [[t0, v0], [t1, v1], ...], { ease: "smooth" | "linear" })` (values may be numbers, arrays or colours; held flat outside the keys; `"smooth"` is the default, `false` also means linear). - Inputs: `slider(name, min = 0, max = 1, value = min, step?)` returns the value and shows a real slider. The name starts with a letter, `_` or `$`, then letters, digits, `_`, `$` or spaces (up to 32 characters); the same name returns the same slider; at most 32 sliders. - Maths: `sin cos tan asin acos atan atan2 sinh cosh tanh sqrt cbrt abs sign floor ceil round trunc min max pow exp log log2 log10 hypot`, `mod(x, m)` (never negative), `PI`, `TAU`, `E`, `range(n)` / `range(a, b, step)`, `rand(seed)` (stable 0 to 1), `random()`. `log` is the natural log, not console output. - 3D: `camera({ yaw, pitch, dist, scale })` with `.point(p)`, `.line(a, b)`, `.polyline(points)`, `.polygon(points)`, `.project(p)`, `.depth(p)`; or `project3d([x, y, z], { yaw, pitch, dist, scale })`. - Graph mode: `graph.ode("y")(t)` is the solution of the graph's ODE for `y` at any t (`graph.ode("y", 1)` its derivative), `graph.fn("f")(x)` a graph function, `graph.value("k")` a slider value, `graph.has(name)`, `graph.names()` (every readable name). - Clips: `clip(name)` gives `.play(style?)` (the frame for `time`), `.draw(frame, style?)`, `.frameAt(seconds)`, `.name`, `.frames`, `.fps`, `.duration` (seconds), `.box` (`[xmin, ymin, xmax, ymax]`). Up to 8 clips. Clips are imported in the app; share links and graph files carry them, JSON specs don't. - Also: `view` (`xmin`, `xmax`, `ymin`, `ymax`), `theme`, `ink` (default colour), `print(...)` / `console.log(...)` (also `.info`, `.warn`, `.error`, `.debug`). A complete script (dots orbiting, with a slider): ```fluxion-script // Coloured dots orbiting, with a slider for how many. const n = slider("dots", 3, 24, 12, 1) loop(6) for (const k of range(n)) { const q = time / 6 * TAU + k * TAU / n circle(3 * cos(q), 3 * sin(q), 0.35, { fill: hsv(360 * k / n, 0.7, 0.95) }) } ``` Give it a name and a helper function for anything you draw more than once: ```fluxion-script // Three tomoe on a red iris. function tomoe(angle, size) { group({ translate: [1.25 * cos(angle), 1.25 * sin(angle)], rotate: angle }, () => { path({ fill: "#120a0a" }) .arc(0, 0, 2 * size, PI / 2, -PI / 2) .arc(0, -size, size, -PI / 2, PI / 2) .arc(0, size, size, -PI / 2, -3 * PI / 2) .close() }) } circle(0, 0, 2, { fill: "#b3121b", color: "#2a0505", width: 3 }) circle(0, 0, 0.42, { fill: "#0b0b0b" }) for (const k of range(3)) tomoe(-time + k * TAU / 3, 0.22) ``` Put a script in a link as the `"script"` string of a JSON spec (then `#spec=` or `#z=` as usual); `expressions` is optional when there is a script. Scripts can read the expressions, e.g. a pendulum driven by an ODE: ```json { "expressions": [{ "expr": "theta'' = -sin(theta) - 0.15theta'", "ic": [2, 0] }], "script": "const a = graph.ode(\"theta\")(time)\nline(0, 2, 3 * sin(a), 2 - 3 * cos(a), { width: 3 })\ncircle(3 * sin(a), 2 - 3 * cos(a), 0.3, { fill: \"#c74440\" })", "viewport": { "xmin": -6, "xmax": 6 } } ``` The orbit example above as a compressed link: https://osmansiddiquer.github.io/Fluxion/#z=NYzBTsMwEER_ZbQnp1hN20ARkXpA_AKcMIc0cRKr7m5quxQU5d9R2nJZjebN25HszxBsjE44Uvn5pSnWwQ2JSspzvImXc7ANGkkREvYuOe40Li71qBC9a2xAKwG9XHCs-HdpuBaOCYzdnStDs25Io9DYPGqsNxrrzLAXGdQ2Mzx_UDfvAGkRKu6s4izDaBi4kRN2SO5okWOLBd5fP_CAwz3l4OvShdpbVWCBWqI6ZRpzjo6vebUsnjRGtM77En38VsV2hQUOsz_j5_m8PGWYMsOTYdLU2iqdg41UjtQF11DZVj7aSdNQsfXXPriuT3egaS8pyfF_N_0B A short script also fits a params link (`script=`, percent-encoded; `&` as `%26`): https://osmansiddiquer.github.io/Fluxion/#script=circle(0,%200,%202,%20%7B%20fill:%20%22tomato%22%20%7D) Script pitfalls: it is JavaScript, so write `x * y` (no implicit multiplication), `**` or `pow` for powers, and `Math`-style names (`sqrt`, `PI`). Angles are radians. Keep a frame under a few milliseconds (over 40 ms shows a "slow" badge), and use one `polyline` instead of thousands of `point`s. A run or edit that takes over 3 s, or one animation frame over 1.5 s (an endless loop), is stopped. Script limits per frame: 20,000 shapes; about 300,000 points (600,000 numbers); 300 characters per text (cut off); 100 console lines of up to 1,000 characters; 32 sliders with names up to 32 characters; 8 clips; 16 gradient stops; 8 dash entries; `width`, `size` and `head` at most 400 px; 256 nested `push()`; `range` up to 1,000,000 values. Coordinates beyond ±1e9 (or `NaN`) are dropped silently (the shape is skipped, or the line gets a gap). Going over the shape, point, slider, nesting or range limit stops the frame with an error. Check a script with `npm run fluxion -- script file.js` (see "Checking a graph"). ## JSON spec For full control (initial conditions, slider ranges, panels, markers) use a JSON spec. JSON Schema: https://osmansiddiquer.github.io/Fluxion/fluxion-spec.schema.json ```json { "version": 1, "expressions": [ "y = sin(x)", { "expr": "y'' = -0.3y' - sin(y)", "ic": [2, 0], "t0": 0, "color": "red" }, { "expr": "k = 1.5", "min": 0, "max": 3, "step": 0.1, "anim": "bounce" }, { "expr": "r = 1 + k*cos(theta)", "thetaMin": 0, "thetaMax": "2pi", "hidden": false }, { "expr": "A = (k, 1)", "label": "A", "labelDir": "ne", "pointSize": 7 } ], "viewport": { "xmin": -6, "xmax": 6, "ymin": -4, "ymax": 4 }, "features": { "extrema": true, "xIntercepts": true, "yIntercept": true, "endpoints": false, "discontinuities": true, "intersections": false }, "panels": { "right": false, "bottom": false, "sliceX": 0, "sliceY": 1 }, "sigFigs": 3 } ``` - Only `expressions` is required (or `script`, see "Script mode"). An expression is a string, or an object with `expr` plus options: `color`, `hidden`, `t0`, `ic`, `min`, `max`, `step`, `anim`, `speed`, `autoplay`, `thetaMin`, `thetaMax`, `label`, `labelDir`, `pointSize`, `drag`, `lineWidth`, `lineStyle`, `fill`, `fillOpacity`, `colorExpr`, `fillColor`, `samples`, `dots`, `blend`, `glow`, `blur`, `layer`, and for ODEs and sliders `field`, `phase`, `phaseAxes`, `extraICs`, `family`. Top level, besides `expressions`: `viewport`, `features`, `panels`, `sigFigs`, `script`, and for animations `aspect`, `fps`, `time`, `frame`. - `color`: `"#rrggbb"`, `"#rgb"` or a palette name. Without one, colours are assigned from the palette in order. - Numbers may be given as constant strings: `"2pi"`, `"-pi/2"`, `"sqrt(2)"`. - `features` turns marker families on/off, `grid` the grid lines and axes, and `equilibria` the ODE equilibria. `panels.sliceX` / `panels.sliceY` position the cross-section cursors; they may be a slider expression like `"k"`. - Validation is strict: unknown keys, wrong types and out-of-range values are rejected with a message naming the field (and "did you mean ...?"). A link with an invalid spec shows that message instead of a graph. ### Putting a JSON spec in a link Readable (percent-encode the JSON, e.g. with `encodeURIComponent`): https://osmansiddiquer.github.io/Fluxion/#spec=%7B%22expressions%22%3A%5B%22y%20%3D%20x%5E2%22%2C%7B%22expr%22%3A%22y'%20%3D%20-y%22%2C%22ic%22%3A%5B3%5D%7D%5D%7D Base64url of the JSON (`#spec=` also accepts this, standard base64 too): https://osmansiddiquer.github.io/Fluxion/#spec=eyJleHByZXNzaW9ucyI6WyJ5ID0geF4yIix7ImV4cHIiOiJ5JyA9IC15IiwiaWMiOlszXX1dfQ Compressed, shortest (raw DEFLATE, then base64url, no padding): https://osmansiddiquer.github.io/Fluxion/#z=PctLCoMwFIXhrYQzsS1XCZZOLrgScaA2bQOaSBJsQLIvV-Gain0Nf75zFqg4OeW9tsaD6-XdYGxrlolK5N1pWzORC6_NYVuPIOgeXJfFhWRD6O1g97lTVyT6vztRCVmcQRi1AUvC2EZwmRrCrNVzsi6AF8Qfx4_LRJhaowa_q9P3RwDf2sErQmdDsOM3U3oB Python: ```python import base64, json, zlib def fluxion_link(spec: dict) -> str: c = zlib.compressobj(9, zlib.DEFLATED, -15) # -15 = raw DEFLATE data = c.compress(json.dumps(spec).encode()) + c.flush() z = base64.urlsafe_b64encode(data).decode().rstrip("=") return "https://osmansiddiquer.github.io/Fluxion/#z=" + z print(fluxion_link({"expressions": ["y' = -y", "y = e^(-x)"]})) ``` JavaScript (browser, Deno, Node 18+): ```javascript async function fluxionLink(spec) { const bytes = new TextEncoder().encode(JSON.stringify(spec)); const stream = new Blob([bytes]).stream().pipeThrough(new CompressionStream("deflate-raw")); const z = new Uint8Array(await new Response(stream).arrayBuffer()); let bin = ""; for (const b of z) bin += String.fromCharCode(b); const b64 = btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); return "https://osmansiddiquer.github.io/Fluxion/#z=" + b64; } ``` ## Built-in examples (templates for drawings and animation) Fluxion ships example scripts (Script mode programs). Open one as-is with `#example=`, or start from its JSON spec: fetch it, edit its `"script"` (colours, sizes, speeds, shapes), then put it in a link as shown above. They are the best reference for Script mode: helper functions, `group` transforms, `keyframes`, `loop`, `camera` 3D, `hsv` colours and `graph.ode`. A machine-readable list is at https://osmansiddiquer.github.io/Fluxion/examples/index.json. | id | what it is | open | JSON spec | | --- | --- | --- | --- | | `sharingan` | Rotating Sharingan | https://osmansiddiquer.github.io/Fluxion/#example=sharingan | https://osmansiddiquer.github.io/Fluxion/examples/sharingan.json | | `cube` | Rotating cube | https://osmansiddiquer.github.io/Fluxion/#example=cube | https://osmansiddiquer.github.io/Fluxion/examples/cube.json | | `mangekyo` | Eye → Sharingan → Mangekyō | https://osmansiddiquer.github.io/Fluxion/#example=mangekyo | https://osmansiddiquer.github.io/Fluxion/examples/mangekyo.json | | `mandala` | Mandala bloom | https://osmansiddiquer.github.io/Fluxion/#example=mandala | https://osmansiddiquer.github.io/Fluxion/examples/mandala.json | | `pendulum` | Pendulum from an ODE (`graph.ode`) | https://osmansiddiquer.github.io/Fluxion/#example=pendulum | https://osmansiddiquer.github.io/Fluxion/examples/pendulum.json | | `silhouette` | Silhouette clip | https://osmansiddiquer.github.io/Fluxion/#example=silhouette | link only (carries a frame clip) | | `sunset` | Cinematic sunset (Graph mode: gradients, layers, splines, letterbox) | https://osmansiddiquer.github.io/Fluxion/#example=sunset | https://osmansiddiquer.github.io/Fluxion/examples/sunset.json | | `impulse` | Spring hit by a hammer (Graph mode: `delta` forcing, inline initial conditions, sliders) | https://osmansiddiquer.github.io/Fluxion/#example=impulse | https://osmansiddiquer.github.io/Fluxion/examples/impulse.json | | `spring-ball` | Ball on a spring (Graph mode: the solution called as `y(T)` moves a ball while the clock plays) | https://osmansiddiquer.github.io/Fluxion/#example=spring-ball | https://osmansiddiquer.github.io/Fluxion/examples/spring-ball.json | Tips for your own drawings, learned from these: - In a script: one `loop(seconds)` clock and values derived from `time` (`keyframes`, `lerp`) keep everything in sync; for a seamless loop make everything return to its start at the end. - Name your shapes: `function petal(length, width, angle) { group({ rotate: angle }, () => curve(...)) }`, then call it in a `for` loop. With expression rows instead of a script: - One clock slider (`T = 0` with `"anim": "loop"`, `"autoplay": true`) and derived values from it (`s = skeys(T, ...)`, `w = pi T/6`) keep everything in sync. For a seamless loop, make every quantity return to its start value at the end of the clock's range. - Define a shape once as a function (`Px(u, L, W) = ...`) and place copies with `(rotx(Px(t, ...), Py(t, ...), angle), roty(...)) for k = 0..11`. - A compound radius needs explicit multiplication: `((0.5 + 0.1 sin(w))*cos(t), (0.5 + 0.1 sin(w))*sin(t))`. - Colours: `colorExpr` for the line, `fillColor` with `"fill": true` for the inside, and `"lineWidth": 0` for a borderless fill. ## Animation & performance (for agent-animators) Fluxion is an ODE plotter first, but everything below makes it a good place to render animations too. All of it is optional: nothing changes for a graph that doesn't use it. **Speed you get for free.** Each expression is compiled once to native code. A sub-expression that doesn't depend on `t`, `x`, `y`, `r` or `theta` (a drift term like `mod(T*0.4 + 3k, 48)`) is computed once per copy per frame, not once per sample, and a term that appears twice is computed once. Shapes whose bounds are entirely off-screen (or behind the letterbox bars) are skipped before sampling. So write the natural formula: there's no need to pre-compute, flatten or inline anything. **Your own levers.** - `samples` sets an expression's resolution (8 to 20000): raise it for a smooth hero shape, lower it (say 48) for a sky full of soft clouds. Defaults: parametric curves 480 per 2π, functions about 1.5 per pixel. - `expr where a = ..., b = ...` defines locals for one row (later ones may use earlier ones and the loop variable), instead of pasting the same formula several times. - `spline((x0, y0), (x1, y1), ...)` is a smooth curve through points (closed and smooth if the last point equals the first). Inside a polyline, `spline(...)` runs smoothly from the previous point, `bezier((c1), (c2), (end))` / `bezier((c), (end))` and `arc((cx, cy), angle)` continue from it, so a silhouette can mix sharp corners and curves. Send 10 control points, not 300 pre-subdivided ones. - In a `for` repeat, colour expressions may use the loop variable: one row `... for k = 0..21` with `"fillColor": "hsv(210, 0.4 + k/40, 1)"` gives 22 differently coloured copies. ```fluxion T = 0 # variable (s*cos(t) + d, 0.6s*sin(t) + 4) where s = 1.2, d = mod(T + 3k, 30) - 15 for k = 0..3 # repeat spline((-6, -3), (-3, 0), (0, -1), (3, 1), (6, -3)) # points ((-2, -4), (0, 0), spline((1, 1), (2, 0.5)), bezier((3, -1), (2, -3), (1, -4)), (-2, -4)) # points ((3, 0), arc((0, 0), pi), (-3, -1)) # points far = layer(-0.2T, 0) # layer camera = layer(0.05sin(40T), 0) # layer ``` **Cinematic rendering.** - Gradients are colour expressions: `linear(x0, y0, x1, y1, c0, c1, ...)` (colours evenly spaced, or `offset, colour` pairs) and `radial(cx, cy, r, c0, c1, ...)`, in graph coordinates. A sky is one rectangle with `"fillColor": "linear(0, 9, 0, -9, #0b1d3a, #f28c38)"`; a sun glow is one disc with a `radial(...)` fading to `rgba(..., 0)`. - `"blend"`: `add` (light adds up: god-rays, flashes), `screen` (soft light), `multiply`, `overlay`, `lighten`, `darken`. `"glow"` / `"blur"`: radius in px (0 to 50; use on a few shapes, not on 2000 copies). - Layers: a row `name = layer(dx, dy, scale, angle, cx, cy)` (only dx, dy required; scale and rotation are about (cx, cy)) and `"layer": "name"` on expressions. Members are moved by the layer's transform at draw time (moving a layer never re-samples anything) and are drawn at the layer row's position in the list, so the row order is the z-order. A layer named `camera` moves everything: `camera = layer(0.05sin(40T), 0)` is a screen shake. Shapes on a layer aren't traceable by hover. - `"aspect": 2.39` (or `"16/9"`) letterboxes the plot to that frame with black bars; xmin..xmax spans the frame exactly, so frame N looks the same on every screen. Don't draw bars as geometry. **Time.** Drive everything from one clock slider `T` with `"anim": "loop", "autoplay": true` (speed 1 sweeps the slider's range in 4 s, so for T in seconds over 0..60 use `"speed": 0.0667`). - `"fps": 24` makes playback deterministic: sliders advance in whole frames, and frame N is a pure function of N (no drift from irregular browser frames). - `"time": 2.5` or `"frame": 60` opens the graph paused at that moment (every autoplay slider set to its value then). `&frame=N` or `&time=s` can also be appended to any link (`#z=...&frame=120`, `#expr=...&time=2`). - Headless capture: browsers throttle background tabs to about 1 fps, so don't record by waiting. Load the link with `&frame=N` per frame, or in the page call `await fluxion.setFrame(n)` (or `setTime(seconds)`), which resolves after the redraw, then `fluxion.capture()` for a PNG data URL. `fluxion.info()` gives the fps, aspect and animated sliders. Graph-mode sliders only; Script mode has its own clock. A complete little scene (open it, then press nothing: it plays): ```json { "expressions": [ { "expr": "T = 0", "min": 0, "max": 60, "anim": "loop", "speed": 0.0667, "autoplay": true }, { "expr": "((-16, -9), (16, -9), (16, 9), (-16, 9))", "fill": true, "fillOpacity": 1, "lineWidth": 0, "fillColor": "linear(0, 9, 0, -9, #0b1d3a, #f28c38)" }, { "expr": "(2.5cos(t) + 6, 2.5sin(t) + 2)", "fill": true, "fillOpacity": 1, "lineWidth": 0, "fillColor": "radial(6, 2, 2.5, rgba(255, 240, 200, 1), rgba(255, 170, 80, 0))", "blend": "screen" }, "far = layer(-0.1*T, 0)", { "expr": "(1.5cos(t) + 4k - 12, 0.6sin(t) + 5) for k = 0..6", "layer": "far", "fill": true, "fillOpacity": 0.9, "lineWidth": 0, "fillColor": "hsv(210, 0.05*k, 1)", "samples": 64 }, { "expr": "spline((-16, -9), (-10, -4), (-4, -6), (2, -3), (8, -6), (16, -9))", "fill": true, "fillOpacity": 1, "lineWidth": 0, "color": "#000000" }, { "expr": "(t, 0.4sin(3t - 4T) - 1)", "thetaMin": -2, "thetaMax": 1, "lineWidth": 5, "glow": 12, "colorExpr": "#ff3b30" } ], "viewport": { "xmin": -16, "xmax": 16, "ymin": -9, "ymax": 9 }, "features": { "grid": false, "extrema": false, "xIntercepts": false, "yIntercept": false, "intersections": false }, "panels": { "right": false, "bottom": false }, "aspect": 2.39, "fps": 24 } ``` The same Lissajous animation opened paused at t = 1.5 s: https://osmansiddiquer.github.io/Fluxion/#expr=a=0&min=0&max=2pi&anim=loop&autoplay=1&expr=(3cos(t),2sin(3t+a))&width=3&grid=off&markers=off&panels=none&time=1.5 ## Checking a graph before you send it There is no server to call, so Fluxion can't validate a link for you remotely. Check your expressions against the syntax above. In particular, every name must be defined, ODEs use t, and you need explicit `*` before parentheses. If you can run code inside a clone of the repository (https://github.com/Osmansiddiquer/Fluxion), the CLI uses the app's real parser: ```bash npm ci npm run fluxion -- check '{"expressions":["y = a*x^2"]}' # JSON report; exit 1 on errors npm run fluxion -- link --expr "y'' = -y" --ic 1,0 --xmin 0 --xmax 10 npm run fluxion -- decode 'https://osmansiddiquer.github.io/Fluxion/#z=...' npm run fluxion -- examples # built-in demos and their links npm run fluxion -- example cube > cube.json # a demo's JSON spec, to edit npm run fluxion -- script orbit.js --time 0,1,2.5 # run a script headlessly: errors (with lines) and what it drew npm run fluxion -- script pendulum.js --spec spec.json # ... reading that spec's expressions via graph.ode / graph.value ``` `check` and `link` also run a spec's `"script"` (sandboxed, with a time limit) and report its errors with line numbers. `check` reports how each expression was understood (e.g. "2nd-order ODE in y(t)", "slider k = 2", "shaded region"), plus errors (unparseable, unknown function, undefined variable) and warnings (options that don't apply, nothing visible in the viewport). ## Viewport - `xmin`/`xmax` are honoured exactly. Fluxion always keeps x and y at the same scale (a square grid, so circles stay round). The visible y-range is therefore set by the window shape, centred on `(ymin + ymax) / 2`, and is about 0.75 × (xmax − xmin) tall on a typical desktop. - So choose the x-range to fit the y-values you need. For quantities on very different scales (say, population in thousands over 10 years), rescale the equation, e.g. measure P in thousands. - Default view: x from -8 to 8, y centred on 0. ## Behaviour and limits - Opening a link replaces the graph in that browser tab. The user's previous graph is only kept elsewhere if they saved or shared it. The URL is cleaned up after loading. - Limits: a script of at most 100,000 characters (its run-time limits are under "Script mode"); at most 300 expressions, 3000 characters per expression, 600 characters per colour expression, 10 initial conditions, |numbers| ≤ 1e9, a θ-range of at most 50 turns, and 1 MB of JSON. - A bad link never shows a blank page: Fluxion keeps the current graph and shows the problem. Expressions that don't parse still load, shown with an error mark so the user can fix them. - In the app, the share menu has "Copy share link" and "Copy as JSON spec". Users can paste the JSON to an assistant, which edits it and returns a new link.