Created
July 7, 2020 16:10
-
-
Save mbrc12/4585c2d70b1d8b37803d676edfe56851 to your computer and use it in GitHub Desktop.
cljs/three.js test
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
<!-- /public/index.html --> | |
<html> | |
<script src = "/js/main.js"></script> | |
<script>window.onload = cjs1.main.main </script> | |
<style> | |
body { margin: 0; } | |
canvas { display: block; } | |
</style> | |
<body> | |
</body> | |
</html> |
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
;; /src/cjs1/macros.clj | |
(ns cjs1.macros) | |
(defmacro update! [x f] | |
`(set! ~x (~f ~x))) |
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
;; /src/cjs1/main.cljs | |
(ns cjs1.main | |
(:require [cjs1.util :as u] | |
["three" :as t]) | |
(:require-macros [cjs1.macros :as m])) | |
(defn log | |
[wtf] | |
(.log js/console wtf)) | |
(defn cube | |
[] | |
(let [geom (t/BoxGeometry. 200 200 200) | |
params #js {"color" 0x00ff00} | |
matr (t/MeshBasicMaterial. params) | |
cube (t/Mesh. geom matr)] | |
(log params) | |
cube)) | |
(defn main | |
[] | |
(let [body (. js/document -body) | |
; WIDTH (/ js/window.innerWidth 2) | |
; HEIGHT (/ js/window.innerHeight 2) | |
WIDTH (.-innerWidth js/window) | |
HEIGHT (.-innerHeight js/window) | |
scene (t/Scene.) | |
camera (t/PerspectiveCamera. 75 (/ WIDTH HEIGHT) 0.1 1000.0) | |
renderer (t/WebGLRenderer.) | |
cube- (cube)] | |
(.setSize renderer WIDTH HEIGHT) | |
(.appendChild body (.-domElement renderer)) | |
(log (str cube-)) | |
(.add scene cube-) | |
(set! (.. camera.position -z) 5) | |
(defn animator [] | |
; (log (.getTime (js/Date.))) | |
(.requestAnimationFrame js/window animator) | |
(m/update! (.. cube-.rotation -x) inc) | |
; (log (.. cube- -rotation -x)) | |
(.render renderer scene camera)) | |
(animator))) |
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
{ | |
"name": "cjs1", | |
"version": "1.0.0", | |
"description": "", | |
"main": "public/index.html", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"three.js": "^0.77.1" | |
}, | |
"devDependencies": { | |
"shadow-cljs": "^2.10.14" | |
} | |
} |
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
{:source-paths ["src"] | |
:dependencies [[appliedscience/js-interop "0.2.4"]] | |
:nrepl {:port 9999} | |
:builds | |
{:app {:target :browser | |
:output-dir "public/js" | |
:asset-path "js/" | |
:modules {:main {:entries [cjs1.main]}} | |
:devtools | |
{:http-root "public" | |
:http-port 8001}}}} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment