From 124be0cd54f0879e269768fbbd5517157a666da8 Mon Sep 17 00:00:00 2001 From: Chris Hodapp Date: Thu, 9 Jul 2020 19:35:00 -0400 Subject: [PATCH] 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. --- project.clj | 32 +++++++++++++++-- resources/public/index.html | 11 ++++++ src/curlnoise/{core.clj => core.cljc} | 50 +++++++++------------------ 3 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 resources/public/index.html rename src/curlnoise/{core.clj => core.cljc} (85%) diff --git a/project.clj b/project.clj index f519c1e..1370ab7 100644 --- a/project.clj +++ b/project.clj @@ -3,7 +3,33 @@ :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :aot [curlnoise.core] - :main curlnoise.core + ;; :aot [curlnoise.core] + ;; :main curlnoise.core :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}}]}) diff --git a/resources/public/index.html b/resources/public/index.html new file mode 100644 index 0000000..616b325 --- /dev/null +++ b/resources/public/index.html @@ -0,0 +1,11 @@ + + + + curlnoise + + +
+ + + + diff --git a/src/curlnoise/core.clj b/src/curlnoise/core.cljc similarity index 85% rename from src/curlnoise/core.clj rename to src/curlnoise/core.cljc index cc9aaac..1ea8b5e 100644 --- a/src/curlnoise/core.clj +++ b/src/curlnoise/core.cljc @@ -1,12 +1,12 @@ (ns curlnoise.core - (:require [quil.core :as q] + (:require [quil.core :as q :include-macros true] [quil.middleware :as m])) (def framerate 30) (def res-x 800) (def res-y res-x) ;; Lower grid size produces more points -(def grid-size 25) +(def grid-size 50) ;; Lower alpha produces *longer* particle trails (def alpha 10) @@ -131,6 +131,7 @@ (defn draw-state [state] ;;(q/background 255) (q/fill 255 255 255 alpha) + (q/translate (- (/ res-x 2)) (- (/ res-y 2))) (q/rect 0 0 (q/width) (q/height)) (q/stroke 0) (q/stroke-weight 3) @@ -148,35 +149,16 @@ ;;(q/update-pixels) )) -(defn update-state-circles [state] - (update state :frame inc)) - -(defn draw-state-circles [state] - (q/background 240) - (q/fill 0 0 0) - (doseq [point (:grid state)] - (let [[i j px py] point - z (/ (:frame state) 50.0) - x (/ i 10.0) - y (/ j 10.0) - rad (int (* (q/noise x y z) grid-size))] - (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])) +(defn ^:export run-sketch [] + (q/defsketch curlnoise + :title "Curl Noise" + :host "curlnoise" + :size [res-x res-y] + :renderer :p3d + :setup setup + :update update-state + :draw draw-state + :features [:keep-on-top] + :middleware [m/fun-mode + ;;m/pause-on-error + ]))