Skip to content

Commit

Permalink
[#15] current-frame-rate, target-frame-rate
Browse files Browse the repository at this point in the history
  • Loading branch information
jfacorro committed Nov 24, 2018
1 parent 417b5b6 commit 45570a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/doodler/core.clje
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,19 @@

(defn frame-count
[]
(:frame-count *sketch*))
(*sketch* :frame-count))

(defn target-frame-rate
[]
(*internal-state* :frame-rate))

(defn current-frame-rate
[]
(let [diff (erlang/- (u/time-mark) (:epoch *sketch*))]
(if (pos? diff)
(erlang/div (erlang/* (:frame-count *sketch*) 1000)
diff)
0)))

(defmacro defsketch
[name & opts]
Expand Down
2 changes: 2 additions & 0 deletions src/doodler/examples/shapes.clje
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
(d/text (str "Fill: " (d/current-fill)) 100 10)
(d/text (str "Stroke: " (d/current-stroke)) 100 30)
(d/text (str "Frame #: " (d/frame-count)) 100 50)
(d/text (str "Target Frame Rate: " (d/target-frame-rate)) 100 70)
(d/text (str "Frame Rate: " (d/current-frame-rate)) 100 90)

)

Expand Down
3 changes: 2 additions & 1 deletion src/doodler/sketch.clje
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@
:draw-fn draw-fn
:on-resize on-resize
:on-close on-close-fn
:frame-count 0}
:frame-count 0
:epoch (u/time-mark)}
;; Create bitmap after frame is visible to
;; get the right dimensions
(let [bitmap (make-bitmap canvas)
Expand Down

0 comments on commit 45570a1

Please sign in to comment.