Compare commits
No commits in common. "a99c2a815265324b160ff226a6e63ad3abce3f7e" and "f94269caa0a443f64bed7ad9357d0b034150dc70" have entirely different histories.
a99c2a8152
...
f94269caa0
8 changed files with 52 additions and 46 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -3,7 +3,3 @@
|
||||||
.clj-kondo/
|
.clj-kondo/
|
||||||
.lsp/
|
.lsp/
|
||||||
tokens.clj
|
tokens.clj
|
||||||
*.love
|
|
||||||
/time-guesser
|
|
||||||
/dist
|
|
||||||
*.zip
|
|
||||||
|
|
|
||||||
1
.nvmrc
1
.nvmrc
|
|
@ -1 +0,0 @@
|
||||||
24
|
|
||||||
5
Makefile
5
Makefile
|
|
@ -1,5 +0,0 @@
|
||||||
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
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(local m (require "main.min.fnl"))
|
(local m (require "main.min.fnl"))
|
||||||
|
|
||||||
(set _G.setup m.s)
|
(set _G.setup m.setup)
|
||||||
(set _G.draw m.d)
|
(set _G.draw m.draw)
|
||||||
(set _G.keyPressed m.k)
|
(set _G.keyPressed m.key-pressed)
|
||||||
|
|
|
||||||
40
main.fnl
40
main.fnl
|
|
@ -4,22 +4,25 @@
|
||||||
(size 640 480)
|
(size 640 480)
|
||||||
(textSize 100))
|
(textSize 100))
|
||||||
|
|
||||||
(local steps 1440)
|
(local colors {
|
||||||
|
: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 (map num 0 steps 0 24))
|
(let [hour (floor (remap 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))))
|
||||||
|
|
||||||
|
|
@ -28,14 +31,21 @@
|
||||||
(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))
|
||||||
(background 0 0 0)
|
(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))
|
||||||
(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)))
|
||||||
|
|
||||||
{
|
{
|
||||||
:s setup
|
:setup setup
|
||||||
:d draw
|
:draw draw
|
||||||
:k key-pressed
|
:key-pressed key-pressed
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
main.lua
14
main.lua
|
|
@ -1,14 +1,20 @@
|
||||||
|
-- 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,
|
table.insert(package.loaders, function(filename)
|
||||||
function(filename)
|
|
||||||
if love.filesystem.getInfo(filename) then
|
if love.filesystem.getInfo(filename) then
|
||||||
return function(...)
|
return function(...)
|
||||||
return fennel.eval(love.filesystem.read(filename),
|
return fennel.eval(
|
||||||
|
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")
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
(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))]
|
||||||
|
|
@ -57,7 +58,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"
|
||||||
":s" ":d" ":k" ":format" ":L5" "map" "color" "lerpColor"})
|
":setup" ":draw" ":key-pressed" ":L5"})
|
||||||
|
|
||||||
(defn collect-bindings [tokens]
|
(defn collect-bindings [tokens]
|
||||||
(reduce (fn [acc token]
|
(reduce (fn [acc token]
|
||||||
|
|
@ -97,6 +98,7 @@
|
||||||
(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
|
||||||
|
|
@ -176,6 +178,7 @@
|
||||||
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))))
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"packageManager": "yarn@4.15.0"
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue