Apdejti knjiznic, popravki, urejen project.clj
parent
836228b612
commit
eade024c25
20
project.clj
20
project.clj
|
@ -1,18 +1,18 @@
|
||||||
(defproject sliva "0.1.0-SNAPSHOT"
|
(defproject sliva "0.1.0-SNAPSHOT"
|
||||||
:description "FIXME: write this!"
|
:description "interactive visualization"
|
||||||
:url "http://example.com/FIXME"
|
:url "https://kreten.si"
|
||||||
:license {:name "Eclipse Public License"
|
:license {:name "GNU Affero General Public License"
|
||||||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:min-lein-version "2.7.1"
|
:min-lein-version "2.7.1"
|
||||||
|
|
||||||
:dependencies [[org.clojure/clojure "1.9.0-beta4"]
|
:dependencies [[org.clojure/clojure "1.9.0"]
|
||||||
[org.clojure/clojurescript "1.9.946"]
|
[org.clojure/clojurescript "1.10.312"]
|
||||||
[org.clojure/core.async "0.3.443"]]
|
[org.clojure/core.async "0.4.474"]]
|
||||||
|
|
||||||
:plugins [[lein-figwheel "0.5.14"]
|
:plugins [[lein-figwheel "0.5.16"]
|
||||||
[lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]]
|
[lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]]
|
||||||
|
|
||||||
:source-paths ["src"]
|
:source-paths ["src"]
|
||||||
|
@ -92,9 +92,9 @@
|
||||||
;; Setting up nREPL for Figwheel and ClojureScript dev
|
;; Setting up nREPL for Figwheel and ClojureScript dev
|
||||||
;; Please see:
|
;; Please see:
|
||||||
;; https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl
|
;; https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl
|
||||||
:profiles {:dev {:dependencies [[binaryage/devtools "0.9.4"]
|
:profiles {:dev {:dependencies [[binaryage/devtools "0.9.10"]
|
||||||
[figwheel-sidecar "0.5.14"]
|
[figwheel-sidecar "0.5.16"]
|
||||||
[com.cemerick/piggieback "0.2.2"]]
|
[cider/piggieback "0.3.6"]]
|
||||||
;; need to add dev source path here to get user.clj loaded
|
;; need to add dev source path here to get user.clj loaded
|
||||||
:source-paths ["src" "dev"]
|
:source-paths ["src" "dev"]
|
||||||
;; for CIDER
|
;; for CIDER
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
(ns sliva.core
|
(ns sliva.core)
|
||||||
(:require ))
|
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
|
@ -36,87 +35,102 @@
|
||||||
|
|
||||||
(def scena (THREE.Scene.))
|
(def scena (THREE.Scene.))
|
||||||
|
|
||||||
(def kamera (THREE.PerspectiveCamera. FOV (/ js/window.innerWidth js/innerHeight 0.1 2000)))
|
(def kamera (THREE.PerspectiveCamera. FOV (/ (.-innerWidth js/window)
|
||||||
|
(.-innerHeight js/window)) 0.1 2000))
|
||||||
(aset kamera "position" "z" odmik-kamere)
|
(aset kamera "position" "z" odmik-kamere)
|
||||||
(aset kamera "aspect" (/ js/window.innerWidth js/window.innerHeight))
|
(aset kamera "aspect" (/ (.-innerWidth js/window)
|
||||||
|
(.-innerHeight js/window)))
|
||||||
(.updateProjectionMatrix kamera)
|
(.updateProjectionMatrix kamera)
|
||||||
|
|
||||||
(def izris (THREE.WebGLRenderer. (js-obj "alpha" true)))
|
(def izris (THREE.WebGLRenderer. (js-obj "alpha" true)))
|
||||||
(.setSize izris js/window.innerWidth js/window.innerHeight)
|
(.setSize izris (.-innerWidth js/window) (.-innerHeight js/window))
|
||||||
|
|
||||||
;; Crno ozadje
|
;; Crno ozadje
|
||||||
(.setClearColor izris 0x000000 1)
|
(.setClearColor izris 0x000000 1)
|
||||||
|
|
||||||
(defn dodaj-obj [sirina]
|
(defn dodaj-obj [sirina]
|
||||||
(let [barva (js/THREE.Color.)
|
(let [barva (js/THREE.Color.)
|
||||||
mat (js/THREE.LineBasicMaterial. (js-obj "color" barva))
|
mat (js/THREE.LineBasicMaterial.)
|
||||||
geo (js/THREE.Geometry.)
|
geo (js/THREE.Geometry.)
|
||||||
|
koti (.-vertices geo)
|
||||||
zamik (/ sirina 2)
|
zamik (/ sirina 2)
|
||||||
-zamik (* -1 zamik)]
|
-zamik (* -1 zamik)]
|
||||||
|
|
||||||
;; Nastavi barvo novega objekta
|
;; Nastavi barvo novega objekta
|
||||||
(.setHSL barva (* @stevec zacetna-barva) saturacija svetlost)
|
(.setHSL barva (* @stevec zacetna-barva) saturacija svetlost)
|
||||||
|
(aset mat "color" barva)
|
||||||
|
|
||||||
;; Kvadratek (za nov objekt)
|
;; Kvadratek (za nov objekt)
|
||||||
(.push geo.vertices (js/THREE.Vector3. -zamik 0 0) (js/THREE.Vector3. 0 zamik 0))
|
(.push koti (js/THREE.Vector3. -zamik 0 0) (js/THREE.Vector3. 0 zamik 0))
|
||||||
(.push geo.vertices (js/THREE.Vector3. -zamik 0 0) (js/THREE.Vector3. 0 -zamik 0))
|
(.push koti (js/THREE.Vector3. -zamik 0 0) (js/THREE.Vector3. 0 -zamik 0))
|
||||||
(.push geo.vertices (js/THREE.Vector3. zamik 0 0) (js/THREE.Vector3. 0 zamik 0))
|
(.push koti (js/THREE.Vector3. zamik 0 0) (js/THREE.Vector3. 0 zamik 0))
|
||||||
(.push geo.vertices (js/THREE.Vector3. zamik 0 0) (js/THREE.Vector3. 0 -zamik 0))
|
(.push koti (js/THREE.Vector3. zamik 0 0) (js/THREE.Vector3. 0 -zamik 0))
|
||||||
|
|
||||||
(let [obj (js/THREE.Line. geo mat js/THREE.LineSegments)]
|
(let [obj (js/THREE.Line. geo mat (.-LineSegments js/THREE))
|
||||||
|
novi-objekti (conj (take obj-limit @objekti)
|
||||||
|
obj)]
|
||||||
(.add scena obj)
|
(.add scena obj)
|
||||||
|
|
||||||
;; pucaj sceno ane
|
;; pucaj sceno ane
|
||||||
(swap! objekti conj obj)
|
(reset! objekti novi-objekti))))
|
||||||
(swap! objekti #(take obj-limit %1)))))
|
|
||||||
|
|
||||||
(defn obj-anim [obj]
|
(defn obj-anim [obj]
|
||||||
(.rotateY obj rotacija-y)
|
(.rotateY obj rotacija-y)
|
||||||
(.rotateZ obj rotacija-z)
|
(.rotateZ obj rotacija-z)
|
||||||
(.rotateX obj rotacija-x)
|
(.rotateX obj rotacija-x)
|
||||||
|
|
||||||
(let [new-scale (+ obj.scale.x w-diff)]
|
(let [new-scale (+ (aget obj "scale" "x")
|
||||||
|
w-diff)]
|
||||||
(aset obj "scale" "x" new-scale)
|
(aset obj "scale" "x" new-scale)
|
||||||
(aset obj "scale" "y" new-scale)
|
(aset obj "scale" "y" new-scale)
|
||||||
(aset obj "scale" "z" new-scale))
|
(aset obj "scale" "z" new-scale))
|
||||||
|
|
||||||
|
(.offsetHSL (aget obj "material" "color") zamik-barve 0 0))
|
||||||
(.offsetHSL obj.material.color zamik-barve 0 0))
|
|
||||||
|
|
||||||
(defn cam-rotate []
|
(defn cam-rotate []
|
||||||
(.translateX kamera rotacija-kamere)
|
(.translateX kamera rotacija-kamere)
|
||||||
(.translateZ kamera (- odmik-kamere
|
(.translateZ kamera (- odmik-kamere
|
||||||
(.sqrt js/Math (+ (.pow js/Math odmik-kamere 2)
|
(.sqrt js/Math (+ (.pow js/Math odmik-kamere 2)
|
||||||
(.pow js/Math rotacija-kamere 2))))))
|
(.pow js/Math rotacija-kamere 2)))))
|
||||||
|
(.lookAt kamera scena.position))
|
||||||
|
|
||||||
(defn render []
|
(defn render []
|
||||||
(js/requestAnimationFrame render)
|
(js/requestAnimationFrame render)
|
||||||
|
|
||||||
(swap! stevec inc)
|
(reset! stevec (inc @stevec))
|
||||||
|
|
||||||
(if (= 0 (rem @stevec gostota-obj)) (dodaj-obj lik-sirina))
|
(if (= 0 (rem @stevec gostota-obj))
|
||||||
|
(dodaj-obj lik-sirina))
|
||||||
|
|
||||||
(.render izris scena kamera)
|
(.render izris scena kamera)
|
||||||
|
|
||||||
(run! obj-anim @objekti))
|
(run! obj-anim @objekti)
|
||||||
;;(cam-rotate))
|
(cam-rotate))
|
||||||
|
|
||||||
|
(defn start-render []
|
||||||
|
(let [container (.getElementById js/document "container")]
|
||||||
|
(.appendChild container (.-domElement izris))))
|
||||||
|
|
||||||
|
(defn stop-render []
|
||||||
|
(let [container (.getElementById js/document "container")]
|
||||||
|
(.removeChild container (.-firstChild container))))
|
||||||
|
|
||||||
;; Zacetek ;;
|
;; Zacetek ;;
|
||||||
(aset js/document "onreadystatechange"
|
(aset js/document "onreadystatechange"
|
||||||
(fn []
|
(fn []
|
||||||
(if (= js/document.readyState "complete")
|
(if (= (.-readyState js/document) "complete")
|
||||||
(let [container (.getElementById js/document "container")]
|
(start-render)
|
||||||
(.appendChild container izris.domElement)
|
(render))))
|
||||||
(render)))))
|
|
||||||
|
|
||||||
(defn on-js-reload []
|
(defn on-js-reload []
|
||||||
;; optionally touch your app-state to force rerendering depending on
|
(stop-render)
|
||||||
;; your application
|
(start-render))
|
||||||
;; (swap! app-state update-in [:__figwheel_counter] inc)
|
|
||||||
)
|
|
||||||
|
|
||||||
;; Hendlaj risajz
|
;; Hendlaj risajz
|
||||||
(defn on-window-resize[]
|
(defn on-window-resize[]
|
||||||
(aset kamera "aspect" (/ js/window.innerWidth js/window.innerHeight))
|
(let [sirina (.-innerWidth js/window)
|
||||||
(.updateProjectionMatrix kamera)
|
visina (.-innerHeight js/window)]
|
||||||
(.setSize izris js/window.innerWidth js/window.innerHeight))
|
(aset kamera "aspect" (/ sirina visina))
|
||||||
|
(.updateProjectionMatrix kamera)
|
||||||
|
(.setSize izris sirina visina)))
|
||||||
(.addEventListener js/window "resize" on-window-resize false)
|
(.addEventListener js/window "resize" on-window-resize false)
|
||||||
|
|
Loading…
Reference in New Issue