Compare commits

..

2 commits

Author SHA1 Message Date
a845fe1582 start coding one line canvas 2025-07-05 21:01:34 +02:00
5ae4550865 init one_line experiment 2025-07-05 21:00:59 +02:00
3 changed files with 6837 additions and 0 deletions

6767
one_line/fennel.lua Normal file

File diff suppressed because one or more lines are too long

59
one_line/main.fnl Normal file
View file

@ -0,0 +1,59 @@
(tset _G :img-width 88)
(tset _G :img-height 31)
(local scale 6)
(tset _G :canvas-width (* scale (. _G :img-width)))
(tset _G :canvas-height (* scale (. _G :img-height)))
(lambda set-center-origin []
(let [(w h f) (love.window.getMode)
x (/ w 2)
y (/ h 2)
]
; (print (.. "setting orgin to middle of window: " x "," y))
(love.graphics.push)
(love.graphics.translate x y)))
(fn love.load []
;; 480p 720×480
(love.window.setMode 720 480)
; (set-center-origin)
; (love.graphics.pop)
;; start a thread listening on stdin
(: (love.thread.newThread "require('love.event')
while 1 do love.event.push('stdin', io.read('*line')) end") :start))
(fn love.handlers.stdin [line]
; evaluate lines read from stdin as fennel code
(let [(ok val) (pcall fennel.eval line)]
(print (if ok (fennel.view val) val))))
(lambda draw-static-bg []
(let [
canvas-w (* scale 88)
canvas-h (* scale 31)
canvas-x (* -1 (/ canvas-w 2))
canvas-y (* -1 (/ canvas-h 2))
]
; canvas
(love.graphics.print "Canvas:" canvas-x (- canvas-y 20))
(love.graphics.rectangle "line" canvas-x canvas-y canvas-w canvas-h)
; preview
(love.graphics.print "Preview:" canvas-x (- canvas-y 80))
(love.graphics.rectangle "line" canvas-x (- canvas-y 60) 89 32)
)
)
(fn love.draw []
(set-center-origin)
(love.graphics.setBackgroundColor (love.math.colorFromBytes 192 192 192))
(love.graphics.setColor (love.math.colorFromBytes 29 29 29))
(draw-static-bg)
(love.graphics.pop))
(fn love.keypressed [key]
(love.event.quit))

11
one_line/main.lua Normal file
View file

@ -0,0 +1,11 @@
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}, ...), filename
end
end
end)
-- jump into Fennel
require("main.fnl")