-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.cljc
42 lines (36 loc) · 885 Bytes
/
core.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(ns quiltools.core
(:require [quil.core :as q]
[quil.middleware :as m]))
(defn stroke-weight
"gets the stroke weight of the current graphics context"
[]
(.strokeWeight (q/current-graphics)))
(defn spin
"returns a draw-fn which draws `p` at angle `theta`"
[theta p]
(fn []
(q/with-rotation [theta] (p))))
(defn at
"returns a draw-fn which draws `p` at origin `[x y]`"
[x y p]
(fn []
(q/with-translation [x y] (p))))
(defn in
"returns a draw-fn which draws `p` in a box of size `[w h]`"
[w h p]
(fn []
(q/push-matrix)
(q/push-style)
(q/stroke-weight (/ (stroke-weight) (/ (+ w h) 2)))
(q/scale w h)
(p)
(q/pop-style)
(q/pop-matrix)))
(defn divides?
"returns `true` if `d` divides `n`"
[n d]
(zero? (mod n d)))
(defn n-ticks?
"returns true only every `n` ticks"
[n]
(divides? (q/frame-count) n))