fennel_love2d_experiments/one_line/main.fnl

59 lines
1.5 KiB
Fennel
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(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))