Add working cljs version
Use 'lein compile' or 'lein figwheel'. Still figuring out details like how to make it compatible with normal Clojure simultaneously. However, code changes were pretty minimal.
This commit is contained in:
parent
5a36660d65
commit
124be0cd54
32
project.clj
32
project.clj
@ -3,7 +3,33 @@
|
|||||||
:url "http://example.com/FIXME"
|
:url "http://example.com/FIXME"
|
||||||
:license {:name "Eclipse Public License"
|
:license {:name "Eclipse Public License"
|
||||||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||||
:aot [curlnoise.core]
|
;; :aot [curlnoise.core]
|
||||||
:main curlnoise.core
|
;; :main curlnoise.core
|
||||||
:dependencies [[org.clojure/clojure "1.10.1"]
|
:dependencies [[org.clojure/clojure "1.10.1"]
|
||||||
[quil "3.1.0"]])
|
[quil "3.1.0"]
|
||||||
|
[org.clojure/clojurescript "1.10.520"]]
|
||||||
|
|
||||||
|
:plugins [[lein-cljsbuild "1.1.7"]
|
||||||
|
[lein-figwheel "0.5.19"]]
|
||||||
|
:hooks [leiningen.cljsbuild]
|
||||||
|
|
||||||
|
:clean-targets ^{:protect false} ["resources/public/js"]
|
||||||
|
:cljsbuild
|
||||||
|
{:builds [; development build with figwheel hot swap
|
||||||
|
{:id "development"
|
||||||
|
:source-paths ["src"]
|
||||||
|
:figwheel true
|
||||||
|
:compiler
|
||||||
|
{:main "curlnoise.core"
|
||||||
|
:output-to "resources/public/js/main.js"
|
||||||
|
:output-dir "resources/public/js/development"
|
||||||
|
:asset-path "js/development"}}
|
||||||
|
; minified and bundled build for deployment
|
||||||
|
{:id "optimized"
|
||||||
|
:source-paths ["src"]
|
||||||
|
:compiler
|
||||||
|
{:main "curlnoise.core"
|
||||||
|
:output-to "resources/public/js/main.js"
|
||||||
|
:output-dir "resources/public/js/optimized"
|
||||||
|
:asset-path "js/optimized"
|
||||||
|
:optimizations :advanced}}]})
|
||||||
|
|||||||
11
resources/public/index.html
Normal file
11
resources/public/index.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>curlnoise</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="curlnoise"></div>
|
||||||
|
<script src="js/main.js"></script>
|
||||||
|
<script>curlnoise.core.run_sketch()</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -1,12 +1,12 @@
|
|||||||
(ns curlnoise.core
|
(ns curlnoise.core
|
||||||
(:require [quil.core :as q]
|
(:require [quil.core :as q :include-macros true]
|
||||||
[quil.middleware :as m]))
|
[quil.middleware :as m]))
|
||||||
|
|
||||||
(def framerate 30)
|
(def framerate 30)
|
||||||
(def res-x 800)
|
(def res-x 800)
|
||||||
(def res-y res-x)
|
(def res-y res-x)
|
||||||
;; Lower grid size produces more points
|
;; Lower grid size produces more points
|
||||||
(def grid-size 25)
|
(def grid-size 50)
|
||||||
;; Lower alpha produces *longer* particle trails
|
;; Lower alpha produces *longer* particle trails
|
||||||
(def alpha 10)
|
(def alpha 10)
|
||||||
|
|
||||||
@ -131,6 +131,7 @@
|
|||||||
(defn draw-state [state]
|
(defn draw-state [state]
|
||||||
;;(q/background 255)
|
;;(q/background 255)
|
||||||
(q/fill 255 255 255 alpha)
|
(q/fill 255 255 255 alpha)
|
||||||
|
(q/translate (- (/ res-x 2)) (- (/ res-y 2)))
|
||||||
(q/rect 0 0 (q/width) (q/height))
|
(q/rect 0 0 (q/width) (q/height))
|
||||||
(q/stroke 0)
|
(q/stroke 0)
|
||||||
(q/stroke-weight 3)
|
(q/stroke-weight 3)
|
||||||
@ -148,35 +149,16 @@
|
|||||||
;;(q/update-pixels)
|
;;(q/update-pixels)
|
||||||
))
|
))
|
||||||
|
|
||||||
(defn update-state-circles [state]
|
(defn ^:export run-sketch []
|
||||||
(update state :frame inc))
|
(q/defsketch curlnoise
|
||||||
|
:title "Curl Noise"
|
||||||
(defn draw-state-circles [state]
|
:host "curlnoise"
|
||||||
(q/background 240)
|
:size [res-x res-y]
|
||||||
(q/fill 0 0 0)
|
:renderer :p3d
|
||||||
(doseq [point (:grid state)]
|
:setup setup
|
||||||
(let [[i j px py] point
|
:update update-state
|
||||||
z (/ (:frame state) 50.0)
|
:draw draw-state
|
||||||
x (/ i 10.0)
|
:features [:keep-on-top]
|
||||||
y (/ j 10.0)
|
:middleware [m/fun-mode
|
||||||
rad (int (* (q/noise x y z) grid-size))]
|
;;m/pause-on-error
|
||||||
(q/ellipse px py rad rad))))
|
]))
|
||||||
|
|
||||||
(q/defsketch curlnoise
|
|
||||||
:title "Curl Noise"
|
|
||||||
:size [res-x res-y]
|
|
||||||
:setup setup
|
|
||||||
:update update-state
|
|
||||||
:draw draw-state
|
|
||||||
:features [:keep-on-top]
|
|
||||||
:middleware [m/fun-mode m/pause-on-error])
|
|
||||||
|
|
||||||
(defn -main [& args]
|
|
||||||
(q/sketch
|
|
||||||
:title "Curl Noise"
|
|
||||||
:size [res-x res-y]
|
|
||||||
:setup setup
|
|
||||||
:update update-state
|
|
||||||
:draw draw-state
|
|
||||||
:features []
|
|
||||||
:middleware [m/fun-mode]))
|
|
||||||
Loading…
x
Reference in New Issue
Block a user