Okay I did it
-- Generates a 47 tile blob tileset from the following five images in a row:
-- * All 8 neighbors
-- * Only neighors on left center and right center
-- * Only neighbors on top center and bottom center
-- * Only neighbors on all centers
-- * No neighbors
local function getSubtile(s, x, y, w, h)
local subtile = Image(w / 2, h / 2, s.spec.colorMode)
local source_image = Image(s)
for i=x*w/2, (x+1)*w/2 do
for j=y*h/2, (y+1)*h/2 do
subtile:drawPixel(i - x*w/2, j - y*h/2, source_image:getPixel(i, j))
end
end
return subtile
end
local spr = app.sprite
if not spr then return app.alert('No active sprite!') end
local tile_width = spr.width / 5
local tile_height = spr.height
local subtiles = {}
subtiles['top_left_full'] = getSubtile(spr, 0, 0, tile_width, tile_height)
subtiles['top_right_full'] = getSubtile(spr, 1, 0, tile_width, tile_height)
subtiles['bottom_left_full'] = getSubtile(spr, 0, 1, tile_width, tile_height)
subtiles['bottom_right_full'] = getSubtile(spr, 1, 1, tile_width, tile_height)
subtiles['top_left_horizontal'] = getSubtile(spr, 2, 0, tile_width, tile_height)
subtiles['top_right_horizontal'] = getSubtile(spr, 3, 0, tile_width, tile_height)
subtiles['bottom_left_horizontal'] = getSubtile(spr, 2, 1, tile_width, tile_height)
subtiles['bottom_right_horizontal'] = getSubtile(spr, 3, 1, tile_width, tile_height)
subtiles['top_left_vertical'] = getSubtile(spr, 4, 0, tile_width, tile_height)
subtiles['top_right_vertical'] = getSubtile(spr, 5, 0, tile_width, tile_height)
subtiles['bottom_left_vertical'] = getSubtile(spr, 4, 1, tile_width, tile_height)
subtiles['bottom_right_vertical'] = getSubtile(spr, 5, 1, tile_width, tile_height)
subtiles['top_left_inner'] = getSubtile(spr, 6, 0, tile_width, tile_height)
subtiles['top_right_inner'] = getSubtile(spr, 7, 0, tile_width, tile_height)
subtiles['bottom_left_inner'] = getSubtile(spr, 6, 1, tile_width, tile_height)
subtiles['bottom_right_inner'] = getSubtile(spr, 7, 1, tile_width, tile_height)
subtiles['top_left_corner'] = getSubtile(spr, 8, 0, tile_width, tile_height)
subtiles['top_right_corner'] = getSubtile(spr, 9, 0, tile_width, tile_height)
subtiles['bottom_left_corner'] = getSubtile(spr, 8, 1, tile_width, tile_height)
subtiles['bottom_right_corner'] = getSubtile(spr, 9, 1, tile_width, tile_height)
local result_spec = ImageSpec(spr.spec)
result_spec.width = tile_width * 12
result_spec.height = tile_height * 4
local result = Image(result_spec)
local layout = {
[0]={
[0]="ccvv",
"chvi",
"hhii",
"hciv",
"fiii",
"hhif",
"hhfi",
"ifii",
"chvf",
"iiff",
"hhff",
"hcfv",
},
{
[0]="vvvv",
"vivi",
"iiii",
"iviv",
"vivf",
"ifff",
"fiff",
"ivfv",
"vfvf",
"iffi",
"",
"fifi",
},
{
[0]="vvcc",
"vich",
"iihh",
"ivhc",
"vfvi",
"ffif",
"fffi",
"fviv",
"ifif",
"ffff",
"fiif",
"fvfv",
},
{
[0]="cccc",
"chch",
"hhhh",
"hchc",
"iifi",
"ifhh",
"fihh",
"iiif",
"vfch",
"ffhh",
"ffii",
"fvhc",
},
}
local sections = {"top_left_", "top_right_", "bottom_left_", "bottom_right_"}
for y,row in pairs(layout) do
for x,tile in pairs(row) do
for i=1,4 do
local p = Point(x * tile_width + (i-1) % 2 * tile_width / 2, y * tile_height + (i-1) // 2 * tile_height / 2)
if tile:sub(i, i) == "f" then
result:drawImage(subtiles[sections[i] .. "full"], p)
elseif tile:sub(i, i) == "h" then
result:drawImage(subtiles[sections[i] .. "horizontal"], p)
elseif tile:sub(i, i) == "v" then
result:drawImage(subtiles[sections[i] .. "vertical"], p)
elseif tile:sub(i, i) == "i" then
result:drawImage(subtiles[sections[i] .. "inner"], p)
elseif tile:sub(i, i) == "c" then
result:drawImage(subtiles[sections[i] .. "corner"], p)
end
end
end
end
local new_sprite = Sprite(result_spec)
new_sprite:setPalette(spr.palettes[1])
new_sprite.cels[1].image = result
new_sprite.filename = "blob"
app.refresh()