Skip to main content
Glama

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
NameRequiredDescriptionDefault
projectIdYesProject identifier
layerIndexNoLayer index (default: 0)
frameIndexNoFrame index (default: 0)
x0YesStart X coordinate
y0YesStart Y coordinate
x1YesEnd X coordinate
y1YesEnd Y coordinate
colorYesColor in hex format
penSizeNoPen size (default: 1)

Implementation Reference

  • 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;
    }
  • 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
  • Tool registration switch case in PiskelServer for 'draw_line'.
    case 'draw_line':
      return this.drawLineTool(
        args.projectId as string,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yafeiaa/piskel-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server