Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert Piskel frames to pixel-art pattern
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 }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.