dsim.cljc icon indicating copy to clipboard operation
dsim.cljc copied to clipboard

Example of DSim + Quil integration

Open kot-behemoth opened this issue 2 years ago • 3 comments

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.

kot-behemoth avatar Oct 26 '21 21:10 kot-behemoth

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 :)

helins avatar Oct 31 '21 11:10 helins

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:

  • At t0 (time 0) msg0..8 (messages 0-8) are at n0 (node 0)
  • At t15 msg0..2 are at n1, msg3..5 are at n2
  • at t18 msg6..8 are at n3

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.

flyingmachine avatar Nov 06 '21 12:11 flyingmachine

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

helins avatar Nov 08 '21 22:11 helins