Multi-Level ToC & Multi-Island Stress Test
Multiple notebooks on one Therapy page
Every exported Snapshot fragment is a self-contained component: its CSS is isolated under @scope (.snap-notebook), its WasmGC runtime is registered per notebook root, and its PlutoUI.TableOfContents() sticks strictly within its own card bounds rather than escaping to the viewport edge.
Two simultaneous ToC levels: Use the outer On This Page rail to jump across notebooks, and each notebook's internal Table of Contents to navigate headings strictly within that notebook. Drag sliders in any notebook — all three WasmGC runtimes stay independently live, and all three dispose cleanly on route change.
1. Interactive 3D Surfaces & Chaos
Pure-Julia WasmMakie Axis3 wave interference surface and Lorenz strange attractor in WebAssembly, with a scoped PlutoUI table of contents.
Interactive 3D Surfaces & Chaos in WebAssembly
Every figure in this notebook is a real WasmMakie.Axis3 scene compiled from Julia to WebAssembly and rasterized with a pure-Julia z-buffered Blinn-Phong triangle shader directly onto an HTML <canvas> — no Julia server, no Three.js, and no WebGL.
Drag any slider below to orbit the 3D camera, reshape the wave interference field, or sweep the Rayleigh parameter of the Lorenz attractor in real time.
1. 3D Wave Interference Surface
We evaluate the radially damped interference field
$$z(x, y) = \frac{\sin(\omega r)}{r}, \qquad r = \sqrt{x^2 + y^2}$$
on a $25 \times 25$ grid and shade every quad with WasmMakie.surface! plus an optional WasmMakie.wireframe! mesh and Colorbar.
Camera azimuth (deg) =
Camera elevation (deg) =
Wave frequency $\omega$ =
Colormap (1: viridis, 2: plasma, 3: inferno, 4: coolwarm) =
Overlay wireframe =
2. The Lorenz Strange Attractor
The classic atmospheric convection system
$$\dot{x} = \sigma (y - x), \qquad \dot{y} = x (\rho - z) - y, \qquad \dot{z} = x y - \beta z$$
with $\sigma = 10$ and $\beta = 8/3$ transitions from decaying spirals ($\rho < 24.74$) to the iconic chaotic butterfly ($\rho = 28$). Below, WebAssembly integrates 1,400 time steps on every slider event and shades the 3D trajectory by instantaneous speed $\|v\|$.
Lorenz azimuth (deg) =
Lorenz elevation (deg) =
Rayleigh number $\rho$ =
3. Dynamical Regime Summary
For $\rho < 24.74$, trajectories spiral inward toward two symmetric fixed points at $(\pm\sqrt{\beta(\rho - 1)},\, \pm\sqrt{\beta(\rho - 1)},\, \rho - 1)$. Above the critical subcritical Hopf threshold $\rho_H \approx 24.74$, both equilibria lose stability and the flow settles onto the iconic two-lobed strange attractor.
Both 3D scenes above run 100% locally in your browser: every slider event invokes a standalone Julia WasmGC module compiled by WasmTarget.jl and rasterized through WasmMakie.Axis3.
using PlutoUI, WasmMakiefunction _wave_cmap_spec(idx::Int64)::WasmMakie.ColormapSpec
if idx == Int64(2)
return WasmMakie.to_colormap_spec(:plasma)
elseif idx == Int64(3)
return WasmMakie.to_colormap_spec(:inferno)
elseif idx == Int64(4)
return WasmMakie.to_colormap_spec(:coolwarm)
end
return WasmMakie.to_colormap_spec(:viridis)
endfunction build_wave_surface(az_deg::Int64, el_deg::Int64, freq::Float64, cmap_idx::Int64, show_wire::Bool)
az = Float64(az_deg) * 0.017453292519943295
el = Float64(el_deg) * 0.017453292519943295
cmap = _wave_cmap_spec(cmap_idx)
fig = WasmMakie.Figure(size = (760.0, 440.0))
ax = WasmMakie.Axis3(
fig[1, 1];
title = "3D Wave Interference Surface",
xlabel = "x",
ylabel = "y",
zlabel = "sinc(w r)",
azimuth = az,
elevation = el,
perspectiveness = 0.25,
)
nx = Int64(25)
ny = Int64(25)
xs = Vector{Float64}(undef, nx)
ys = Vector{Float64}(undef, ny)
i = Int64(1)
while i <= nx
xs[i] = -6.0 + 12.0 * Float64(i - Int64(1)) / Float64(nx - Int64(1))
i = i + Int64(1)
end
j = Int64(1)
while j <= ny
ys[j] = -6.0 + 12.0 * Float64(j - Int64(1)) / Float64(ny - Int64(1))
j = j + Int64(1)
end
zs = Vector{Float64}(undef, nx * ny)
j = Int64(1)
while j <= ny
yj = ys[j]
i = Int64(1)
while i <= nx
xi = xs[i]
r = sqrt(xi * xi + yj * yj)
wr = freq * r
zs[i + (j - Int64(1)) * nx] = wr == 0.0 ? 1.0 : sin(wr) / wr
i = i + Int64(1)
end
j = j + Int64(1)
end
sf = WasmMakie.surface!(ax, xs, ys, zs, nx, ny; colormap = cmap)
if show_wire
WasmMakie.wireframe!(ax, xs, ys, zs, nx, ny; color = (0.0, 0.0, 0.0, 0.22), linewidth = 0.6)
end
WasmMakie.Colorbar(fig[1, 2], sf; label = "Amplitude")
return fig
endfunction build_lorenz_attractor(az_deg::Int64, el_deg::Int64, rho_i::Int64)
az = Float64(az_deg) * 0.017453292519943295
el = Float64(el_deg) * 0.017453292519943295
rho = Float64(rho_i)
sigma = 10.0
beta = 8.0 / 3.0
dt = 0.008
fig = WasmMakie.Figure(size = (760.0, 440.0))
ax = WasmMakie.Axis3(
fig[1, 1];
title = "Lorenz Strange Attractor",
xlabel = "x",
ylabel = "y",
zlabel = "z",
azimuth = az,
elevation = el,
perspectiveness = 0.25,
)
n = Int64(1400)
xs = Vector{Float64}(undef, n)
ys = Vector{Float64}(undef, n)
zs = Vector{Float64}(undef, n)
cs = Vector{Float64}(undef, n)
x = 1.0
y = 1.0
z = 1.0
i = Int64(1)
while i <= n
xs[i] = x
ys[i] = y
zs[i] = z
dx = sigma * (y - x)
dy = x * (rho - z) - y
dz = x * y - beta * z
cs[i] = sqrt(dx * dx + dy * dy + dz * dz)
x = x + dt * dx
y = y + dt * dy
z = z + dt * dz
i = i + Int64(1)
end
ln = WasmMakie.lines!(ax, xs, ys, zs; color = cs, colormap = :plasma, linewidth = 1.7)
WasmMakie.scatter!(
ax,
Float64[xs[1], xs[n]],
Float64[ys[1], ys[n]],
Float64[zs[1], zs[n]];
color = Float64[cs[1], cs[n]],
colormap = :plasma,
markersize = 10.0,
strokecolor = :black,
strokewidth = 1.0,
)
WasmMakie.Colorbar(fig[1, 2], ln; label = "Speed ||v||")
return fig
end2. Interactivity with HTML
Live @bind inputs, custom HTML controls, and JavaScript widgets with an independent scoped PlutoUI table of contents.
Interactivity with HTML
Pluto notebooks can use the @bind macro for interactive inputs. Neat!
If you're completely new to coding anything interactive in a web browser, the easiest way to get started is with the PlutoUI package in Julia. (Check out the PlutoUI featured notebook if you'd like to learn more about that!)
If you have some experience with HTML, or if you would like to learn how to make your own interactive elements, this notebook is for you! We'll cover the basics of using @bind with HTML elements. Let's get started!
Bound variables
A basic interactive cell looks like this: we use the @bind macro, define a Julia variable, and add a bit of HTML code that creates an <input> element. The HTML element will be rendered as the cell's output.
@bind x html"<input type=range>"That's all you need! Pluto will synchronise the value of x with the latest value of the HTML input. Try moving the slider! 👆
xA neat aspect of this @bind macro is that on the Julia side, x is just a normal integer:
typeof(x)Not an observable, callback, or something else that you need to wrap your head around. You can use x like you would any other number, and Pluto's reactivity means anything depending on x will be updated with it. 🚀
y = x^2Input types
You can use binds with anything that fires an input event. For example:
@bind a html"<input type=range >"@bind b html"<input type=text >"@bind c html"<input type=checkbox >"@bind d html"""
<select>
<option value='one'>First</option>
<option value='two'>Second</option>
</select>
"""@bind e html"<input type=color >"@bind f html"<input type=date>"(a, b, c, d, e, f)Scripting inputs with Javascript
You can also use Javascript to write more complicated inputs.
To get started with this, add a <script> tag to your cell. The easiest setup is to make the script a child of the cell's root element. Then you can use currentScript.parentElement to select the script's parent element.
For instance, here a HTML snippet with a script added to it.
html"""
<div>
Let's make something interactive here!
<script>
const div = currentScript.parentElement;
</script>
</div>
"""Now we can use the script to handle whatever interaction we want. For a simple element, let's add a button and count the number of clicks.
html"""
<div>
<button>Click me!</button>
<script>
const div = currentScript.parentElement;
const button = div.querySelector("button");
var clicks = 0;
button.addEventListener("click", e => {
clicks += 1;
});
</script>
</div>
"""The script is now keeping track of clicks, but it's not sending that value anywhere.
We need to:
Update the parent's element
valueproperty (this is what Pluto will be reading).Dispatch an
"input"event to trigger change detection.
html"""
<div>
<button>Click me!</button>
<script>
const div = currentScript.parentElement;
const button = div.querySelector("button");
var clicks = 0;
function update() {
div.value = clicks;
div.dispatchEvent(new CustomEvent("input"));
}
button.addEventListener("click", e => {
clicks += 1;
update();
});
// fire an event with the initial value immediately
update();
</script>
</div>
"""Okay, now we can use this HTML snippet with a @bind macro and see the result!
@bind counter html"""
<div>
<button>Click me!</button>
<script>
const div = currentScript.parentElement;
const button = div.querySelector("button");
var clicks = 0;
function update() {
div.value = clicks;
div.dispatchEvent(new CustomEvent("input"));
}
button.addEventListener("click", e => {
clicks += 1;
update();
});
// fire an event with the initial value immediately
update();
</script>
</div>
"""counterTip
In this example, we immediately call update() and trigger an input event with the initial value. If we didn't do that, the value of counter would be nothing until the first interaction. Whether that's appropriate, depends on the interaction you want. In this case, it made sense that the counter should start at 0!
Using Julia values in HTML
We've seen how you can pass on values from an interactive HTML element on to Julia, but for proper interaction, we also want to do it the other way around!
The most basic way to do this is string interpolation. In this example, you can change the value of limit in the code to affect the maximum value of the slider. Try it out!
limit = 5@bind limited HTML("""
<input type="range" min="0" max="$(limit)">
""")limitedKeep in mind that changing the value of limit will re-evaluate the slider cell, so it will reset the value.
For something even fancier, you can also interpolate value in Javascript. For example, here I have adapted my counter so it won't count past limit:
@bind limited_counter HTML("""
<div>
<button>Click me!</button>
<script>
const div = currentScript.parentElement;
const button = div.querySelector("button");
const max = $limit;
var clicks = 0;
function update() {
div.value = clicks;
div.dispatchEvent(new CustomEvent("input"));
}
button.addEventListener("click", e => {
if (clicks < max) {
clicks += 1;
update();
}
});
// fire an event with the initial value immediately
update();
</script>
</div>
""")limited_counterTip
Interpolating values in Javascript is neat, but remember that we are just taking the string representation of the variable and pasting it in the javascript code. For some complex data types like dates, you will need to do a bit of conversion to turn them into proper javascript expressions.
If you're looking for something more sophisticated than simple string interpolation, check out the HyperTextLiteral package!
Reusing elements
Once you've written some neat interactive element, you may want to use it a few times in notebook. The easiest way is to put the HTML literal in a variable.
myslider = html"""<input type="range" min=50 max=100 step=5 style="width: 100%">""";@bind x1 myslider@bind x2 mysliderx1, x2It's as simple as that!
Tip
To avoid confusing your readers, it's a good idea to put a ; at the end of the cell where you define the interactive element, like we did here. This way, we only show sliders that are actually bound to something.
This is is how the PlutoUI package works - it defines HTML literals - sometimes with their own scripts.
If you've written some cool HTML inputs and you want to share them with others, you can also make a UI package! Just publish those definitions as a Julia package and you're done! ✨
Behind the scenes
If you're curious to learn a bit more about how this all works, keep reading!
The output value
As we've mentioned, bound values are just the latest value of the input element, rather than some kind of observable.
The update mechanism is lossy and lazy, which means that it will skip values if your code is still running - and only send the latest value when your code is ready again. This is important when changing a slider from 0 to 100, for example. If it would send all intermediate values, it might take a while for your code to process everything, causing a noticeable lag.
What does the macro do?
The @bind macro does not actually contain the interactivity mechanism, this is built into Pluto itself. Still, it does two things: it assigns a default value to the variable (missing in most cases), and it wraps the second argument in a PlutoRunner.Bond object.
For example, expanding the @bind macro turns this expression:
@bind x Slider(5:15)
into (simplified):
begin
local el = Slider(5:15)
global x = AbstractPlutoDingetjes.intial_value(el)
PlutoRunner.create_bond(el, :x)
end
We see that the macro creates a variable x, which is given the value AbstractPlutoDingetjes.intial_value(el). This function returns missing by default, unless a method was implemented for your widget type. For example, PlutoUI has a Slider type, and it defines a method for intial_value(slider::Slider) that returns the default number.
Declaring a default value using AbstractPlutoDingetjes is not necessary, as shown by the earlier examples in this notebook, but the default value will be used for x if the notebook.jl file is run as a plain julia file, without Pluto's interactivity.
You don't need to worry about this if you are just getting started with Pluto and interactive elements, but more advanced users should take a look at AbstractPlutoDingetjes.jl.
JavaScript?
Yes! We are using Generator.input from observablehq/stdlib to create a JS Generator (kind of like an Observable) that listens to onchange, onclick or oninput events, depending on the element type.
This makes it super easy to create nice HTML/JS-based interaction elements - a package creator simply has to write a show method for MIME type text/html that creates a DOM object that triggers the input event. In other words, Pluto's @bind will behave exactly like viewof in observablehq.
If you want to learn more about using Javascript in Pluto, check out the JavaScript sample notebook!
3. Fractals & Julia Sets
Complex sequences, PlutoImageCoordinatePicker, TwoColumn controls, and live WasmMakie Julia-set rendering — running simultaneously beside the notebooks above.
using PlutoUI, PlutoTeachingTools, PlutoImageCoordinatePicker, WasmMakieusing ImageShow, ImageIO, ColorsFractals: A Mathematical Concept
Hey there 👋 Do you remember the first time you ever saw a snowflake? ❄️
Did you also know that if you zoom into a snowflake, you will see the same shape over and over again, no matter how deep you zoom in.

