Using quil for visualization of a long-running process, not in a draw loop

瀏覽次數:45 次
跳到第一則未讀訊息

Lee Spector

未讀,
2016年11月20日 中午12:49:022016/11/20
收件者:clj-processing
I asked this on slack, but am wondering if this google group might be a better forum for it:

Is there a way to use quil for drawing but not in a draw loop? I have a long (hours/days) running process and I'd like to draw something derived from the state periodically. I know I could break the long-running process into chunks and in do a chunk of work and make the drawing in the draw function, which would loop. But I'd rather not have to rework the long-running process. I'd like to just insert calls within it that cause drawing to happen... but I don't know how to use quil in this way. Is it possible?


@ blueberry replied:

@lspector It is possible to solve the problem, although the solution is a bit different from what you describe, but it requires much more explanations than is possible in this chat interface. Processing: A Programming Handbook for Visual Designers etc. has this covered. 

To which I responded:

@blueberry Thanks. I have that book and have just looked through it but don't see what you're referring to. Could you orient me to the relevant section?
 
I've been thinking that maybe the right approach would be to somehow start in parallel (with a `send` to an `agent`?) my long-running process and a quil sketch. The quil sketch could just loop doing nothing until the long-running process indicates that there's something to draw, by putting it in a global atom, and when that happens the quil sketch would draw it (and then resume looping doing nothing until this happens again). Does that seem like a reasonable approach, or is there something better? 

That's where it stands now, and I'm wondering if anyone here might have advice about what approach would be best.

Thanks,

 -Lee

Nikita Beloglazov

未讀,
2016年11月20日 晚上7:01:392016/11/20
收件者:clj-processing
Hi Lee

I tried to implement drawing outside of 'draw' function but failed because of underlying Processing doesn't support it, see this. Instead your suggestion with pausing draw loop until we get a message from agent seems the way to go. Or maybe use a blocking queue to which your main process pushes state object and quil waits until state is available and draws it. 

Also do you need to display drawn images in real-time or you can run it after the main long-running process finishes? if it's the latter I'd propose for the long running process to save all intermediate states in a file (json, edn) and then have a separate quil program that reads this file and draws/visualizes all states. I think it will be easier to debug it this way: you have intermediate file that you can check for correctness. 

Nikita

--
You received this message because you are subscribed to the Google Groups "clj-processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-processin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lee Spector

未讀,
2016年11月20日 晚上9:47:222016/11/20
收件者:clj-processing
Thanks Nikita.

I don't really understand how I'd use the blocking queue, just because I don't do much Java interop, but I'll try to get the approach with an agent and the draw loop running concurrently.

FWIW I do indeed want to display the images in realtime, since I want to use them to monitor the progress of the long-running process.

 -Lee

Nikita Beloglazov

未讀,
2016年11月21日 凌晨3:05:122016/11/21
收件者:clj-processing
Using queue is pretty simple: you need to create a queue, long process adds elements (state objects) to it and quil program retrieves them and draws. If queue is empty - quil is blocked until long-runnin process adds a new state object to it. Example

Actually I'm not sure how you're going to do it using agents. If I understand correctly agents are good if you want to update state asynchronously in another thread and in your case you just want to pass thread from one thread (main long running) to another (quil thread). I feel like atoms might be easier: there is a global atom containing state. Long process updates it from time to time while quil constantly draws it. 

But anyway, any approach should work :) 


Lee Spector

未讀,
2016年11月21日 上午9:29:092016/11/21
收件者:clj-processing
Thanks for the queue example. I think that an ordinary Clojure data structure in an atom would do as well, but perhaps I'll see a use for the queue as I proceed.

My mention of agents was not related to the communication between the long-running process and the quil draw loop (which I imagined happening through an atom) but instead related to the need to start the long-running process and the quil draw loop both running concurrently. One way to get two things running concurrently is to create an agent, use `send` to that agent with a function call that will run one of the things, and then do the other thing in the code following the call to `send`.

In any event, thanks for the input; I will experiment.

It may turn out to be simpler just to use some other drawing library that doesn't require to draw from within a draw loop. That would be a shame, since quil has all of the features that I want and is so pleasant in other ways. But if I want to do this, does anyone have a suggestion for such a drawing library?

Thanks,

 -Lee
回覆所有人
回覆作者
轉寄
0 則新訊息