CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pixi--graphics

2D graphics rendering library for drawing primitive shapes, paths, and complex vector graphics with fills, strokes, and advanced geometric operations

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

drawing-api.mddocs/

Core Drawing API

Primary Graphics class providing chainable methods for drawing shapes, paths, and applying styles. Supports real-time graphics creation with immediate and deferred rendering modes.

Capabilities

Graphics Class Constructor

Creates a new Graphics object with optional geometry parameter for sharing geometry between multiple graphics instances.

/**
 * Creates a new Graphics object
 * @param geometry - Optional GraphicsGeometry to share between multiple Graphics objects
 */
constructor(geometry?: GraphicsGeometry): Graphics;

Basic Shape Drawing

Core shape drawing methods for common geometric primitives. All methods return this for method chaining.

/**
 * Draws a rectangle
 * @param x - X position of the rectangle
 * @param y - Y position of the rectangle  
 * @param width - Width of the rectangle
 * @param height - Height of the rectangle
 */
drawRect(x: number, y: number, width: number, height: number): this;

/**
 * Draws a rounded rectangle
 * @param x - X position of the rectangle
 * @param y - Y position of the rectangle
 * @param width - Width of the rectangle
 * @param height - Height of the rectangle
 * @param radius - Corner radius
 */
drawRoundedRect(x: number, y: number, width: number, height: number, radius: number): this;

/**
 * Draws a circle
 * @param x - X center of the circle
 * @param y - Y center of the circle
 * @param radius - Radius of the circle
 */
drawCircle(x: number, y: number, radius: number): this;

/**
 * Draws an ellipse
 * @param x - X center of the ellipse
 * @param y - Y center of the ellipse
 * @param width - Width of the ellipse
 * @param height - Height of the ellipse
 */
drawEllipse(x: number, y: number, width: number, height: number): this;

Polygon and Complex Shape Drawing

Methods for drawing polygons and arbitrary shapes from point data or shape objects.

/**
 * Draws a polygon from a series of points
 * @param path - Array of numbers (x,y pairs) or Point objects, or Polygon object
 */
drawPolygon(...path: Array<number> | Array<IPointData>): this;
drawPolygon(path: Array<number> | Array<IPointData> | Polygon): this;

/**
 * Draws any IShape object (Circle, Ellipse, Polygon, Rectangle, RoundedRectangle)
 * @param shape - The shape object to draw
 */
drawShape(shape: IShape): this;

Path Drawing Methods

Low-level path drawing methods for creating custom shapes and complex paths.

/**
 * Moves the drawing position without drawing a line
 * @param x - X coordinate to move to
 * @param y - Y coordinate to move to
 */
moveTo(x: number, y: number): this;

/**
 * Draws a line from current position to specified coordinates
 * @param x - X coordinate to draw line to
 * @param y - Y coordinate to draw line to
 */
lineTo(x: number, y: number): this;

/**
 * Closes the current path by drawing a line back to the starting point
 */
closePath(): this;

Fill Control Methods

Methods for controlling fill behavior and appearance of drawn shapes.

/**
 * Begins a solid color fill
 * @param color - Hex color value (default: 0x000000)
 * @param alpha - Alpha transparency (default: 1)
 */
beginFill(color?: number, alpha?: number): this;

/**
 * Begins a texture fill with advanced options
 * @param options - Fill style options including texture, color, alpha, and matrix
 */
beginTextureFill(options?: IFillStyleOptions): this;

/**
 * Applies the current fill to all shapes drawn since beginFill/beginTextureFill
 */
endFill(): this;

Hole Drawing

Methods for creating holes within filled shapes (complex path operations).

/**
 * Begin adding holes to the last drawn shape
 */
beginHole(): this;

/**
 * End adding holes to the last drawn shape
 */
endHole(): this;

Transform and Matrix Operations

Methods for applying transformations to drawing operations.

/**
 * Applies a transformation matrix to subsequent drawing operations
 * @param matrix - Transformation matrix to apply
 */
setMatrix(matrix: Matrix): this;

Graphics Management

Methods for managing graphics state and lifecycle.

/**
 * Clears all graphics and resets fill/line styles to defaults
 */
clear(): this;

/**
 * Creates a clone of the Graphics object with the same geometry (not transforms)
 */
clone(): Graphics;

/**
 * Destroys the Graphics object and cleans up resources
 * @param options - Destroy options or boolean for children destruction
 */
destroy(options?: IDestroyOptions | boolean): void;

Utility and Query Methods

Methods for querying graphics properties and optimization.

/**
 * Tests if a point is inside the graphics object
 * @param point - Point to test for containment
 */
containsPoint(point: IPointData): boolean;

/**
 * Checks if graphics consists of a single rectangle for rendering optimization
 */
isFastRect(): boolean;

Static Properties

Static properties for controlling global graphics behavior.

/**
 * New rendering behavior for rounded rectangles: circular arcs instead of quadratic bezier curves.
 * In the next major release, this will be enabled by default.
 */
static nextRoundedRectBehavior: boolean;

Properties

Key properties for controlling graphics appearance and behavior.

/**
 * Renderer plugin name for batching (default: 'batch')
 */
pluginName: string;

/**
 * Blend mode applied to graphic shapes
 */
blendMode: BLEND_MODES;

/**
 * Hex tint value applied to each graphic shape (default: 0xFFFFFF)
 */
tint: number;

/**
 * Vertex and fragment shaders for GPU processing
 */
shader: Shader;

/**
 * Graphics geometry containing vertex positions, indices, colors, and UVs (readonly)
 */
readonly geometry: GraphicsGeometry;

/**
 * Current path being drawn (readonly)
 */
readonly currentPath: Polygon;

/**
 * Current fill style configuration (readonly)
 */
readonly fill: FillStyle;

/**
 * Current line style configuration (readonly)
 */
readonly line: LineStyle;

Usage Examples

Basic Shape Drawing:

import { Graphics } from "@pixi/graphics";

const graphics = new Graphics();

// Draw multiple shapes with method chaining
graphics
  .beginFill(0xff0000, 0.8)
  .drawRect(0, 0, 100, 100)
  .drawCircle(150, 50, 30)
  .endFill()
  .beginFill(0x00ff00)
  .drawPolygon([200, 0, 250, 50, 200, 100, 150, 50])
  .endFill();

Complex Path Drawing:

const graphics = new Graphics();

graphics
  .lineStyle(2, 0x0000ff)
  .moveTo(50, 50)
  .lineTo(150, 50)
  .lineTo(150, 150)
  .lineTo(50, 150)
  .closePath()
  .beginFill(0xffff00, 0.5)
  .moveTo(75, 75)
  .lineTo(125, 75)
  .lineTo(125, 125)
  .lineTo(75, 125)
  .closePath()
  .endFill();

Shape with Holes:

const graphics = new Graphics();

// Draw outer shape
graphics
  .beginFill(0xff0000)
  .drawRect(0, 0, 200, 200)
  // Add holes
  .beginHole()
  .drawCircle(50, 50, 20)
  .drawCircle(150, 50, 20)
  .drawRect(75, 100, 50, 50)
  .endHole()
  .endFill();

Install with Tessl CLI

npx tessl i tessl/npm-pixi--graphics

docs

curves.md

drawing-api.md

geometry.md

index.md

styling.md

utilities.md

tile.json