Sunday, June 22, 2014

Alpha version of Quil on ClojureScript

I am phd student at Saratov State University and I am taking part in the GSOC 2014. My project is to add support for ClojureScript to Quil library.

What is Quil?

Quil is a Clojure wrapper for Processing Java library. It is used for creating animations. You can see a lot of examples here:
Nikita Beloglazov wrote a very good intro to Quil, check it if you don't have experience with Quil:

Currently Quil supports only desktop environment for running sketches. But Processing supported not only desktops. It works well inside the browsers (how you can see in previous examples).

For browser support, Processing uses Processing.js library which copies functionality of desktop version. It provides two approaches to make sketches:

  1. Write sketch fully in JavaScript;
  2. Write sketch in Processing Language and exporting it to pde format.

I chose for Quil on ClojureScript the first approach. This makes sence if we want to save maximal compatibility between desktop and browser sketches in Quil.

So, look at the following code:
With this code, we get here is a simple sketch (click on it to start/stop):

One more important thing about Quil on ClojureScript: You can control sketch from you html page. Look at this function:

They called when you push the button. Instead of stopping the sketch tthere might be a code which  changes sketch state or draw something.

So, if you want to play with previous example you can clone it from github and run with command lein run on your desktop. Or you can call lein compile and open web/index.html for running it in your browser.

If you are interested, you can get started by checking the following resources:

  1. - my working branch;
  2. - a lot of examples for Quil on ClojureScript
  3. Short docs about available macroses and functions.
Or you can create new project for sсratch with command lein new quil-cljs project-name

What about plans?

I'm going to do the following things before ClojureScript support is added to the main Quil repository:

  1. Add support for :advanced optimization level of Google Closure;
  2. Write more complete tests for ClojureScript part of Quil;
  3. Investigate a few strange behaviors in ClojureScript (like value of mousePressed inside mouseMoved event).

P.S. Quil middleware and fun-mode features are not be supported in this alpha but they will be supported in 2.0.1-SNAPSHOT.