Skip to content

Instantly share code, notes, and snippets.

@pancelor
Last active January 28, 2023 08:45
Embed
What would you like to do?
basic aseprite to picotron exporter

picotron is in early alpha -- it doesn't seem to have a sprite editor yet but it does support sprites in a particular format, so I threw together this quick-and-dirty aseprite exporter. hopefully this exporter will be obsolete soon!

requirements

you'll need Aseprite to use this.

this script is Windows-only, because of the io.popen('clip' ... str) -- "clip" is a windows executable. but you can replace that with print(str) and manually press ctrl-c on the popup window and it should work (don't close the popup afterwards or you'll need to re-open the script)

how to use

  1. save this script to your aseprite scripts folder (File > Scripts > Open Scripts Folder) then reopen aseprite (or rescan scripts)
  2. load an image with the picotron palette (or pico-8 extended palette)
  3. change the image's color mode to "indexed" (Sprite > Color Mode > Indexed)
  4. launch this script, press "copy" to copy to clipboard.
  • if there is a current selection, it will only copy that region
  • leave the script window open to copy again later
  1. see the picotron alpha release notes for info on how to use the string in your clipboard. it should looks something like [gfx]08080000000000000000000000000700707007777007717177700777777000607070[/gfx]

how does it work

it converts pixels into picotron's gfx format: "[gfx]", 2-char hex width, 2-char hex height, WxH chars of color data, "[\gfx]".

the color data is "extended hexadecimal", i.e. 0=>"0", ... 15=>"f", 16=>"g", ... 31=>"v"

pico8

you can use this for pico8 too; just copy and you can to paste directly into the pico8 sprite editor. note that it will likely only work with the first 16 colors

-- Pico[8|tron] Export
-- by pancelor
-- a simple script to export the entire sprite (or current selection)
-- in the pico8 format, e.g.
-- [gfx]08080000000000000000000000000700707007777007717177700777777000607070[/gfx]
function add(tab,elem)
table.insert(tab,elem)
return elem
end
-- 0=>"0", ... 15=>"f", 16=>"g", ... 31=>"v"
local function picohex(val)
if 0<=val and val<=9 then
return string.char(0x30+val)
elseif 10<=val and val<=31 then
return string.char(97+val-10)
else
assert(nil,"bad val for picohex: "..val)
end
end
-- copy string to host clipboard
-- windows-only
-- https://community.aseprite.org/t/solved-copy-string-within-aseprite-extension/16344
local function xsel(str)
io.popen('clip','w'):write(str):close()
-- print(str) --non-windows systems (requires manual ctrl-c)
end
--[[
# main
]]
local dlg = Dialog("Pico Export")
dlg:button{text="Copy", onclick=function()
local cel=app.activeCel
if not cel then return app.alert("error: no sprite found") end
if cel.image.colorMode~=ColorMode.INDEXED then return app.alert("sprite palette must be indexed") end
-- rect: the subrectangle to export tiles from
local rect=app.activeSprite.selection.isEmpty and app.activeSprite.bounds or app.activeSprite.selection.bounds
local build={}
--add(build,"b=userdata(\"")
add(build,string.format("[gfx]%02x%02x",rect.width,rect.height))
for dy=0,rect.height-1 do
for dx=0,rect.width-1 do
local col = cel.image:getPixel(rect.x+dx,rect.y+dy)
local ix = app.pixelColor.tileI(col)
add(build,picohex(ix))
end
end
add(build,"[/gfx]")
--add(build,"\")")
xsel(table.concat(build,""))
end}
-- dlg:label{ text="(then ctrl-c)" } --non-windows systems
dlg:show{wait=false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment