honeylisp/editor/tiledraw/iigs.fnl

22 lines
955 B
Fennel

(local {: putpixel : make-canvas} (require :editor.tiledraw))
; converted from http://pixeljoint.com/forum/forum_posts.asp?TID=12795 (db16)
; maybe check out https://lospec.com/palette-list ?
(local pal [[1 0 1] [4 2 3] [3 3 6] [4 4 4] [8 4 3] [3 6 2] [13 4 4] [7 7 6]
[5 7 12] [13 7 2] [8 9 10] [6 10 2] [13 10 9] [6 12 12] [13 13 5] [13 14 13]])
(fn gs-to-rgb [color] (icollect [_ v (ipairs color)] (* v 0x11)))
(fn tile-to-sprite [tile]
(if tile (make-canvas 16 16 (fn [canvas]
(for [y 0 15]
(for [x 0 15 2]
(let [ibyte (+ (* y 8) (math.floor (/ x 2)) 1)
byte (string.byte (tile:sub ibyte ibyte))
_ (print x y ibyte byte)
left (bit.band (bit.rshift byte 4) 0xf)
right (bit.band byte 0xf)]
(putpixel x y (gs-to-rgb (. pal (+ left 1))))
(putpixel (+ x 1) y (gs-to-rgb (. pal (+ right 1)))))))))))
{: tile-to-sprite : pal : gs-to-rgb}