Skip to content

Instantly share code, notes, and snippets.

@filipemeneses
Last active March 28, 2022 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipemeneses/4095dacb052486f99a256c86b63d5597 to your computer and use it in GitHub Desktop.
Save filipemeneses/4095dacb052486f99a256c86b63d5597 to your computer and use it in GitHub Desktop.
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 }
})
@JMCPH
Copy link

JMCPH commented Mar 27, 2022

HI! How can this be used? I'm trying to export Piskel to JSON instead of C.

@filipemeneses
Copy link
Author

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