From 55d76f6854bf67119873d98e2c9c18d8390ab90a Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sat, 25 Mar 2023 15:52:25 -0400 Subject: [PATCH] proof of concept: add quil to ludus --- .gitignore | 2 +- project.clj | 3 ++- src/ludus/draw.clj | 32 ++++++++++++++++++++++++++++++++ src/ludus/prelude.clj | 22 ++++++++++++++-------- 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 src/ludus/draw.clj diff --git a/.gitignore b/.gitignore index b41fa4f..dee6131 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ pom.xml.asc **/.DS_Store /sandbox ludus.sublime-workspace -ludus \ No newline at end of file +/ludus \ No newline at end of file diff --git a/project.clj b/project.clj index d0c36f5..1e7b261 100644 --- a/project.clj +++ b/project.clj @@ -4,7 +4,8 @@ :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} :dependencies [[org.clojure/clojure "1.11.1"] - [babashka/fs "0.1.6"]] + [babashka/fs "0.1.6"] + [quil "4.0.0-SNAPSHOT-1"]] :plugins [[lein-cljfmt "0.8.0"]] :repl-options {:init-ns ludus.core} :main ludus.core diff --git a/src/ludus/draw.clj b/src/ludus/draw.clj new file mode 100644 index 0000000..5bc82e8 --- /dev/null +++ b/src/ludus/draw.clj @@ -0,0 +1,32 @@ +(ns ludus.draw + (:require [quil.core :as q] + [quil.middleware :as m])) + +(defn setup [] + (q/frame-rate 60) + (q/color-mode :hsb) + {:color 0 :angle 0}) + +(defn update-state [state] + {:color (mod (+ (:color state) 0.7) 255) + :angle (+ (:angle state) 0.1)}) + +(defn draw-state [state] + (q/background 240) + (q/fill (:color state) 255 255) + (let [angle (:angle state) + x (* 150 (q/cos angle)) + y (* 150 (q/sin angle))] + (q/with-translation [(/ (q/width) 2) + (/ (q/height) 2)] + (q/ellipse x y 100 100)))) + +(defn ludus-draw [] + (q/defsketch sketch + :title "Hello Ludus" + :size [500 500] + :setup setup + :update update-state + :draw draw-state + :features [] + :middleware [m/fun-mode])) diff --git a/src/ludus/prelude.clj b/src/ludus/prelude.clj index 41ec6f9..62cd803 100644 --- a/src/ludus/prelude.clj +++ b/src/ludus/prelude.clj @@ -1,7 +1,8 @@ (ns ludus.prelude (:require [ludus.data :as data] - [ludus.show :as show])) + [ludus.show :as show] + [ludus.draw :as draw])) ;; TODO: make eq, and, or special forms that short-circuit ;; Right now, they evaluate all their args @@ -83,16 +84,20 @@ :body (fn [ms] (Thread/sleep ms))}) (def conj- {:name "conj" - ::data/type ::data/clj - :body conj}) + ::data/type ::data/clj + :body conj}) (def assoc- {:name "assoc" - ::data/type ::data/clj - :body assoc}) + ::data/type ::data/clj + :body assoc}) (def get- {:name "get" - ::data/type ::data/clj - :body get}) + ::data/type ::data/clj + :body get}) + +(def draw {:name "draw" + ::data/type ::data/clj + :body draw/ludus-draw}) (def prelude {"eq" eq "add" add @@ -112,4 +117,5 @@ "assoc" assoc- "conj" conj- "get" get- - }) \ No newline at end of file + "draw" draw + })