draw_pixels
Modify Aseprite files by drawing individual pixels with specific colors using hex codes, enabling precise pixel art creation and editing.
Instructions
Draw pixels on the canvas with specified colors.
Args: filename: Name of the Aseprite file to modify pixels: List of pixel data, each containing: {"x": int, "y": int, "color": str} where color is a hex code like "#FF0000"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | ||
| pixels | Yes |
Implementation Reference
- aseprite_mcp/tools/drawing.py:12-64 (handler)The `draw_pixels` handler function, which validates inputs, builds a Lua script using `LuaBuilder`, and executes it on an Aseprite file.
@mcp.tool() async def draw_pixels(filename: str, pixels: List[Dict[str, Any]]) -> str: """Draw pixels on the canvas with specified colors. Args: filename: Name of the Aseprite file to modify pixels: List of pixel data, each containing: {"x": int, "y": int, "color": str} where color is a hex code like "#FF0000" """ try: # Validate inputs file_path = validate_file_path(filename, must_exist=True) if not pixels: raise ValidationError("pixels", pixels, "Pixel list cannot be empty") # Build Lua script builder = LuaBuilder() builder.add_line('local spr = app.activeSprite') builder.if_condition('not spr') builder.add_line('error("No active sprite")') builder.end_if() builder.add_line() builder.begin_transaction() builder.add_line('local cel = app.activeCel') builder.if_condition('not cel') builder.add_comment('If no active cel, create one') builder.add_line('app.activeLayer = spr.layers[1]') builder.add_line('app.activeFrame = spr.frames[1]') builder.add_line('cel = app.activeCel') builder.if_condition('not cel') builder.add_line('error("No active cel and couldn\'t create one")') builder.end_if() builder.end_if() builder.add_line() # Use the efficient batch pixel drawing builder.draw_pixels(pixels) builder.end_transaction() builder.save_sprite() # Execute script cmd = get_command() success, output = cmd.execute_lua_script(builder.build(), str(file_path)) return f"Pixels drawn successfully in {file_path}" except (ValidationError, AsepriteError) as e: return f"Failed to draw pixels: {e}" except Exception as e: return f"Unexpected error: {e}"