honeylisp/editor/tiledraw/iigs.fnl

22 lines
936 B
Plaintext
Raw Normal View History

2021-08-29 02:04:54 +00:00
(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]
2021-09-14 03:16:03 +00:00
(love.graphics.clear 0 0 0 0)
2021-08-29 02:04:54 +00:00
(for [y 0 15]
(for [x 0 15]
(let [ibyte (+ (* y 16) x 1)
2021-08-29 02:04:54 +00:00
byte (string.byte (tile:sub ibyte ibyte))
mask (bit.band (bit.rshift byte 4) 0xf)
color (bit.band byte 0xf)
rgb (if (= mask 0) (gs-to-rgb (. pal (+ color 1))) [255 0 255])]
2021-09-14 03:16:03 +00:00
(when (= mask 0) (putpixel x y rgb)))))))))
2021-08-29 02:04:54 +00:00
{: tile-to-sprite : pal : gs-to-rgb}