Turns out, many objects have this same property, where they can be split into parts and each tiny part is a copy of the whole. We call them Fractals.
Pretty cool, right? But what's even more cool is that fractals can be defined mathematically following a super simple formula! One famous such set of fractals is called the Julia Set
A Fun Sequence to Work With
Before we get to the fractals, there are a few things we want to talk about.
So, in math, instead of dealing with numbers in a list, we can define a formula that looks like this:
$$z_{n+1} = z_n^2 + 1$$
This is called a sequence. Let's see how it works 😁
Calculating numbers
Step 1: choose an initial value $z_0$ :
Now, we can calculate $z_1$, and $z_2$, and so on:
z1 = z0^2 + 1z2 = z1^2 + 1z3 = z2^2 + 1z4 = z3^2 + 1And so on ..
Basically we calculate the next value by using the same function applied to the last value.
Fun Julia Alert!
Now check out this piece of cool Julia code. Can you guess what it does?
F(z) = z^2 + 1;function Fⁿ(x, n)
z = x
for i in 1:n
z = F(z) # apply F, n times in a row
end
return z
end;zₙ = Fⁿ(z0, n)💡 Did you guess what the code does?
Tip: Move both the $n$ and the $z_0$ sliders around if you need help!
The Sequence
Now let's put it together!
This code generate the whole sequence up to our chosen n and saves it in a list. If you're interested in how to use Julia methods to write compact code, check it out!
But no worries if you don't understand it, it's not necessary for the rest.
function create_sequence(initial_value, max_n)
# Build the sequence one step at a time, starting from the initial value
series = [initial_value]
z = initial_value
for i in 2:max_n
z = F(z) # next element: apply our function F
push!(series, z) # save it in the list
end
return series
end;Change the initial value and n and observe how the series changes!
$z_0 =$
$n =$
sequence = create_sequence(initial_value, max_n)👆 Click on the sequence to see all entries.
Divergence!
What happens when we keep doing this for a long time?
For most initial values, our numbers are always increasing and getting bigger and bigger, so they're going to infinity. We say the series diverges.
Fun Functions for a Fun Sequence
Now that you (hopefully) got the gist of that. Let's make it a bit more complicated.
Remember how we chose the formula $z_{n+1} = z_n^2 + 1$ before? Well, we can do this in a more general way as $z_{n+1} = z_n^2 + C$. Before, we had C = 1.
C = -1Let's define our function again in a more general setting
Fc(z, c) = z^2 + c;Now let's use our code from above again with our new function this time.
function create_sequence_with_c(C, initial_value, max_n)
# Same idea as before, but now our function also uses the constant C
series = [initial_value]
z = initial_value
for i in 2:max_n
z = Fc(z, C) # next element: apply F with our constant C
push!(series, z)
end
return series
end;Try setting C = -1. What happens to our C_sequence (if you chance nothing else)?
C_sequence = create_sequence_with_c(C, initial_value_with_c, max_n)If you noticed that we get a completely new sequence, that's correct!
But, how about if we set initial_value_with_c = 1. What happens? Do you notice anything special about this sequence?
✅ Answer
In this case, the series doesn't go to infinity but moves back and forth between 0 and -1, and so it doesn't diverge. It oscillates.
PS: The same thing happens if initial_value_with_c = 0
Now, to make things more fun, let's try more values of C and see if the same thing happens again.
To make it even more fun, let's make C a complex number!
If you don't know about complex numbers, that's okay. For now, we can think of C as a 2D point.
👇 Click anywhere to chose a point!
cAgain, starting from a fixed initial value, let's watch the size of each term in the sequence. See how it changes completely for even very similar c values? Pretty cool right!
new_initial_value = 1.0 + 0.0imnew_sequence = let
# Track the SIZE (magnitude) of each term — that's exactly what tells us
# whether the sequence stays small (converges) or blows up (diverges).
# We cap huge values so the list stays readable: a value of 1000000 means
# "this term blew up".
zc = new_initial_value
sizes = Int[]
for i in 1:15
m = abs(zc)
push!(sizes, round(Int, min(m, 1.0e6)))
m > 1.0e6 && break # stop once it has clearly diverged
zc = Fc(zc, c) # our function from above, now with a complex c
end
sizes
end👆 Click on the sequence to see all entries.
Convergence?
Let's look at the size of the last term. Is it a small number (convergence), or something very large or NaN (divergence)?
last(new_sequence)One last thing
Choose 2 of your favorite colors (ideally they should match each other 😉):
First color:
Second color:
Construct Fractals
Now we have everything we need to construct a fractal from the Julia set.
Recipe: Julia Set picture
Choose a complex number $c$ (on the left).
We define our favorite sequence $z_{n+1} = z_n^2 + c$
Now, we're going over all the imaginary numbers in a square around $0$, and for each:
Use the number as the initial value to compute a sequence.
If the sequence converges, we color the point gold.
If the sequence diverges, we color the point green.
👇 Drag the sliders to choose the constant $c = c_x + i\,c_y$, zoom, and detail!
$c_x =$
$c_y =$
zoom
Bonus: the Mandelbrot set
The Julia set above fixes one constant $c$ and sweeps the starting point $z_0$ across the plane. The Mandelbrot set does the opposite: it starts every pixel at $z_0 = 0$ and uses the pixel's own coordinate as $c$. The result is the single most famous fractal in mathematics — and the same simple loop $z \\leftarrow z^2 + c$ draws it.
Pan with the centre sliders and zoom in to find miniature copies of the whole shape hiding along its edge.
centre $x$
centre $y$
zoom
If you're interested to dive deep into the code, take a look below, it's so simple and straighforward and yet we can create so many beautiful things with it!