Created
November 12, 2012 20:12
-
-
Save noidi/4061590 to your computer and use it in GitHub Desktop.
ClojureScript + three.js HelloWorld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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