# Sand Simulation Written in Julia -\> WASM (Web Game)

**URL:** <https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391>\
**Category:** Community\
**Tags:** games\
**Created:** [February 1, 2026, 8:58pm UTC](https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391 "2026-02-01T20:58:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyjor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kyjor/32/48132_2.png) [@Kyjor](https://discourse.julialang.org/u/Kyjor)\
**Post date:** [February 1, 2026, 8:58pm UTC](https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391/1 "2026-02-01T20:58:49Z")

</div>

> **[Sand Simulation Written in Julia by Kyjor](https://kyjor.itch.io/julia-web-sand)**
>
> Play in your browser

Hey everyone,

Sometime last year I started tinkering with StaticCompiler.jl for fun. I was able to PoC getting it to work with SDL to create web builds. I was able to write the actual game logic in Julia and convert it to WASM. The game is very simple, but I thought it’d be a good way to show off what I was working on. This is something I’d like to tinker with more and see what I can do with it. I don’t know if anyone has done something similar, but I thought it was cool to get Julia running in the browser. If anyone is interested, here’s the source code for this specific game: [StaticCompilerGame.jl/sand.jl at main · Kyjor/StaticCompilerGame.jl · GitHub](https://github.com/Kyjor/StaticCompilerGame.jl/blob/main/sand.jl) . The repo is really messy at the moment, but I plan to clean it up as I work on other projects within it. Also, I still am working on the commercial game. Things are taking longer than expected, but we are still making progress.

---

<div class="post-metadata">

**Author:** ![simsurace](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simsurace/32/30216_2.png) [@simsurace](https://discourse.julialang.org/u/simsurace)\
**Post date:** [February 2, 2026, 12:59pm UTC](https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391/2 "2026-02-02T12:59:03Z")

</div>

Very nice! I noticed that the water surface does not become level in all cases, I suppose it’s a limitation of the model?

---

<div class="post-metadata">

**Author:** ![Kyjor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kyjor/32/48132_2.png) [@Kyjor](https://discourse.julialang.org/u/Kyjor)\
**Post date:** [February 2, 2026, 1:05pm UTC](https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391/3 "2026-02-02T13:05:51Z")

</div>

Thank you! Yes, this is a very simple version to show that it’s not too hard to create WASM code using Static Compiler. I adapted the code from someone else’s example

---

<div class="post-metadata">

**Author:** ![j-fu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j-fu/32/11373_2.png) [@j-fu](https://discourse.julialang.org/u/j-fu)\
**Post date:** [February 2, 2026, 6:47pm UTC](https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391/4 "2026-02-02T18:47:01Z")

</div>

This sounds great! Once you seem to be keen to work with wasm, I would like to make you aware of [this thread](https://discourse.julialang.org/t/jupyterlab-lite-and-status-of-julia-running-wasm/129957). May be you get some ideas for synergy with other attempts on Julia and wasm.

---

<div class="post-metadata">

**Author:** ![linwaytin](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@linwaytin](https://discourse.julialang.org/u/linwaytin)\
**Post date:** [February 3, 2026, 6:07pm UTC](https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391/5 "2026-02-03T18:07:11Z")

</div>

Interesting! I am curious about static compilation in Julia. Can anybody tell me the difference between StaticTools/StaticCompiler and JuliaC?

I think both can compile Julia code to native, small binaries. Is that right? How is one compared to the other?

---

<div class="post-metadata">

**Author:** ![Alexander-Barth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexander-barth/32/3692_2.png) [@Alexander-Barth](https://discourse.julialang.org/u/Alexander-Barth)\
**Post date:** [February 5, 2026, 9:07am UTC](https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391/6 "2026-02-05T09:07:38Z")

</div>

This is really nice and quite fun to play with!  
Your approach to manipulate the game state is quite interesting:

> <https://github.com/Kyjor/StaticCompilerGame.jl/blob/main/sand.jl#L38-L66>

Is it that julia in 64-bit uses wrong alignment for WASM 32-bit therefore you have to implement the accessor function manually?

I guess, I side stepped the problem in [these experiments](https://github.com/Alexander-Barth/FluidSimDemo-WebAssembly) by using julia 32-bit for the cross-compilation. Hopefully this will get better in the future.

I am wondering if you considered to use [MallocArray](https://github.com/brenhinkeller/StaticTools.jl) ? This allows you to use the regular julia array syntax `A[i,j] = value` (as long you use @inbounds)

> <https://github.com/Alexander-Barth/FluidSimDemo-WebAssembly/blob/main/ShallowWater/compile.jl#L31-L36>

Thank you for sharing your great project 😄

---

<div class="post-metadata">

**Author:** ![Kyjor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kyjor/32/48132_2.png) [@Kyjor](https://discourse.julialang.org/u/Kyjor)\
**Post date:** [February 8, 2026, 3:48pm UTC](https://discourse.julialang.org/t/sand-simulation-written-in-julia-wasm-web-game/135391/7 "2026-02-08T15:48:18Z")

</div>

First of all, thank you!

> [@Alexander-Barth](#):
>
> Is it that julia in 64-bit uses wrong alignment for WASM 32-bit therefore you have to implement the accessor function manually?

It’s been months since I initially implemented that, but IIRC that was the issue! I guess I didn’t think about using julia 32-bit, but that’s a great callout!

I believe at one point I tried to use MallocArray and was having a bit of trouble understanding how to use it. I’ll take a look at your code and use it as a reference. Thanks!!
