Stream: show and tell

Topic: Roc-Ray & 2d PGA Demo - Ball Physics


view this post on Zulip Luke Boswell (Nov 03 2024 at 08:09):

I made something cool I wanted to share so I made a small blog post about it. https://lukewilliamboswell.github.io/roc-ray-ball-physics/

It's a simple physics simulation of a number of balls that are attracted to the mouse, and experience gravity.

The different parts that come together to build this are all early in development (roc-ray graphics platform using purity-inference, 2D PGA library etc...), but I'm really impressed with what we can do already with roc. :star_struck: :roc:

view this post on Zulip Sam Mohr (Nov 03 2024 at 08:13):

Ooh, cool!

view this post on Zulip Sam Mohr (Nov 03 2024 at 08:13):

I love the embedding of the entire app's source on the webpage

view this post on Zulip Sam Mohr (Nov 03 2024 at 08:14):

It proves how easy this is to do

view this post on Zulip Luke Boswell (Nov 03 2024 at 08:19):

Yeah, source included (typos, warts and all :sweat_smile:)

view this post on Zulip Hannes (Nov 03 2024 at 09:21):

Wow! So cool! How easy is it to embed a raylib project written in Roc in a web page? If it's easy I might try to build some simple games in Roc

view this post on Zulip Luke Boswell (Nov 03 2024 at 09:29):

It's as easy as copy-paste four files from static/ after running just webRelease path/to/your/app.roc, the index.html, rocray.data (only needed if you are embedding assets like fonts or images etc, rocray.js, and rocray.wasm.

view this post on Zulip Luke Boswell (Nov 03 2024 at 09:30):

You'll need roc built from source using the purity inference branch, and also using the purity inference branch in roc-ray. We've been working from that branch so all the latest features are there until purity inference lands in the roc nightlies.

view this post on Zulip Luke Boswell (Nov 03 2024 at 09:34):

https://raw.githubusercontent.com/lukewilliamboswell/lukewilliamboswell.github.io/refs/heads/main/content/roc-ray-ball-physics/index.md

This is the hmtl/js/css I used to embed that demo.

view this post on Zulip Richard Feldman (Nov 03 2024 at 12:30):

this is so cool!!!! :heart_eyes:

view this post on Zulip Isaac Van Doren (Nov 03 2024 at 21:53):

That's awesome! Was not expecting to see a full demo right there in the browser when I opened up the blog post :big_smile:

view this post on Zulip Luke Boswell (Nov 03 2024 at 22:09):

Yeah, I just think it's pretty neat with a hot-reload dev flow using native and then it just compiles and works on the web too. It makes it easier to share with others.

view this post on Zulip Richard Feldman (Nov 03 2024 at 23:25):

also it makes me realize we should really port over Random.list :big_smile:

view this post on Zulip Richard Feldman (Nov 03 2024 at 23:27):

because then generateBalls could be:

generateBalls : List Ball
generateBalls =
    ballGenerator
    |> Random.list numberOfBalls
    |> Random.step (Random.seed 1234)
    |> .value

view this post on Zulip Luke Boswell (Nov 04 2024 at 02:49):

Richard Feldman said:

also it makes me realize we should really port over Random.list :big_smile:

Done https://github.com/lukewilliamboswell/roc-random/pull/12

view this post on Zulip Luke Boswell (Nov 04 2024 at 02:55):

It now looks like

generateBalls : List Ball
generateBalls =
    { value: balls } = Random.step (Random.seed 1234) (Random.list ballGenerator numberOfBalls)
    balls

view this post on Zulip Nils Hjelte (Nov 21 2024 at 10:33):

Nice demo. Have a small comment not really related to the roc code. The damping parameter seem to be inversed, high damping value should dissipate momentum but right now it seems it is the inverse. So you should probably negate the 0-1 interval, where 0 damping should not dissipate any energy

view this post on Zulip Luke Boswell (Nov 21 2024 at 10:39):

The physics is pretty rough... :smiley:

I hacked some things together and was stoked it was "working" -- in the sense it didn't crash and burn and I could get something that ran nicely in the browser.

I've been slowly working through the bivector.net stuff and learning the maths (which is new to me), so hopefully I can make a more realistic simulation soon. So far I've been pleasantly surprised at how nice PGA is for modelling things. But I'm definitely a complete noob at this point.

My hope is to build up a supporting things as I go. Just now I've been researching how to make a nice graph to display points and lines from my simulated world.

view this post on Zulip Luke Boswell (Nov 21 2024 at 10:44):

Thank you for the feedback though. It's great to hear people are checking it out. I hope it inspires people to have a go and build something cool.

view this post on Zulip Richard Feldman (Dec 20 2024 at 12:28):

I wonder if something like this could be useful for Roc 2d platforms like roc-ray: https://www.nicbarker.com/clay

view this post on Zulip Isaac Van Doren (Dec 20 2024 at 18:21):

Just got recommended this phenomenal video by the creator about clay https://youtu.be/DYWTw19_8r4?si=6mN2kf-hIxr5rZZ6

view this post on Zulip Isaac Van Doren (Dec 20 2024 at 18:21):

It really looks excellent!

view this post on Zulip Jasper Woudenberg (Dec 21 2024 at 09:46):

Oh wow, I hadn't heard of clay before. This sounds really compelling.

view this post on Zulip Isaac Van Doren (Mar 03 2025 at 02:40):

Another wonderful video about layout from the creator of clay https://youtu.be/by9lQvpvMIc?si=m9MJhUYRpiEPa9hj

view this post on Zulip Luke Boswell (Mar 03 2025 at 07:55):

Yeah I watched that video the other day. Very interested to give it a go. Kind of a little distracted with our zig compiler ... :sweat_smile:

view this post on Zulip Anthony Bullard (Mar 04 2025 at 22:46):

Nic Barker is a true legend. Love his content even if I already know the concepts he is explaining

view this post on Zulip Sam Mohr (Mar 05 2025 at 01:05):

@JanCVanB are you secretly Nic Barker?? You look so alike


Last updated: Jul 06 2025 at 12:14 UTC