draw_rectangle
Add rectangular shapes to pixel art projects by specifying coordinates and color, with options for outlines or filled areas to create sprites and animations.
Instructions
Draw a rectangle (outline or filled)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | Project identifier | |
| layerIndex | No | Layer index (default: 0) | |
| frameIndex | No | Frame index (default: 0) | |
| x0 | Yes | Top-left X coordinate | |
| y0 | Yes | Top-left Y coordinate | |
| x1 | Yes | Bottom-right X coordinate | |
| y1 | Yes | Bottom-right Y coordinate | |
| color | Yes | Color in hex format | |
| filled | No | Whether to fill the rectangle (default: false) | |
| penSize | No | Stroke width for outline (default: 1) |
Implementation Reference
- src/tools/drawing.ts:108-125 (handler)The actual logic for drawing the rectangle outline.
export function drawRectangle( frame: Frame, x0: number, y0: number, x1: number, y1: number, color: number | string, penSize: number = 1 ): number { const colorInt = typeof color === 'string' ? colorToInt(color) : color; const pixels = getRectangleStrokePixels(x0, y0, x1, y1, penSize); let count = 0; for (const [x, y] of pixels) { if (frame.containsPixel(x, y)) { frame.setPixel(x, y, colorInt); count++; } - src/server/PiskelServer.ts:1091-1105 (handler)The server-side handler that processes the MCP request and calls the drawing function.
private drawRectangleTool( projectId: string, layerIndex: number, frameIndex: number, x0: number, y0: number, x1: number, y1: number, color: string, filled: boolean, penSize: number ): object { const frame = this.getFrame(projectId, layerIndex, frameIndex); const count = filled ? drawFilledRectangle(frame, x0, y0, x1, y1, color) - src/server/PiskelServer.ts:358-365 (registration)The registration of the draw_rectangle tool in the server's tool list.
name: 'draw_rectangle', description: 'Draw a rectangle (outline or filled)', inputSchema: { type: 'object', properties: { projectId: { type: 'string', description: 'Project identifier',