Compare commits

...

6 commits

Author SHA1 Message Date
a99c2a8152
finalize build 2026-05-27 22:07:27 +01:00
c652c21213
init build 2026-05-27 21:37:22 +01:00
66c5827ed7
reduce chars 2026-05-27 20:06:51 +01:00
ac70953ae9
fix l5 env issues 2026-05-27 19:36:38 +01:00
b4f9aaa39f
use l5 colorLerp and color fns 2026-05-27 19:23:25 +01:00
580218dac4
use l5 map fn instead of custom re-map 2026-05-27 18:06:54 +01:00
8 changed files with 46 additions and 52 deletions

4
.gitignore vendored
View file

@ -3,3 +3,7 @@
.clj-kondo/ .clj-kondo/
.lsp/ .lsp/
tokens.clj tokens.clj
*.love
/time-guesser
/dist
*.zip

1
.nvmrc Normal file
View file

@ -0,0 +1 @@
24

5
Makefile Normal file
View file

@ -0,0 +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

View file

@ -1,5 +1,5 @@
(local m (require "main.min.fnl")) (local m (require "main.min.fnl"))
(set _G.setup m.setup) (set _G.setup m.s)
(set _G.draw m.draw) (set _G.draw m.d)
(set _G.keyPressed m.key-pressed) (set _G.keyPressed m.k)

View file

@ -4,25 +4,22 @@
(size 640 480) (size 640 480)
(textSize 100)) (textSize 100))
(local colors { (local steps 1440)
:yellow [255 228 112] ; #ffe470
: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) (var step 0)
(lambda lpad [num] (if (< num 10) (.. "0" num) num)) ; (lambda lpad [num] (if (< num 10) (.. "0" num) num))
(lambda time [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))] ; min (- num (* hour 60))]
(.. (lpad hour) ":" (lpad min)))) ; (.. (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 pause false)
(var won false) (var won false)
(fn key-pressed [] (fn key-pressed []
(when (= key "space") (set pause (not pause)))) (when (= key "space") (set pause (not pause))))
@ -31,21 +28,14 @@
(fn draw [] (fn draw []
(when (and (not won) (not pause)) (set step (+ step 1))) (when (and (not won) (not pause)) (set step (+ step 1)))
(when (>= step steps) (set step 0)) (when (>= step steps) (set step 0))
(let [ (background 0 0 0)
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))
(text (time step) 175 150) (text (time step) 175 150)
(text (time goal-time) 175 250) (text (time goal-time) 175 250)
(when (and pause (= goal-time step)) (set won true)) (when (and pause (= goal-time step)) (set won true))
(when won (text "YOU WIN" 100 400))) (when won (text "YOU WIN" 100 400)))
{ {
:setup setup :s setup
:draw draw :d draw
:key-pressed key-pressed :k key-pressed
} }

View file

@ -1,20 +1,14 @@
-- Mostly from https://sr.ht/~benthor/absolutely-minimal-love2d-fennel/
-- But added the allowedGlobals=false option
fennel = require("fennel") fennel = require("fennel")
debug.traceback = fennel.traceback debug.traceback = fennel.traceback
table.insert(package.loaders, function(filename) table.insert(package.loaders,
function(filename)
if love.filesystem.getInfo(filename) then if love.filesystem.getInfo(filename) then
return function(...) return function(...)
return fennel.eval( return fennel.eval(love.filesystem.read(filename),
love.filesystem.read(filename),
{ env = _G, filename = filename, allowedGlobals = false }, { env = _G, filename = filename, allowedGlobals = false },
... ...), filename
),
filename
end end
end end
end) end)
-- jump into Fennel -- jump into Fennel
require("bootstrap.fnl") require("bootstrap.fnl")

View file

@ -12,7 +12,6 @@
(defn tokenize [source] (defn tokenize [source]
(let [chars (vec source) total-chars (count chars)] (let [chars (vec source) total-chars (count chars)]
(loop [cursor 0 tokens []] (loop [cursor 0 tokens []]
; (when (< cursor 100) (pprint {:tokens tokens}))
(if (>= cursor total-chars) (if (>= cursor total-chars)
tokens tokens
(let [c (chars cursor) nxt (get chars (inc cursor))] (let [c (chars cursor) nxt (get chars (inc cursor))]
@ -58,7 +57,7 @@
(def built-ins #{"fn" "local" "λ" "lambda" "require" "let" "+" "-" "/" "*" "<" ">" "<=" ">=" "not=" ".." (def built-ins #{"fn" "local" "λ" "lambda" "require" "let" "+" "-" "/" "*" "<" ">" "<=" ">=" "not=" ".."
"var" "if" "when" "and" "or" "not" "do" "set" "each" "for" "while" "var" "if" "when" "and" "or" "not" "do" "set" "each" "for" "while"
"true" "$1" "math.floor" "floor" "false" "nil" "size" "textSize" "background" "text" "random" "key" "true" "$1" "math.floor" "floor" "false" "nil" "size" "textSize" "background" "text" "random" "key"
":setup" ":draw" ":key-pressed" ":L5"}) ":s" ":d" ":k" ":format" ":L5" "map" "color" "lerpColor"})
(defn collect-bindings [tokens] (defn collect-bindings [tokens]
(reduce (fn [acc token] (reduce (fn [acc token]
@ -98,7 +97,6 @@
(defn needs-space? (defn needs-space?
"does this token need space before it?" "does this token need space before it?"
[prev current nxt] [prev current nxt]
(when (= (current :type) :string) (pprint {:current current}))
(or (or
(= (current :type) :open-annon-fn) (= (current :type) :open-annon-fn)
(and (and
@ -178,7 +176,6 @@
re-map (build-rename-map (collect-bindings tokens)) re-map (build-rename-map (collect-bindings tokens))
output (emit tokens re-map) output (emit tokens re-map)
output-file-name (gen-output-file-name file-name)] 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 "tokens.clj" (with-out-str (pprint (transform-tokens tokens re-map))))
(write-file output-file-name output) (write-file output-file-name output)
(println (str "Wrote file " output-file-name)))) (println (str "Wrote file " output-file-name))))

3
package.json Normal file
View file

@ -0,0 +1,3 @@
{
"packageManager": "yarn@4.15.0"
}