<- Notebooks/Interactive 3D Surfaces & Chaos in WebAssembly2/2 cells live
.jl source

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) = 230

Camera elevation (deg) = 25

Wave frequency $\omega$ = 1.0

Colormap (1: viridis, 2: plasma, 3: inferno, 4: coolwarm) = 1

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) = 225

Lorenz elevation (deg) = 20

Rayleigh number $\rho$ = 28

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, WasmMakie
_wave_cmap_spec (generic function with 1 method)
function _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)
end
build_wave_surface (generic function with 1 method)
function 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
end
build_lorenz_attractor (generic function with 1 method)
function 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
end

Pluto notebooks compiled to WebAssembly islands and hosted as native Therapy components, with no Julia server.