proof of concept: add quil to ludus
This commit is contained in:
parent
1c2ab5182e
commit
55d76f6854
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -19,4 +19,4 @@ pom.xml.asc
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
/sandbox
|
/sandbox
|
||||||
ludus.sublime-workspace
|
ludus.sublime-workspace
|
||||||
ludus
|
/ludus
|
|
@ -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
32
src/ludus/draw.clj
Normal 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]))
|
|
@ -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
|
||||||
|
@ -83,16 +84,20 @@
|
||||||
:body (fn [ms] (Thread/sleep ms))})
|
:body (fn [ms] (Thread/sleep ms))})
|
||||||
|
|
||||||
(def conj- {:name "conj"
|
(def conj- {:name "conj"
|
||||||
::data/type ::data/clj
|
::data/type ::data/clj
|
||||||
:body conj})
|
:body conj})
|
||||||
|
|
||||||
(def assoc- {:name "assoc"
|
(def assoc- {:name "assoc"
|
||||||
::data/type ::data/clj
|
::data/type ::data/clj
|
||||||
:body assoc})
|
:body assoc})
|
||||||
|
|
||||||
(def get- {:name "get"
|
(def get- {:name "get"
|
||||||
::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
|
||||||
|
@ -112,4 +117,5 @@
|
||||||
"assoc" assoc-
|
"assoc" assoc-
|
||||||
"conj" conj-
|
"conj" conj-
|
||||||
"get" get-
|
"get" get-
|
||||||
})
|
"draw" draw
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user