Skip to content

Instantly share code, notes, and snippets.

@mikebelanger
Created September 12, 2016 14:40
Show Gist options
  • Save mikebelanger/8e9c77c0295509682c976b375d755ce3 to your computer and use it in GitHub Desktop.
Save mikebelanger/8e9c77c0295509682c976b375d755ce3 to your computer and use it in GitHub Desktop.
;;Using the threejs bindings from : https://clojars.org/cljsjs/three
(ns minimal-cljs.core
(:require cljsjs.three))
(defn init []
;;First initiate the basic elements of a THREE scene
(let [scene (js/THREE.Scene.)
p-camera (js/THREE.PerspectiveCamera.
view-angle aspect near far)
box (js/THREE.BoxGeometry.
200 200 200)
mat (js/THREE.MeshBasicMaterial.
(js-obj "color" 0xff0000
"wireframe" true))
mesh (js/THREE.Mesh. box mat)
renderer (js/THREE.WebGLRenderer.)]
;;Change the starting position of cube and camera
(aset p-camera "name" "p-camera")
(aset p-camera "position" "z" 500)
(aset mesh "rotation" "x" 45)
(aset mesh "rotation" "y" 0)
(.setSize renderer 500 500)
;;Add camera, mesh and box to scene and then that to DOM node.
(.add scene p-camera)
(.add scene mesh)
(.appendChild js/document.body (.-domElement renderer))
;Kick off the animation loop updating
(defn render []
(aset mesh "rotation" "y" (+ 0.01 (.-y (.-rotation mesh))))
(.render renderer scene p-camera))
(defn animate []
(.requestAnimationFrame js/window animate)
(render))
(animate)))
(init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment