Skip to content

Instantly share code, notes, and snippets.

@noidi
Created November 12, 2012 20:12
Show Gist options
  • Save noidi/4061590 to your computer and use it in GitHub Desktop.
Save noidi/4061590 to your computer and use it in GitHub Desktop.
ClojureScript + three.js HelloWorld
(ns cljs-hello.hello
(:require-macros [cljs-hello.macros :as m]))
(defn make-world []
(let [geometry (THREE.CubeGeometry. 200 200 200)
material (THREE.MeshBasicMaterial. (js* "{color: 0xff0000,
wireframe: true}"))
mesh (THREE.Mesh. geometry material)
scene (doto (THREE.Scene.)
(.add mesh))
renderer (doto (THREE.CanvasRenderer.)
(.setSize (.-innerWidth js/window) (.-innerHeight js/window)))
camera (doto (THREE.PerspectiveCamera. 75 (/ (.-innerWidth js/window)
(.-innerHeight js/window))
1 10000)
(-> .-position .-z (set! 1000)))]
(-> js/document .-body (.appendChild (.-domElement renderer)))
{:mesh mesh
:renderer renderer
:scene scene
:camera camera}))
(defn animate [{:keys [mesh renderer scene camera]
:as world}]
(js/requestAnimationFrame (partial animate world))
(m/+= (-> mesh .-rotation .-x) 0.01)
(m/+= (-> mesh .-rotation .-y) 0.02)
(.render renderer scene camera))
(animate (make-world))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment