start coding one line canvas
This commit is contained in:
parent
5ae4550865
commit
a845fe1582
1 changed files with 59 additions and 0 deletions
59
one_line/main.fnl
Normal file
59
one_line/main.fnl
Normal 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))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue