helins / dsim.cljc

Idiomatic and purely functional discrete event-simulation
Mozilla Public License 2.0
119 stars 5 forks source link

Example of DSim + Quil integration #6

Open kot-behemoth opened 2 years ago

kot-behemoth commented 2 years ago

I've been trying to learn DSim to do animation using Quil. While going through the docs, there is a mention of Quil integration and how animation is one of the things DSim can help with:

When it comes to the huge topic of any form of animation, offline or online ones, the Clojure community is well endowed by having the Quil library

Now, as a newbie there is quite a lot to grok in Dsim, and the docs show useful code snippets. However, it still is quite difficult to jump from an abstract concept to a simple toy example (might just be that I'm also quite new to Clojure). It would be great if there was one or several runnable examples available.

In particular, it could be really helpful to see a simple example of how exactly an animation can be done using DSim + Quil combination. Even just giving an actual runnable example from the docs:

For instance, suppose this simple animation: an object moving on its X axis from pixel 200 to pixel 800 during 2000 milliseconds, in a universe where time units are indeed milliseconds. Using our infrastructure, it is a matter of barely a few lines of code to write a flow that can move anything from A to B.

The main issue I can see people like myself encountering is how DSim's ctx would play with Quil's fun-mode - and whether you even need it when one is using DSim.

P.S. I watched the wonderful referenced animation, and am really excited to try using DSim for animation!

P.P.S. I understand that asking for examples and docs improvement can be a big ask for maintainers. If someone was able to provide some samples for Quil, I'd be happy to turn them into a runnable example as a PR.

helins commented 2 years ago

Hi,

A ctx is functionnally pure, it's just Clojure data structures and functions, so using fun-mode can help with state management. Indeed, writing Quil examples would be too time consuming at the moment. Overall, it depends how comfortable you are both with Quil and DSim. I have had mixed responses for DSim, where people either understand very well where this is going or have a hard time. So I find it hard to target both. I would advice to just focus on DSim for the moment, without any drawing whatsoever, just get how it works.

Then I hope it becomes more straightforward to imagine how to use it for drawing since this is just about managing state over time. There is nothing too specific about that state when it comes to drawing, akin to how Re-frame uses generic Clojure data structures for building UIs for instance.

I know @flyingmachine has been grokking with animation but I don't know how far or how well that went :)

flyingmachine commented 2 years ago

My little dsim/d3 experiment went well! The animation was meant to show requests and responses for a collection of nodes in a server cluster.

I used dsim to model request timelines, something along the lines of:

This dsim timeline would describe the location of each request in reference to time zero. To produce animations, however, I needed the duration of each message's trip between nodes; if msg5 is at n1 at t15 and n2 at t30, the duration is 15. That just required writing a little helper function to derive these values from the dsim timeline data.

Hope this helps.

helins commented 2 years ago

Thanks! (feel free to share if there is something online :) )