Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Three.js demo with ClojureScript. Actually works.
(ns three.demo)
(def THREE js/THREE)
(def camera (THREE.PerspectiveCamera. 75 (/ (.-innerWidth js/window)
(.-innerHeight js/window)) 1 10000))
(set! (.-z (.-position camera)) 1000)
(def scene (THREE.Scene.))
(def geometry (THREE.CubeGeometry. 200 200 200))
(def obj (js/Object.))
(set! (.-color obj) 0xff0000)
(set! (.-wireframe obj) true)
(def material (THREE.MeshBasicMaterial. obj))
(def mesh (THREE.Mesh. geometry material))
(.add scene mesh)
(def renderer (THREE.CanvasRenderer.))
(.setSize renderer (.-innerWidth js/window) (.-innerHeight js/window))
(.appendChild (.-body js/document) (.-domElement renderer))
(defn render []
(set! (.-x (.-rotation mesh)) (+ (.-x (.-rotation mesh)) 0.01))
(set! (.-y (.-rotation mesh)) (+ (.-y (.-rotation mesh)) 0.02))
(.render renderer scene camera))
(defn animate []
(.requestAnimationFrame js/window animate)
(render))
(animate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.