Last active
March 11, 2024 17:53
-
-
Save unclebob/fd813557f5b345bafa7d6f5583277036 to your computer and use it in GitHub Desktop.
newquil -- Script for creating a clojure/quil project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
echo "making quil project $1." | |
mkdir $1 | |
cd $1 | |
mkdir src | |
mkdir spec | |
cat >deps.edn << EOF | |
{:paths ["src" "resources"] | |
:deps {org.clojure/clojure {:mvn/version "1.11.1"} | |
quil/quil {:mvn/version "4.3.1563"} | |
speclj/speclj {:mvn/version "3.4.5"}} | |
:aliases {:spec {:main-opts ["-m" "speclj.main" "-c"] | |
:extra-deps {speclj/speclj {:mvn/version "3.4.5"}} | |
:extra-paths ["spec"]} | |
:$1 {:main-opts [-m $1]}}} | |
EOF | |
cat >src/$1.clj << EOF | |
(ns $1 | |
(:require [quil.core :as q] | |
[quil.middleware :as m])) | |
(defn setup [] | |
(q/frame-rate 30) | |
(q/color-mode :hsb) | |
{:color 0 | |
:angle 0 | |
:distance 150 | |
:size 100}) | |
(defn update-state [{:keys [color angle distance size]}] | |
{:color (mod (+ color 0.7) 255) | |
:angle (+ angle 0.1) | |
:distance (if (< distance -150) 150 (- distance 1)) | |
:size (if (< size -100) 100 (- size 1))}) | |
(defn draw-state [{:keys [color angle distance size]}] | |
(q/background 240) | |
(q/fill color 255 255) | |
(let [size (Math/abs size) | |
distance (Math/abs distance) | |
x (* distance (q/cos angle)) | |
y (* distance (q/sin angle))] | |
(q/with-translation [(/ (q/width) 2) | |
(/ (q/height) 2)] | |
(q/ellipse x y size size)))) | |
(q/defsketch $1 | |
:title "You spin my circle right round" | |
:size [500 500] | |
:setup setup | |
:update update-state | |
:draw draw-state | |
:features [:keep-on-top] | |
:middleware [m/fun-mode]) | |
(defn -main [& args] | |
(println "$1 has begun.")) | |
EOF | |
cat >spec/$1_spec.clj << EOF | |
(ns $1-spec | |
(:require [speclj.core :refer :all] | |
[$1 :refer :all])) | |
(describe "$1" | |
(it "needs writing" | |
(should false))) | |
EOF | |
echo "Done. " | |
echo "Start tests with clj -M:spec <opts>" | |
echo "Start app with clj -M:$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment