proof of concept: add quil to ludus

This commit is contained in:
Scott Richmond 2023-03-25 15:52:25 -04:00
parent 1c2ab5182e
commit 55d76f6854
4 changed files with 49 additions and 10 deletions

2
.gitignore vendored
View File

@ -19,4 +19,4 @@ pom.xml.asc
**/.DS_Store **/.DS_Store
/sandbox /sandbox
ludus.sublime-workspace ludus.sublime-workspace
ludus /ludus

View File

@ -4,7 +4,8 @@
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :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/"} :url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.11.1"] :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"]] :plugins [[lein-cljfmt "0.8.0"]]
:repl-options {:init-ns ludus.core} :repl-options {:init-ns ludus.core}
:main ludus.core :main ludus.core

32
src/ludus/draw.clj Normal file
View File

@ -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]))

View File

@ -1,7 +1,8 @@
(ns ludus.prelude (ns ludus.prelude
(:require (:require
[ludus.data :as data] [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 ;; TODO: make eq, and, or special forms that short-circuit
;; Right now, they evaluate all their args ;; Right now, they evaluate all their args
@ -94,6 +95,10 @@
::data/type ::data/clj ::data/type ::data/clj
:body get}) :body get})
(def draw {:name "draw"
::data/type ::data/clj
:body draw/ludus-draw})
(def prelude {"eq" eq (def prelude {"eq" eq
"add" add "add" add
"print" print- "print" print-
@ -112,4 +117,5 @@
"assoc" assoc- "assoc" assoc-
"conj" conj- "conj" conj-
"get" get- "get" get-
"draw" draw
}) })