Simple way of having multiple sketches in quil-cljs

49 views
Skip to first unread message

Greg Goltsov

unread,
Nov 19, 2017, 4:25:24 PM11/19/17
to clj-processing
Hi everyone,

I'm quite new to Clojure/Script and Quil, and have been having a slight problem with the project structure.

I prefer using CLJS for Quil experiments (mostly because of Figwheel hot reloading). While learning, you really want to just have a library of sketches that you can refer to, and easily re-run. I noticed that it's fairly easy to do in Clojure Quil (best example is the Quil examples themselves). A simple

(defn -main [& args])

at the end of the sketch file does the trick. Then you can just lein run -m <sketch file>, or (require ...) straight in the REPL.

I've been looking for a way of doing the same with CLJS, and have not really found one yet. I know that in the project.clj, :cljsbuild specifies the main function, so that would probably have to change depending on what sketch will need to be run. Or would I need to have some require logic in the project's core.cljs?

I also saw Nikita's answers to a very similar questions in the much-earlier Using Quil as a library, instance many sketches thread, however I couldn't really adapt it to make it work.

My desired workflow: having a folder full of different sketches (just like in quil-examples), and being able to either just load whichever one I want via C-C C-k, or require'ing the ns in the REPL, or something similar.

Any help is much appreciated.

Cheers,
Greg

Nikita Beloglazov

unread,
Nov 22, 2017, 1:04:39 AM11/22/17
to clj-pro...@googlegroups.com
Hi Greg

In the case of cljs you could do something similar to what quil.info is doing. Each sketch is defined in its own cljs file. At the end of each sketch they call "register-example!" and pass initialization function. Then there is a main cljs file that defines register-example!. What register-example! does is it stores sketch info (name + initialization function) in a list and then it can render a list of sketch names. Upon clicking on a sketch name it will lookup initialization function for the sketch and runs it. When you add new example cljs file cljsbuild should recompile everything and upon browser refresh you'll see the new sketch in the list.


It requires some work implementing register-example! and rendering list of sketches. Though you won't be able to do C-C C-k thing and it requires interaction with a web page. I haven't worked with figweel much so don't know how to implement your desired workflow there.

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.
Reply all
Reply to author
Forward
0 new messages