From 580218dac497ffb94a8b17f0154364911a97d1b0 Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Wed, 27 May 2026 17:59:58 +0100 Subject: [PATCH 1/6] use l5 map fn instead of custom re-map --- main.fnl | 13 ++++--------- minify.bb | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/main.fnl b/main.fnl index 7e72df3..966adb1 100644 --- a/main.fnl +++ b/main.fnl @@ -9,20 +9,18 @@ :dark [64 56 48] ; #403830 }) -(lambda remap [v in-min in-max out-min out-max] - (+ out-min (* (/ (- v in-min) (- in-max in-min)) (- out-max out-min)))) - (local steps (* 24 60)) (var step 0) (lambda lpad [num] (if (< num 10) (.. "0" num) num)) (lambda time [num] - (let [hour (floor (remap num 0 steps 0 24)) + (let [hour (floor (map num 0 steps 0 24)) min (- num (* hour 60))] (.. (lpad hour) ":" (lpad min)))) (var pause false) (var won false) + (fn key-pressed [] (when (= key "space") (set pause (not pause)))) @@ -34,11 +32,8 @@ (let [ half (/ steps 2) color-step (if (> step half) (- half (- step half)) step) - color-fn #(+ (. colors.dark $1) (* (/ (- (. colors.yellow $1) (. colors.dark $1)) half) color-step)) - r (color-fn 1) - g (color-fn 2) - b (color-fn 3)] - (background r g b)) + color-fn #(+ (. colors.dark $1) (* (/ (- (. colors.yellow $1) (. colors.dark $1)) half) color-step))] + (background (color-fn 1) (color-fn 2) (color-fn 3))) (text (time step) 175 150) (text (time goal-time) 175 250) (when (and pause (= goal-time step)) (set won true)) diff --git a/minify.bb b/minify.bb index c382e23..35ad7a8 100755 --- a/minify.bb +++ b/minify.bb @@ -58,7 +58,7 @@ (def built-ins #{"fn" "local" "λ" "lambda" "require" "let" "+" "-" "/" "*" "<" ">" "<=" ">=" "not=" ".." "var" "if" "when" "and" "or" "not" "do" "set" "each" "for" "while" "true" "$1" "math.floor" "floor" "false" "nil" "size" "textSize" "background" "text" "random" "key" - ":setup" ":draw" ":key-pressed" ":L5"}) + ":setup" ":draw" ":key-pressed" ":L5" "map"}) (defn collect-bindings [tokens] (reduce (fn [acc token] From b4f9aaa39f7778537b8e71ad812dab13e843aa8d Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Wed, 27 May 2026 18:10:27 +0100 Subject: [PATCH 2/6] use l5 colorLerp and color fns --- main.fnl | 11 ++++------- minify.bb | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/main.fnl b/main.fnl index 966adb1..ecafdb5 100644 --- a/main.fnl +++ b/main.fnl @@ -4,11 +4,8 @@ (size 640 480) (textSize 100)) -(local colors { - :yellow [255 228 112] ; #ffe470 - :dark [64 56 48] ; #403830 -}) - +(local yellow (color 255 228 112)) ; #ffe470 +(local dark (color 64 56 48)) ; #403830 (local steps (* 24 60)) (var step 0) @@ -32,8 +29,8 @@ (let [ half (/ steps 2) color-step (if (> step half) (- half (- step half)) step) - color-fn #(+ (. colors.dark $1) (* (/ (- (. colors.yellow $1) (. colors.dark $1)) half) color-step))] - (background (color-fn 1) (color-fn 2) (color-fn 3))) + current-color (lerpColor dark yellow (map color-step 0 half 0 1))] + (background current-color)) (text (time step) 175 150) (text (time goal-time) 175 250) (when (and pause (= goal-time step)) (set won true)) diff --git a/minify.bb b/minify.bb index 35ad7a8..842bff9 100755 --- a/minify.bb +++ b/minify.bb @@ -58,7 +58,7 @@ (def built-ins #{"fn" "local" "λ" "lambda" "require" "let" "+" "-" "/" "*" "<" ">" "<=" ">=" "not=" ".." "var" "if" "when" "and" "or" "not" "do" "set" "each" "for" "while" "true" "$1" "math.floor" "floor" "false" "nil" "size" "textSize" "background" "text" "random" "key" - ":setup" ":draw" ":key-pressed" ":L5" "map"}) + ":setup" ":draw" ":key-pressed" ":L5" "map" "color" "lerpColor"}) (defn collect-bindings [tokens] (reduce (fn [acc token] From ac70953ae9acd3589f62efbab3c46f2f7830228e Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Wed, 27 May 2026 19:24:13 +0100 Subject: [PATCH 3/6] fix l5 env issues --- main.fnl | 9 ++++++--- main.lua | 26 ++++++++++---------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/main.fnl b/main.fnl index ecafdb5..397192b 100644 --- a/main.fnl +++ b/main.fnl @@ -1,11 +1,14 @@ (require :L5) +(var yellow nil) ; #ffe470 +(var dark nil) ; #403830 + (fn setup [] (size 640 480) - (textSize 100)) + (textSize 100) + (set yellow (color 255 228 112)) + (set dark (color 64 56 48))) -(local yellow (color 255 228 112)) ; #ffe470 -(local dark (color 64 56 48)) ; #403830 (local steps (* 24 60)) (var step 0) diff --git a/main.lua b/main.lua index dc30c68..594a408 100644 --- a/main.lua +++ b/main.lua @@ -1,20 +1,14 @@ --- Mostly from https://sr.ht/~benthor/absolutely-minimal-love2d-fennel/ --- But added the allowedGlobals=false option - fennel = require("fennel") debug.traceback = fennel.traceback -table.insert(package.loaders, function(filename) - if love.filesystem.getInfo(filename) then - return function(...) - return fennel.eval( - love.filesystem.read(filename), - { env = _G, filename = filename, allowedGlobals = false }, - ... - ), - filename - end - end -end) - +table.insert(package.loaders, + function(filename) + if love.filesystem.getInfo(filename) then + return function(...) + return fennel.eval(love.filesystem.read(filename), + { env = _G, filename = filename, allowedGlobals = false }, + ...), filename + end + end + end) -- jump into Fennel require("bootstrap.fnl") From 66c5827ed70c715d188a9ece8f807a6e17661297 Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Wed, 27 May 2026 19:38:16 +0100 Subject: [PATCH 4/6] reduce chars --- bootstrap.fnl | 6 +++--- main.fnl | 8 ++++---- minify.bb | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bootstrap.fnl b/bootstrap.fnl index e775c02..fbd0661 100644 --- a/bootstrap.fnl +++ b/bootstrap.fnl @@ -1,5 +1,5 @@ (local m (require "main.min.fnl")) -(set _G.setup m.setup) -(set _G.draw m.draw) -(set _G.keyPressed m.key-pressed) +(set _G.setup m.s) +(set _G.draw m.d) +(set _G.keyPressed m.k) diff --git a/main.fnl b/main.fnl index 397192b..fdd353a 100644 --- a/main.fnl +++ b/main.fnl @@ -9,7 +9,7 @@ (set yellow (color 255 228 112)) (set dark (color 64 56 48))) -(local steps (* 24 60)) +(local steps (* 24 60)) (var step 0) (lambda lpad [num] (if (< num 10) (.. "0" num) num)) @@ -40,7 +40,7 @@ (when won (text "YOU WIN" 100 400))) { - :setup setup - :draw draw - :key-pressed key-pressed + :s setup + :d draw + :k key-pressed } diff --git a/minify.bb b/minify.bb index 842bff9..0091c1c 100755 --- a/minify.bb +++ b/minify.bb @@ -58,7 +58,7 @@ (def built-ins #{"fn" "local" "λ" "lambda" "require" "let" "+" "-" "/" "*" "<" ">" "<=" ">=" "not=" ".." "var" "if" "when" "and" "or" "not" "do" "set" "each" "for" "while" "true" "$1" "math.floor" "floor" "false" "nil" "size" "textSize" "background" "text" "random" "key" - ":setup" ":draw" ":key-pressed" ":L5" "map" "color" "lerpColor"}) + ":s" ":d" ":k" ":L5" "map" "color" "lerpColor"}) (defn collect-bindings [tokens] (reduce (fn [acc token] From c652c212134bee64fa816117297704b6668bcf7f Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Wed, 27 May 2026 20:08:19 +0100 Subject: [PATCH 5/6] init build --- .gitignore | 1 + Makefile | 2 ++ main.fnl | 37 ++++++++++++++++--------------------- minify.bb | 2 +- 4 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 3b1ad01..756d83e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .clj-kondo/ .lsp/ tokens.clj +*.love diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ced9260 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +build: + zip time-guesser.love main.lua main.min.fnl bootstrap.fnl fennel.lua L5.lua diff --git a/main.fnl b/main.fnl index fdd353a..44b52ee 100644 --- a/main.fnl +++ b/main.fnl @@ -1,22 +1,21 @@ (require :L5) -(var yellow nil) ; #ffe470 -(var dark nil) ; #403830 - (fn setup [] (size 640 480) - (textSize 100) - (set yellow (color 255 228 112)) - (set dark (color 64 56 48))) + (textSize 100)) -(local steps (* 24 60)) +(local steps 1440) (var step 0) -(lambda lpad [num] (if (< num 10) (.. "0" num) num)) -(lambda time [num] - (let [hour (floor (map num 0 steps 0 24)) - min (- num (* hour 60))] - (.. (lpad hour) ":" (lpad min)))) +; (lambda lpad [num] (if (< num 10) (.. "0" num) num)) +; (lambda time [num] +; (let [hour (floor (map num 0 steps 0 24)) +; min (- num (* hour 60))] +; (.. (lpad hour) ":" (lpad min)))) + +(fn time [num] + (let [hour (floor (map num 0 steps 0 24))] + (: "%02d:%02d" :format hour (- num (* hour 60))))) (var pause false) (var won false) @@ -29,15 +28,11 @@ (fn draw [] (when (and (not won) (not pause)) (set step (+ step 1))) (when (>= step steps) (set step 0)) - (let [ - half (/ steps 2) - color-step (if (> step half) (- half (- step half)) step) - current-color (lerpColor dark yellow (map color-step 0 half 0 1))] - (background current-color)) - (text (time step) 175 150) - (text (time goal-time) 175 250) - (when (and pause (= goal-time step)) (set won true)) - (when won (text "YOU WIN" 100 400))) + (background 0 0 0) + (text (time step) 175 150) + (text (time goal-time) 175 250) + (when (and pause (= goal-time step)) (set won true)) + (when won (text "YOU WIN" 100 400))) { :s setup diff --git a/minify.bb b/minify.bb index 0091c1c..069b36d 100755 --- a/minify.bb +++ b/minify.bb @@ -58,7 +58,7 @@ (def built-ins #{"fn" "local" "λ" "lambda" "require" "let" "+" "-" "/" "*" "<" ">" "<=" ">=" "not=" ".." "var" "if" "when" "and" "or" "not" "do" "set" "each" "for" "while" "true" "$1" "math.floor" "floor" "false" "nil" "size" "textSize" "background" "text" "random" "key" - ":s" ":d" ":k" ":L5" "map" "color" "lerpColor"}) + ":s" ":d" ":k" ":format" ":L5" "map" "color" "lerpColor"}) (defn collect-bindings [tokens] (reduce (fn [acc token] From a99c2a815265324b160ff226a6e63ad3abce3f7e Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Wed, 27 May 2026 21:38:25 +0100 Subject: [PATCH 6/6] finalize build --- .gitignore | 3 +++ .nvmrc | 1 + Makefile | 3 +++ minify.bb | 3 --- package.json | 3 +++ 5 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .nvmrc create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 756d83e..7d42c20 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ .lsp/ tokens.clj *.love +/time-guesser +/dist +*.zip diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..a45fd52 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +24 diff --git a/Makefile b/Makefile index ced9260..e901892 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ build: + ./minify.bb main.fnl zip time-guesser.love main.lua main.min.fnl bootstrap.fnl fennel.lua L5.lua + bash -c 'source ~/.nvm/nvm.sh && nvm use && yarn dlx love.js time-guesser.love dist -c' + zip -r time-guesser-web.zip dist diff --git a/minify.bb b/minify.bb index 069b36d..b24c1fe 100755 --- a/minify.bb +++ b/minify.bb @@ -12,7 +12,6 @@ (defn tokenize [source] (let [chars (vec source) total-chars (count chars)] (loop [cursor 0 tokens []] - ; (when (< cursor 100) (pprint {:tokens tokens})) (if (>= cursor total-chars) tokens (let [c (chars cursor) nxt (get chars (inc cursor))] @@ -98,7 +97,6 @@ (defn needs-space? "does this token need space before it?" [prev current nxt] - (when (= (current :type) :string) (pprint {:current current})) (or (= (current :type) :open-annon-fn) (and @@ -178,7 +176,6 @@ re-map (build-rename-map (collect-bindings tokens)) output (emit tokens re-map) output-file-name (gen-output-file-name file-name)] - (pprint {:output output :token-sample (take 15 tokens) :bindings (build-rename-map (collect-bindings tokens))}) (write-file "tokens.clj" (with-out-str (pprint (transform-tokens tokens re-map)))) (write-file output-file-name output) (println (str "Wrote file " output-file-name)))) diff --git a/package.json b/package.json new file mode 100644 index 0000000..4a2cee2 --- /dev/null +++ b/package.json @@ -0,0 +1,3 @@ +{ + "packageManager": "yarn@4.15.0" +}