-- Uniform export of one generated four-key direction. Keep complete anatomy. local src=app.open(app.params.source) local pixels=Image(src.cels[1].image) local boxes=dofile(app.params.boxes) for p in pixels:pixels() do local c=p() if app.pixelColor.rgbaA(c)<192 then p(0) else p(app.pixelColor.rgba(app.pixelColor.rgbaR(c),app.pixelColor.rgbaG(c),app.pixelColor.rgbaB(c),255)) end end src:close() local maxw,maxh=0,0 for _,b in ipairs(boxes) do maxw,maxh=math.max(maxw,b.w),math.max(maxh,b.h) end local scale=math.min(42/maxw,tonumber(app.params.height)/maxh) local frames={} for i,b in ipairs(boxes) do local tmp=Sprite(b.w,b.h,ColorMode.RGB) tmp.cels[1].image:drawImage(pixels,Point(-b.x,-b.y)) local w,h=math.floor(b.w*scale+.5),math.floor(b.h*scale+.5) app.command.SpriteSize{ui=false,width=w,height=h,method='nearest-neighbor'} local frame=Image(48,64,ColorMode.RGB) local dx=math.floor(24-(b.head_x or b.w/2)*scale+.5) dx=math.max(0,math.min(48-w,dx)) local flight=(app.params.gait=='run' and i%2==0) and 2 or 0 frame:drawImage(tmp.cels[1].image,Point(dx,61-h-flight)) frames[i]=frame tmp:close() end local out=Sprite(192,64,ColorMode.RGB) for i,f in ipairs(frames) do out.cels[1].image:drawImage(f,Point((i-1)*48,0)) end out:saveAs(app.params.output);out:close()