2018-08-10 18:29:18 +02:00
|
|
|
(ns sliva.pages.gibanica
|
|
|
|
(:require [reagent.core :as reagent]
|
|
|
|
[sliva.data :refer [appstate]]
|
|
|
|
[sliva.pages.navigation :refer [navigation]]
|
|
|
|
[sliva.socket :refer [send-message]]))
|
|
|
|
|
|
|
|
(defn motion-track [event]
|
|
|
|
(let [pospesek (.-acceleration event)
|
|
|
|
gibX (.-x pospesek)
|
|
|
|
gibY (.-y pospesek)
|
|
|
|
gibZ (.-z pospesek)
|
|
|
|
cas (-> (js/Date.)
|
|
|
|
(.valueOf))]
|
2018-08-10 21:45:24 +02:00
|
|
|
(send-message "motion" cas gibX gibY gibZ)))
|
2018-08-10 18:29:18 +02:00
|
|
|
|
|
|
|
(defn start-motion-track []
|
|
|
|
(.addEventListener js/window "devicemotion" motion-track))
|
|
|
|
|
|
|
|
(defn stop-motion-track []
|
|
|
|
(.removeEventListener js/window "devicemotion" motion-track))
|
|
|
|
|
2018-08-10 21:45:24 +02:00
|
|
|
(defn rotation-track [event]
|
|
|
|
(let [alpha (.-alpha event)
|
|
|
|
beta (.-beta event)
|
|
|
|
gamma (.-gamma event)
|
|
|
|
cas (-> (js/Date.)
|
|
|
|
(.valueOf))]
|
|
|
|
(send-message "rotation" cas alpha beta gamma)))
|
|
|
|
|
|
|
|
(defn start-rotation-track []
|
|
|
|
(.addEventListener js/window "deviceorientation" rotation-track))
|
|
|
|
|
|
|
|
(defn stop-rotation-track []
|
|
|
|
(.removeEventListener js/window "deviceorientation" rotation-track))
|
|
|
|
|
2018-08-10 18:29:18 +02:00
|
|
|
(defn gibanica []
|
|
|
|
(reagent/create-class
|
|
|
|
{:display-name "gibanica"
|
2018-08-10 21:45:24 +02:00
|
|
|
:component-did-mount (fn []
|
|
|
|
(start-motion-track)
|
|
|
|
(start-rotation-track))
|
|
|
|
:component-will-unmount (fn []
|
|
|
|
(stop-motion-track)
|
|
|
|
(stop-rotation-track))
|
|
|
|
:reagent-render
|
|
|
|
(fn []
|
|
|
|
[:div
|
|
|
|
[:h3 "gibaj me!"]
|
|
|
|
(let [vizual [:vizual @appstate]]
|
|
|
|
[:input {:type "range"
|
|
|
|
:min 0
|
|
|
|
:max 50}])
|
|
|
|
[navigation]])}))
|
2018-08-10 18:29:18 +02:00
|
|
|
|