-- My First Aseprite Script-- Creates a sprite and draws a red square-- Create a new 32x32 pixel spritelocal sprite = Sprite(32, 32)print("Created sprite: " .. sprite.width .. "x" .. sprite.height)-- Define red colorlocal red = Color{ r=255, g=0, b=0 }-- Draw a filled rectangleapp.useTool{ tool = 'filled_rectangle', color = red, brush = Brush(1), points = { Point(8, 8), Point(24, 24) }}print("Drew a red square!")
Instead of creating a new sprite, you can work with the currently open sprite:
-- Get the active spritelocal sprite = app.activeSpriteif not sprite then print("No sprite is open!") returnendprint("Working with: " .. sprite.filename)print("Size: " .. sprite.width .. "x" .. sprite.height)
local sprite = Sprite(32, 32)-- Create a new layerlocal newLayer = sprite:newLayer()newLayer.name = "My Layer"-- Set as active layerapp.activeLayer = newLayer-- Draw on the new layerapp.useTool{ tool = 'pencil', color = Color(255, 0, 0), points = { Point(10, 10) }}-- Access layers by indexlocal firstLayer = sprite.layers[1]print("First layer: " .. firstLayer.name)
local dialog = Dialog("My First Dialog")dialog:entry{ id = "name", label = "Sprite Name:", text = "MySprite"}dialog:slider{ id = "size", label = "Size:", min = 16, max = 256, value = 32}dialog:button{ id = "ok", text = "Create", onclick = function() local data = dialog.data local sprite = Sprite(data.size, data.size) sprite.filename = data.name .. ".aseprite" print("Created: " .. sprite.filename) dialog:close() end}dialog:button{ id = "cancel", text = "Cancel"}dialog:show()
You can run scripts without opening the Aseprite UI:
# Run a script in batch modeaseprite -b -script my-first-script.lua# Run a script on a specific fileaseprite -b input.aseprite -script process.lua -save-as output.png