Skip to content

Commit

Permalink
Merge pull request #45 from clojerl/15-rotate-functions
Browse files Browse the repository at this point in the history
[#15] Add rotate and with-rotation functions
  • Loading branch information
jfacorro authored Oct 10, 2021
2 parents 28b44fa + 192e51e commit b8ad844
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/doodler/core.clje
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,20 @@
([tx ty] (p/translate *canvas* tx ty))
([tx ty tz] (throw "Unsupported")))

(defmacro with-rotation
[rotation & body]
`(let [tr# ~rotation]
(doodler.core/push-matrix)
(try
(apply doodler.core/rotate tr#)
~@body
(finally
(doodler.core/pop-matrix)))))

(defn rotate
[angle]
(p/rotate *canvas* angle))

;; Drawing

(defn arc
Expand Down
1 change: 1 addition & 0 deletions src/doodler/examples/tailspin.clje
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

(defn draw-state [state]
(d/background 255)
(d/stroke 0)
(d/fill 0)
(let [dots (:dots state)]
(loop [curr (first dots)
Expand Down
22 changes: 22 additions & 0 deletions src/doodler/examples/transformations.clje
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(ns doodler.examples.transformations
(:require [doodler.core :as d]))

(defn setup
[]
(d/frame-rate 10))

(defn draw []
(d/stroke (rand-int 256) (rand-int 256) (rand-int 256))
(d/fill (rand-int 256) (rand-int 256) (rand-int 256))
(d/with-translation [(float (rand-int 100)) (float (rand-int 100))]
(d/with-rotation [(float (rand-int 360))]
(d/rect 0.0 0.0 10.0 10.0))))

(d/defsketch sketch
:title "Transformations"
:size [100 100]
:setup setup
:draw draw
:features [:resizable :keep-on-top]
:bgcolor [200]
:open-gl true)

0 comments on commit b8ad844

Please sign in to comment.