Live Showcase · Compiled Julia Packages in WasmGC
Interactive WasmGC Showcase
Every interactive panel on this page compiles unmodified Julia packages (OrdinaryDiffEqTsit5, StaticArrays, ImageFiltering, ImageBinarization, and FFTL) directly into standalone WebAssembly GC using WasmTarget.jl, Therapy.jl, and WasmMakie.jl.
3D Lorenz Attractor with OrdinaryDiffEqTsit5
Imports OrdinaryDiffEqTsit5 and StaticArrays directly inside the @island. Stepping sigma, rho, or t_end calls solve(ODEProblem{false}(...), Tsit5(); abstol = 1e-6, reltol = 1e-6, saveat = 0.02) live in WebAssembly GC and renders both the 3D Axis3 phase-space curve and the 2D z(t) series through WasmMakie.
View Julia @island source
using OrdinaryDiffEqTsit5
using StaticArrays
import WasmMakie as WM
using WasmMakie: lines!
function _lorenz_rhs(u::SVector{3, Float64}, p::SVector{3, Float64}, t::Float64)
σ, ρ, β = p[1], p[2], p[3]
return SVector{3, Float64}(
σ * (u[2] - u[1]),
u[1] * (ρ - u[3]) - u[2],
u[1] * u[2] - β * u[3],
)
end
function _build_lorenz_figure(sigma_i::Int64, rho_i::Int64, tend_i::Int64)
u0 = SVector{3, Float64}(1.0, 1.0, 1.0)
p = SVector{3, Float64}(Float64(sigma_i), Float64(rho_i), 8.0 / 3.0)
prob = ODEProblem{false}(_lorenz_rhs, u0, (0.0, Float64(tend_i)), p)
sol = solve(prob, Tsit5(); abstol = 1e-6, reltol = 1e-6, saveat = 0.02)
n = length(sol.t)
xs = Vector{Float64}(undef, n)
ys = Vector{Float64}(undef, n)
zs = Vector{Float64}(undef, n)
for i in Int64(1):n
u = sol.u[i]
xs[i] = u[1]
ys[i] = u[2]
zs[i] = u[3]
end
fig = WM.Figure(size = (960.0, 420.0))
ax1 = WM.Axis3(
fig[1, 1];
title = "Lorenz Attractor (OrdinaryDiffEqTsit5)",
xlabel = "x",
ylabel = "y",
zlabel = "z",
azimuth = 0.72,
elevation = 0.32,
)
lines!(ax1, xs, ys, zs; color = :purple, linewidth = 1.5)
ax2 = WM.Axis(
fig[1, 2];
title = "z(t) Trajectory (Tsit5, abstol = 1e-6)",
xlabel = "t",
ylabel = "z(t)",
)
lines!(ax2, sol.t, zs; color = :blue, linewidth = 1.4)
return fig
end
@island function LorenzExplorer()
sigma, set_sigma = create_signal(Int64(10))
rho, set_rho = create_signal(Int64(28))
tend, set_tend = create_signal(Int64(24))
create_effect(() -> begin
fig = _build_lorenz_figure(sigma(), rho(), tend())
WM.render!(fig, WM.WasmCtx())
end)
return Div(
Canvas(:width => 960, :height => 420),
Button(:on_click => () -> set_sigma(max(Int64(4), sigma() - Int64(1))), "-"),
Span(sigma),
Button(:on_click => () -> set_sigma(min(Int64(20), sigma() + Int64(1))), "+"),
Button(:on_click => () -> set_rho(max(Int64(10), rho() - Int64(2))), "-"),
Span(rho),
Button(:on_click => () -> set_rho(min(Int64(44), rho() + Int64(2))), "+"),
Button(:on_click => () -> set_tend(max(Int64(8), tend() - Int64(4))), "-"),
Span(tend),
Button(:on_click => () -> set_tend(min(Int64(40), tend() + Int64(4))), "+"),
)
endImage Processing with ImageFiltering and ImageBinarization
Imports ImageFiltering and ImageBinarization directly. Each click runs imfilter(src, Kernel.gaussian(sigma)), imgradients(blurred, KernelFactors.sobel), or binarize(blurred, Otsu()) inside WebAssembly GC over a 40x40 grayscale matrix and draws the input and output side by side with WasmMakie.heatmap!.
View Julia @island source
using ImageFiltering
using ImageBinarization
import WasmMakie as WM
using WasmMakie: heatmap!
function _build_image_studio_figure(scene_id::Int64, mode_id::Int64, sigma_step::Int64)
n = Int64(40)
src = _make_test_image(scene_id, n)
sigma = Float64(sigma_step) * 0.5
blurred = imfilter(src, Kernel.gaussian(sigma))
proc = if mode_id == Int64(1)
blurred
elseif mode_id == Int64(2)
gy, gx = imgradients(blurred, KernelFactors.sobel)
mag = sqrt.(gx .^ 2 .+ gy .^ 2)
maxv = max(maximum(mag), 1e-9)
mag ./ maxv
else
Float64.(binarize(blurred, Otsu()))
end
xs = collect(1.0:Float64(n))
fig = WM.Figure(size = (960.0, 420.0))
ax1 = WM.Axis(fig[1, 1]; title = "Input Field (40x40)", xlabel = "x (px)", ylabel = "y (px)")
heatmap!(ax1, xs, xs, src; colormap = :grays, colorrange = (0.0, 1.0))
ax2 = WM.Axis(fig[1, 2]; title = "Filtered Output", xlabel = "x (px)", ylabel = "y (px)")
heatmap!(ax2, xs, xs, proc; colormap = mode_id == Int64(2) ? :inferno : :grays, colorrange = (0.0, 1.0))
return fig
end
@island function ImageStudio()
scene, set_scene = create_signal(Int64(1))
mode, set_mode = create_signal(Int64(2))
sigma_step, set_sigma_step = create_signal(Int64(2))
create_effect(() -> begin
fig = _build_image_studio_figure(scene(), mode(), sigma_step())
WM.render!(fig, WM.WasmCtx())
end)
return Div(
Canvas(:width => 960, :height => 420),
Button(:on_click => () -> set_scene(Int64(1)), "Rings"),
Button(:on_click => () -> set_scene(Int64(2)), "Grid"),
Button(:on_click => () -> set_scene(Int64(3)), "Shapes"),
Button(:on_click => () -> set_mode(Int64(1)), "Blur"),
Button(:on_click => () -> set_mode(Int64(2)), "Sobel"),
Button(:on_click => () -> set_mode(Int64(3)), "Otsu"),
)
endLive Real FFT Spectrum with FFTL.jl
Imports FFTL directly and runs FFTL.rfft(ys) over the 128-point damped odd-harmonic signal in compiled WebAssembly GC. Raising damping visibly broadens the real FFT spectral peaks in the barplot! panel on the right.
View Julia @island source
using FFTL
import WasmMakie as WM
using WasmMakie: lines!, barplot!
function _build_wave_figure(freq_i::Int64, harm_i::Int64, damp_i::Int64)
f = Float64(freq_i)
damp = Float64(damp_i) * 0.12
n = Int64(128)
two_pi = 6.283185307179586
xs = Vector{Float64}(undef, n)
ys = Vector{Float64}(undef, n)
for i in Int64(0):(n - Int64(1))
x = Float64(i) / Float64(n) * two_pi
env = exp(-damp * x)
val = 0.0
for k in Int64(1):harm_i
kf = Float64(2 * k - Int64(1))
val += sin(kf * f * x) / kf
end
xs[i + Int64(1)] = x
ys[i + Int64(1)] = val * env
end
spec = FFTL.rfft(ys)
nbins = Int64(32)
freqs = Vector{Float64}(undef, nbins)
mags = Vector{Float64}(undef, nbins)
scale = 2.0 / Float64(n)
for k in Int64(1):nbins
freqs[k] = Float64(k)
mags[k] = abs(spec[k + Int64(1)]) * scale
end
fig = WM.Figure(size = (960.0, 400.0))
ax1 = WM.Axis(fig[1, 1]; title = "Damped Odd-Harmonic Signal (N = 128)", xlabel = "x (rad)", ylabel = "y(x)")
lines!(ax1, xs, ys; color = :purple, linewidth = 2.0)
ax2 = WM.Axis(fig[1, 2]; title = "Live Magnitude Spectrum (FFTL.rfft)", xlabel = "frequency bin k", ylabel = "|Y[k]| * 2/N")
barplot!(ax2, freqs, mags; color = :blue)
return fig
end
@island hydrate = :visible function WaveSpectrumLab()
freq, set_freq = create_signal(Int64(2))
harmonics, set_harmonics = create_signal(Int64(3))
damping, set_damping = create_signal(Int64(1))
create_effect(() -> begin
fig = _build_wave_figure(freq(), harmonics(), damping())
WM.render!(fig, WM.WasmCtx())
end)
return Div(
Canvas(:width => 960, :height => 400),
Button(:on_click => () -> set_freq(max(Int64(1), freq() - Int64(1))), "-"),
Span(freq),
Button(:on_click => () -> set_freq(min(Int64(5), freq() + Int64(1))), "+"),
Button(:on_click => () -> set_harmonics(max(Int64(1), harmonics() - Int64(1))), "-"),
Span(harmonics),
Button(:on_click => () -> set_harmonics(min(Int64(5), harmonics() + Int64(1))), "+"),
Button(:on_click => () -> set_damping(max(Int64(0), damping() - Int64(1))), "-"),
Span(damping),
Button(:on_click => () -> set_damping(min(Int64(8), damping() + Int64(1))), "+"),
)
endJulia Base Numeric Kernel Workbench
Three reactive memos running integer trial-division prime counting, exact Int64 Fibonacci iteration, and composite Simpson quadrature using Julia Base inside a single compiled WasmGC module.
Prime Count pi(N)
Trial division compiled to WasmGC i64
pi(500) =
95
Fibonacci F(n)
Zero-allocation iterative Int64 loop
F(32) =
2178309
Simpson Integral
sin(x) * exp(-x/4) on [0, 4pi]
intervals = 40
0.90055
View Julia @island source
function _wt_count_primes(limit::Int64)::Int64
count = Int64(0)
n = Int64(2)
while n <= limit
is_prime = true
d = Int64(2)
while d * d <= n
if n % d == Int64(0)
is_prime = false
break
end
d = d + Int64(1)
end
if is_prime
count = count + Int64(1)
end
n = n + Int64(1)
end
return count
end
function _wt_fib_iter(n::Int64)::Int64
a = Int64(0)
b = Int64(1)
i = Int64(0)
while i < n
nxt = a + b
a = b
b = nxt
i = i + Int64(1)
end
return a
end
function _wt_simpson_damped(n_intervals::Int64)::Float64
m = n_intervals < Int64(2) ? Int64(2) : n_intervals
if m % Int64(2) != Int64(0)
m = m + Int64(1)
end
b = 3.141592653589793
h = b / Float64(m)
acc = 0.0
i = Int64(0)
while i <= m
x = Float64(i) * h
fx = sin(x) * exp(-0.35 * x)
w = if i == Int64(0) || i == m
1.0
elseif i % Int64(2) == Int64(1)
4.0
else
2.0
end
acc = acc + w * fx
i = i + Int64(1)
end
val = acc * (h / 3.0)
return floor(val * 100000.0 + 0.5) / 100000.0
end
@island function NumericKernelBench()
prime_limit, set_prime_limit = create_signal(Int64(500))
fib_n, set_fib_n = create_signal(Int64(32))
quad_n, set_quad_n = create_signal(Int64(40))
prime_count = create_memo(() -> _wt_count_primes(prime_limit()))
fib_val = create_memo(() -> _wt_fib_iter(fib_n()))
quad_val = create_memo(() -> _wt_simpson_damped(quad_n()))
return Div(
Div(
P("pi(", prime_limit, ") = ", prime_count),
Button(
:on_click =>
() -> set_prime_limit(max(Int64(100), prime_limit() - Int64(100))),
"-",
),
Button(
:on_click =>
() -> set_prime_limit(min(Int64(5000), prime_limit() + Int64(100))),
"+",
),
),
Div(
P("F(", fib_n, ") = ", fib_val),
Button(:on_click => () -> set_fib_n(max(Int64(1), fib_n() - Int64(1))), "-"),
Button(:on_click => () -> set_fib_n(min(Int64(60), fib_n() + Int64(1))), "+"),
),
Div(
P("intervals = ", quad_n, " -> ", quad_val),
Button(:on_click => () -> set_quad_n(max(Int64(4), quad_n() - Int64(4))), "-"),
Button(
:on_click => () -> set_quad_n(min(Int64(200), quad_n() + Int64(4))),
"+",
),
),
)
end