-
Notifications
You must be signed in to change notification settings - Fork 164
Snippets
Snippet is a small example that shows how to use some Quil function. Each function should have at least one snippets. Snippets have two important goals:
- Documentation. On quil.info/api snippets displayed under each function as example of how to use that function.
- Testing. When releasing new version of Quil we run all snippets on clj and cljs to make sure that they don't throw any errors. Though at the moment we don't check visually whether snippets produce desired output as there are too many functions to check manually. Ideally we'd have visual automated tests at some point.
When adding/changing Quil function author should add/modify corresponding snippets.
Snippets live in https://github.com/quil/quil/tree/master/src/cljc/quil/snippets folder. Structure of the folder follows category/subcategory of the functions. For example snippets for abs
function which has :category "Math" :subcategory "Calculation"
will be in the file math/calculation.cljc
. Snippet for the abs
function looks like the following:
(defsnippet abs
"abs"
{}
(q/background 255)
(q/fill 0)
(q/text (str "(q/abs -1) = " (q/abs -1)) 10 20)
(q/text (str "(q/abs -0.5) = " (q/abs -0.5)) 10 40))
Snippet is defined using defsnippet
macro. Name of the snippet doesn't really matter. It just need to be unique in the snippet file. Second argument is the name of the function this snippet is testing. For example in abs
snippet we use many Quil functions (background, fill, text, abs) but in fact snippet exercises only abs
.