draw_line
Draw straight lines between two coordinates in pixel art projects to create shapes, outlines, or connect elements.
Instructions
Draw a line between two points
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 | Start X coordinate | |
| y0 | Yes | Start Y coordinate | |
| x1 | Yes | End X coordinate | |
| y1 | Yes | End Y coordinate | |
| color | Yes | Color in hex format | |
| penSize | No | Pen size (default: 1) |
Implementation Reference
- src/tools/drawing.ts:61-104 (handler)The implementation of the drawLine tool, which calculates pixel coordinates for a line and applies color to the frame.
export function drawLine( frame: Frame, x0: number, y0: number, x1: number, y1: number, color: number | string, penSize: number = 1, uniform: boolean = false ): number { const colorInt = typeof color === 'string' ? colorToInt(color) : color; const linePixels = uniform ? getUniformLinePixels(x0, x1, y0, y1) : getLinePixels(x0, x1, y0, y1); let count = 0; if (penSize === 1) { for (const pixel of linePixels) { if (frame.containsPixel(pixel.col, pixel.row)) { frame.setPixel(pixel.col, pixel.row, colorInt); count++; } } } else { // Draw with larger pen size const drawnSet = new Set<string>(); for (const pixel of linePixels) { const resized = resizePixel(pixel.col, pixel.row, penSize); for (const [px, py] of resized) { const key = `${px},${py}`; if (!drawnSet.has(key) && frame.containsPixel(px, py)) { drawnSet.add(key); frame.setPixel(px, py, colorInt); count++; } } } } return count; } - src/server/PiskelServer.ts:1075-1101 (handler)The handler method in PiskelServer that parses inputs and calls the drawing function.
private drawLineTool( projectId: string, layerIndex: number, frameIndex: number, x0: number, y0: number, x1: number, y1: number, color: string, penSize: number ): object { const frame = this.getFrame(projectId, layerIndex, frameIndex); const count = drawLine(frame, x0, y0, x1, y1, color, penSize); return { success: true, pixelsDrawn: count }; } private drawRectangleTool( projectId: string, layerIndex: number, frameIndex: number, x0: number, y0: number, x1: number, y1: number, color: string, filled: boolean, penSize: number - src/server/PiskelServer.ts:774-776 (registration)Tool registration switch case in PiskelServer for 'draw_line'.
case 'draw_line': return this.drawLineTool( args.projectId as string,