22 lines
936 B
Fennel
22 lines
936 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]
|
|
(love.graphics.clear 0 0 0 0)
|
|
(for [y 0 15]
|
|
(for [x 0 15]
|
|
(let [ibyte (+ (* y 16) x 1)
|
|
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])]
|
|
(when (= mask 0) (putpixel x y rgb)))))))))
|
|
|
|
{: tile-to-sprite : pal : gs-to-rgb}
|