Apdejti knjiznic, popravki, urejen project.clj

master
Jure Podgoršek 2018-06-18 01:05:40 +02:00
parent 836228b612
commit eade024c25
2 changed files with 56 additions and 42 deletions

View File

@ -1,18 +1,18 @@
(defproject sliva "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:description "interactive visualization"
:url "https://kreten.si"
:license {:name "GNU Affero General Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:min-lein-version "2.7.1"
:dependencies [[org.clojure/clojure "1.9.0-beta4"]
[org.clojure/clojurescript "1.9.946"]
[org.clojure/core.async "0.3.443"]]
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.10.312"]
[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]]]]
:source-paths ["src"]
@ -92,9 +92,9 @@
;; Setting up nREPL for Figwheel and ClojureScript dev
;; Please see:
;; https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl
:profiles {:dev {:dependencies [[binaryage/devtools "0.9.4"]
[figwheel-sidecar "0.5.14"]
[com.cemerick/piggieback "0.2.2"]]
:profiles {:dev {:dependencies [[binaryage/devtools "0.9.10"]
[figwheel-sidecar "0.5.16"]
[cider/piggieback "0.3.6"]]
;; need to add dev source path here to get user.clj loaded
:source-paths ["src" "dev"]
;; for CIDER

View File

@ -1,5 +1,4 @@
(ns sliva.core
(:require ))
(ns sliva.core)
(enable-console-print!)
@ -36,87 +35,102 @@
(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 "aspect" (/ js/window.innerWidth js/window.innerHeight))
(aset kamera "aspect" (/ (.-innerWidth js/window)
(.-innerHeight js/window)))
(.updateProjectionMatrix kamera)
(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
(.setClearColor izris 0x000000 1)
(defn dodaj-obj [sirina]
(let [barva (js/THREE.Color.)
mat (js/THREE.LineBasicMaterial. (js-obj "color" barva))
mat (js/THREE.LineBasicMaterial.)
geo (js/THREE.Geometry.)
koti (.-vertices geo)
zamik (/ sirina 2)
-zamik (* -1 zamik)]
;; Nastavi barvo novega objekta
(.setHSL barva (* @stevec zacetna-barva) saturacija svetlost)
(aset mat "color" barva)
;; Kvadratek (za nov objekt)
(.push geo.vertices (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 geo.vertices (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 koti (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 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)
;; pucaj sceno ane
(swap! objekti conj obj)
(swap! objekti #(take obj-limit %1)))))
(reset! objekti novi-objekti))))
(defn obj-anim [obj]
(.rotateY obj rotacija-y)
(.rotateZ obj rotacija-z)
(.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" "y" new-scale)
(aset obj "scale" "z" new-scale))
(.offsetHSL obj.material.color zamik-barve 0 0))
(.offsetHSL (aget obj "material" "color") zamik-barve 0 0))
(defn cam-rotate []
(.translateX kamera rotacija-kamere)
(.translateZ kamera (- odmik-kamere
(.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 []
(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)
(run! obj-anim @objekti))
;;(cam-rotate))
(run! obj-anim @objekti)
(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 ;;
(aset js/document "onreadystatechange"
(fn []
(if (= js/document.readyState "complete")
(let [container (.getElementById js/document "container")]
(.appendChild container izris.domElement)
(render)))))
(if (= (.-readyState js/document) "complete")
(start-render)
(render))))
(defn on-js-reload []
;; optionally touch your app-state to force rerendering depending on
;; your application
;; (swap! app-state update-in [:__figwheel_counter] inc)
)
(stop-render)
(start-render))
;; Hendlaj risajz
(defn on-window-resize[]
(aset kamera "aspect" (/ js/window.innerWidth js/window.innerHeight))
(.updateProjectionMatrix kamera)
(.setSize izris js/window.innerWidth js/window.innerHeight))
(let [sirina (.-innerWidth js/window)
visina (.-innerHeight js/window)]
(aset kamera "aspect" (/ sirina visina))
(.updateProjectionMatrix kamera)
(.setSize izris sirina visina)))
(.addEventListener js/window "resize" on-window-resize false)