Last active
March 28, 2022 12:03
-
-
Save filipemeneses/4095dacb052486f99a256c86b63d5597 to your computer and use it in GitHub Desktop.
Convert Piskel frames to pixel-art pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.concat.apply([], Array(pskl.app.piskelController.getFrameCount())).map((_, index) => { | |
let palette = {} | |
let paletteIndex = 97 | |
let art = [] | |
pskl.utils.LayerUtils.mergeFrameAt(pskl.app.piskelController.getLayers(), index).forEachPixel((pixel, col, row) => { | |
if (!art[row]) art[row] = [] | |
if (!pixel) { | |
art[row][col] = ' ' | |
return | |
} | |
if (!palette[pixel]) { | |
palette[pixel] = { | |
id: String.fromCharCode(paletteIndex++), | |
color: pskl.utils.intToHex(pixel) | |
} | |
} | |
art[row][col] = palette[pixel].id | |
}) | |
palette = Object.keys(palette).reduce((obj, attr) => { | |
obj[palette[attr].id] = palette[attr].color | |
return obj | |
}, {}) | |
art = art.map(row => row.join('')) | |
return { art, palette } | |
}) |
Opening Piskel and running this code in the console
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI! How can this be used? I'm trying to export Piskel to JSON instead of C.