[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CSXNABXQMK8KXRW5RT1BDR":3,"skill-same:01M7CSXNABXQMK8KXRW5RT1BDR":52},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7CSXNABXQMK8KXRW5RT1BDR","pixijs-scene-graphics",null,"Use this skill when drawing vector shapes and paths in PixiJS v8. Covers the Graphics API: shape-then-fill methods (rect\u002Fcircle\u002Fellipse\u002Fpoly\u002FroundRect\u002Fstar\u002FregularPoly\u002FroundPoly\u002FroundShape\u002FfilletRect\u002FchamferRect), path methods (moveTo\u002FlineTo\u002FbezierCurveTo\u002FquadraticCurveTo\u002Farc\u002FarcTo\u002FarcToSvg\u002FclosePath), fill\u002Fstroke\u002Fcut, holes, FillGradient (linear\u002Fradial), FillPattern, GraphicsContext sharing, svg import\u002Fexport, containsPoint hit testing, cloning, clearing, bounds, fillStyle\u002FstrokeStyle, draw-time transforms (rotateTransform\u002FscaleTransform\u002FtranslateTransform\u002FsetTransform\u002Fsave\u002Frestore), default styles, GraphicsPath reuse. Triggers on: Graphics, GraphicsContext, rect, circle, poly, roundRect, fill, stroke, cut, hole, beginHole, FillGradient, FillPattern, moveTo, bezierCurveTo, svg, graphicsContextToSvg, svg export, GraphicsOptions, containsPoint, clone, clear, bounds, rotateTransform, translateTransform, setFillStyle, setStrokeStyle, GraphicsPath.","om-scogo\u002Fskillsh-scraper","om-scogo","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F160466840?v=4","01M79AWB6DFVCQ7RK70CS34B96","Om Achrekar","01M79AWB6ZM9SKR8KDH1WSSM22",0,"MIT","https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fpixijs-pixijs-skills\u002Fpixijs-scene-graphics\u002FSkill.md",[],[],"2026-11-15 14:19:17",false,"---\nname: pixijs-scene-graphics\ndescription: \"Use this skill when drawing vector shapes and paths in PixiJS v8. Covers the Graphics API: shape-then-fill methods (rect\u002Fcircle\u002Fellipse\u002Fpoly\u002FroundRect\u002Fstar\u002FregularPoly\u002FroundPoly\u002FroundShape\u002FfilletRect\u002FchamferRect), path methods (moveTo\u002FlineTo\u002FbezierCurveTo\u002FquadraticCurveTo\u002Farc\u002FarcTo\u002FarcToSvg\u002FclosePath), fill\u002Fstroke\u002Fcut, holes, FillGradient (linear\u002Fradial), FillPattern, GraphicsContext sharing, svg import\u002Fexport, containsPoint hit testing, cloning, clearing, bounds, fillStyle\u002FstrokeStyle, draw-time transforms (rotateTransform\u002FscaleTransform\u002FtranslateTransform\u002FsetTransform\u002Fsave\u002Frestore), default styles, GraphicsPath reuse. Triggers on: Graphics, GraphicsContext, rect, circle, poly, roundRect, fill, stroke, cut, hole, beginHole, FillGradient, FillPattern, moveTo, bezierCurveTo, svg, graphicsContextToSvg, svg export, GraphicsOptions, containsPoint, clone, clear, bounds, rotateTransform, translateTransform, setFillStyle, setStrokeStyle, GraphicsPath.\"\nlicense: MIT\n---\n\n`Graphics` is the vector-drawing leaf of the PixiJS v8 scene graph. The v8 API follows a shape-then-style pattern: draw a shape or path with `rect`, `circle`, `moveTo`, etc., then apply `fill` and\u002For `stroke`. Every method returns `this` for chaining, and the drawing instructions live on a `GraphicsContext` that can be shared between instances.\n\nAssumes familiarity with `pixijs-scene-core-concepts`. `Graphics` is a leaf: do not nest children inside it. Wrap multiple `Graphics` objects in a `Container` to group them.\n\n## Quick Start\n\n```ts\nconst g = new Graphics();\n\ng.rect(10, 10, 200, 100)\n  .fill({ color: 0x3498db, alpha: 0.8 })\n  .stroke({ width: 3, color: 0x2c3e50 });\n\ng.circle(300, 60, 40).fill(0xe74c3c);\n\ng.moveTo(50, 200)\n  .lineTo(200, 200)\n  .bezierCurveTo(250, 250, 100, 300, 50, 250)\n  .closePath()\n  .fill(0x6c5ce7);\n\napp.stage.addChild(g);\n```\n\n**Related skills:** `pixijs-scene-core-concepts` (scene graph basics), `pixijs-scene-container` (group graphics with other objects), `pixijs-scene-core-concepts\u002Freferences\u002Fmasking.md` (Graphics as a stencil mask), `pixijs-filters` (effects), `pixijs-performance` (batching, `cacheAsTexture`).\n\n## Constructor options\n\nAll `Container` options (`position`, `scale`, `tint`, `label`, `filters`, `zIndex`, etc.) are also valid here — see `skills\u002Fpixijs-scene-core-concepts\u002Freferences\u002Fconstructor-options.md`.\n\nLeaf-specific options added by `GraphicsOptions`:\n\n| Option        | Type              | Default                 | Description                                                                                                                                                                                          |\n| ------------- | ----------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `context`     | `GraphicsContext` | new `GraphicsContext()` | Shared drawing context. Passing a context reuses its tessellated geometry across multiple `Graphics` nodes, avoiding duplicate GPU work. If omitted, each `Graphics` creates and owns a new context. |\n| `roundPixels` | `boolean`         | `false`                 | Rounds the final on-screen `x`\u002F`y` to the nearest pixel. Produces crisper lines for pixel-art styles at the cost of smooth sub-pixel movement.                                                       |\n\nThe constructor also accepts a `GraphicsContext` instance as its sole argument (`new Graphics(ctx)`), which is shorthand for `new Graphics({ context: ctx })`.\n\n## Core Patterns\n\n### Shape-then-fill workflow\n\n```ts\nconst g = new Graphics();\n\ng.rect(10, 10, 200, 100)\n  .fill({ color: 0x3498db, alpha: 0.8 })\n  .stroke({ width: 3, color: 0x2c3e50 });\n\ng.circle(150, 200, 40).fill(0xe74c3c);\ng.roundRect(300, 10, 150, 80, 12).fill(0x2ecc71);\ng.poly([0, 0, 60, 0, 30, 50], true).fill(0x9b59b6);\ng.star(400, 200, 5, 40, 20, 0).fill(0xf39c12);\ng.ellipse(100, 350, 60, 30).fill(0x1abc9c);\n```\n\n`fill()` accepts a `FillInput`: a color number\u002Fstring, `{ color, alpha, texture, matrix, textureSpace }`, a `FillGradient`, a `FillPattern`, or a `Texture`. When filling with a texture, `textureSpace` controls coordinate mapping:\n\n- `'local'` (default): texture is scaled to fit each shape's bounding box (normalized 0-1 coordinates).\n- `'global'`: texture position\u002Fscale are relative to the Graphics object's coordinate system, shared across all shapes.\n\n`FillInput` also supports a nested `fill` subfield: a `FillStyle` options object can embed a `FillGradient` or `FillPattern` under its `fill` key, which applies the gradient or pattern alongside the `color`, `alpha`, `texture`, and `matrix` modifiers on the outer object.\n\n`stroke()` accepts a color, a `FillGradient`, a `FillPattern`, or a `StrokeStyle` object that combines all `FillStyle` keys (`color`, `alpha`, `texture`, `matrix`, `fill`, `textureSpace`) with stroke attributes:\n\n| Attribute    | Default   | Notes                                                                   |\n| ------------ | --------- | ----------------------------------------------------------------------- |\n| `width`      | `1`       | Pixel width of the stroke.                                              |\n| `cap`        | `'butt'`  | One of `'butt'`, `'round'`, `'square'`. End style for open paths.       |\n| `join`       | `'miter'` | One of `'miter'`, `'round'`, `'bevel'`. Corner style.                   |\n| `miterLimit` | `10`      | Caps how far miter joins extend before falling back to bevel.           |\n| `alignment`  | `0.5`     | `1` = inside the shape, `0.5` = centered, `0` = outside.                |\n| `pixelLine`  | `false`   | Aligns 1-pixel lines to the pixel grid for crisp output. Graphics-only. |\n\nStrokes can use the same gradients and patterns as fills via `fill: gradient` or `texture: tex`:\n\n```ts\nconst grad = new FillGradient({\n  end: { x: 1, y: 0 },\n  colorStops: [\n    { offset: 0, color: 0xff0000 },\n    { offset: 1, color: 0x0000ff },\n  ],\n});\ng.rect(0, 0, 200, 100).stroke({\n  width: 8,\n  fill: grad,\n  join: \"round\",\n  cap: \"round\",\n});\n```\n\nBoth `fill()` and `stroke()` can be called after the same shape; calling `stroke()` immediately after `fill()` reuses the same path.\n\n### Advanced shape primitives\n\n```ts\ng.regularPoly(100, 100, 50, 6, 0).fill(0x3498db);\ng.roundPoly(250, 100, 50, 5, 10).fill(0xe74c3c);\ng.chamferRect(350, 50, 100, 80, 15).fill(0x2ecc71);\ng.filletRect(500, 50, 100, 80, 15).fill(0x9b59b6);\ng.roundShape(\n  [\n    { x: 50, y: 250, radius: 20 },\n    { x: 150, y: 250, radius: 5 },\n    { x: 150, y: 350, radius: 10 },\n    { x: 50, y: 350, radius: 15 },\n  ],\n  10,\n).fill(0xf39c12);\n```\n\n### Holes with cut()\n\n```ts\ng.rect(0, 0, 200, 200).fill(0x00ff00).circle(100, 100, 50).cut();\n```\n\n`cut()` subtracts the current active path from the previously drawn fill or stroke. Rules:\n\n- The hole must be **completely inside** the target shape. Holes that overlap edges or sit outside the shape will not render correctly because the renderer triangulates with the hole as an interior boundary.\n- `cut()` looks back at up to the **last two** instructions. When you `fill()` and then `stroke()` the same path, a single `cut()` adds the hole to the stroke first; a second `cut()` adds it to the fill underneath.\n- After `cut()`, the active path resets so you can start the next shape with `moveTo`, `rect`, etc.\n- `cut()` applies to strokes too — `g.rect(...).stroke(...).circle(...).cut()` cuts a hole through the stroke outline.\n\nPunch multiple holes with a single `cut()` by drawing several shapes into the active path before calling it. Each shape accumulates into the same hole path:\n\n```ts\nconst g = new Graphics();\n\ng.rect(350, 350, 150, 150).fill(0x00ff00);\n\n\u002F\u002F Draw three circles into the active path, then cut them all in one call\ng.circle(375, 375, 25);\ng.circle(425, 425, 25);\ng.circle(475, 475, 25);\ng.cut();\n```\n\nIf you need holes on **separate** filled shapes, give each shape its own `fill()` and matching `cut()`:\n\n```ts\ng.rect(0, 0, 100, 100).fill(0x3498db);\ng.circle(50, 50, 20).cut(); \u002F\u002F hole in the rect\n\ng.rect(120, 0, 100, 100).fill(0xe74c3c);\ng.circle(170, 50, 20).cut(); \u002F\u002F hole in the second rect\n```\n\nCalling `cut()` on a shape that already has a hole **adds** to the existing hole path rather than replacing it. Use this to layer holes additively.\n\n### Paths and complex shapes\n\n```ts\ng.moveTo(50, 50)\n  .lineTo(200, 50)\n  .bezierCurveTo(250, 100, 250, 150, 200, 200)\n  .quadraticCurveTo(100, 250, 50, 200)\n  .closePath()\n  .fill({ color: 0x6c5ce7, alpha: 0.7 })\n  .stroke({ width: 2, color: 0xdfe6e9 });\n```\n\nPath methods: `moveTo`, `lineTo`, `bezierCurveTo`, `quadraticCurveTo`, `arc`, `arcTo`, `arcToSvg`, `closePath`. Call `beginPath()` to discard the current path and start a new one.\n\n```ts\n\u002F\u002F arc(cx, cy, radius, startAngle, endAngle, counterclockwise?)\ng.moveTo(80, 50)\n  .arc(50, 50, 30, 0, Math.PI)\n  .stroke({ width: 4, color: 0x2c3e50 });\n\n\u002F\u002F arcTo(x1, y1, x2, y2, radius) — rounded corner between two line segments\ng.moveTo(150, 20)\n  .arcTo(200, 20, 200, 80, 20)\n  .lineTo(200, 80)\n  .stroke({ width: 2 });\n\n\u002F\u002F arcToSvg(rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y) — matches the SVG `A` command\ng.moveTo(250, 50).arcToSvg(40, 20, 0, 1, 0, 330, 50).stroke({ width: 2 });\n```\n\n### Gradients and patterns\n\n```ts\n\u002F\u002F Linear gradient\nconst linear = new FillGradient({\n  end: { x: 1, y: 0 },\n  colorStops: [\n    { offset: 0, color: 0xff0000 },\n    { offset: 1, color: 0x0000ff },\n  ],\n});\ng.rect(0, 0, 200, 100).fill(linear);\n\n\u002F\u002F Radial gradient — inner circle at center, outer circle reaches edges\nconst radial = new FillGradient({\n  type: \"radial\",\n  center: { x: 100, y: 100 },\n  innerRadius: 0,\n  outerCenter: { x: 100, y: 100 },\n  outerRadius: 100,\n  colorStops: [\n    { offset: 0, color: 0xffffff },\n    { offset: 1, color: 0x000000 },\n  ],\n});\ng.circle(100, 100, 100).fill(radial);\n\nconst brick = await Assets.load(\"brick.png\");\n\n\u002F\u002F Options-object form (preferred)\nconst pattern = new FillPattern({\n  texture: brick,\n  repetition: \"repeat\", \u002F\u002F 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat'\n  textureSpace: \"global\", \u002F\u002F 'global' (default) | 'local'\n});\n\n\u002F\u002F Legacy positional form is still supported\nconst pattern2 = new FillPattern(brick, \"repeat\");\n\ng.rect(0, 120, 200, 100).fill(pattern);\n```\n\n`FillGradient`'s default `type` is `'linear'` with `start {0,0}` to `end {0,1}`. Set `type: 'radial'` with `center`\u002F`innerRadius` and `outerCenter`\u002F`outerRadius` for radial gradients.\n\n`FillPattern` takes an options object (`{ texture, repetition?, textureSpace? }`) or the legacy positional form (`new FillPattern(texture, repetition?)`). `repetition` selects the tiling mode. `textureSpace` controls how tiles map to shapes:\n\n- `'global'` (default): tiles repeat continuously across the `Graphics` coordinate system, so adjacent shapes share one tiling grid. Best for backgrounds and seamless textures.\n- `'local'`: a single tile fits each shape's bounds. Combine with `setTransform` to subdivide a shape into a tile grid.\n\nNote `FillPattern` defaults `textureSpace` to `'global'`, unlike the `'local'` default for texture fills shown above.\n\n`setTransform(matrix)` copies the given matrix directly onto the pattern transform to scale, rotate, or offset the tiling; call `setTransform()` with no argument to reset to identity.\n\n### Drawing a texture directly\n\n```ts\nconst tex = await Assets.load(\"icon.png\");\n\n\u002F\u002F Draw the whole texture at (x, y) with optional tint\ng.texture(tex, 0xffffff, 20, 20);\n\n\u002F\u002F Draw a subregion (dx, dy, dw, dh)\ng.texture(tex, 0xff0000, 100, 20, 64, 64);\n```\n\n`Graphics.texture(texture, tint?, dx?, dy?, dw?, dh?)` is a shortcut for drawing a single textured rect without going through `fill()`. Useful for icons where you don't need the full sprite lifecycle.\n\n### GraphicsContext sharing\n\n```ts\nconst ctx = new GraphicsContext().rect(0, 0, 50, 50).fill(0xff0000);\n\nconst g1 = new Graphics(ctx);\nconst g2 = new Graphics(ctx);\ng2.x = 100;\n```\n\nContext sharing avoids duplicate GPU geometry; the expensive tessellation runs once. You can also assign a context after construction: `g.context = existingContext`.\n\n### SVG import and export\n\nParse SVG markup into the active context with `svg()`:\n\n```ts\ng.svg(`\u003Csvg viewBox=\"0 0 100 100\">\n    \u003Ccircle cx=\"50\" cy=\"50\" r=\"40\" fill=\"red\"\u002F>\n\u003C\u002Fsvg>`);\n```\n\n`svg()` supports paths, basic shapes, and inline styles; complex hole geometries may render inaccurately because Pixi's triangulation is performance-optimized.\n\nSerialize a `Graphics` or `GraphicsContext` back to a self-contained SVG document string with `graphicsContextToSvg`:\n\n```ts\nimport { Graphics, graphicsContextToSvg } from \"pixi.js\";\n\nconst g = new Graphics()\n  .rect(0, 0, 100, 50)\n  .fill({ color: 0xff0000 })\n  .circle(150, 25, 25)\n  .stroke({ color: 0x0000ff, width: 4 });\n\nconst svgString = graphicsContextToSvg(g, 2);\n```\n\n`graphicsContextToSvg(source, precision = 2)` is a pure function that reads the context's instructions and returns a complete `\u003Csvg>` string with an auto-computed `viewBox`. Pass a `Graphics` or a `GraphicsContext`; `precision` controls decimal places on emitted coordinates. Exports every shape-then-fill primitive (advanced ones like `regularPoly`\u002F`filletRect` fall back to a shape-path), all path methods, stroke attributes (`width`, `cap`, `join`, `miterLimit`), `fill-opacity`\u002F`stroke-opacity`, and `FillGradient` (linear and radial) via a `\u003Cdefs>` block. Holes collapse into one `\u003Cpath>` with `fill-rule=\"evenodd\"`. `FillPattern` and texture fills have no SVG equivalent: patterns fall through to the fill's solid `color`, and `texture()` instructions are skipped entirely. Exported markup roundtrips back through `g.svg(...)` without cleanup, so you can export, store, and later reimport a shape into another `Graphics`.\n\n### Reusing a GraphicsPath\n\n```ts\nconst arrow = new GraphicsPath()\n  .moveTo(0, 0)\n  .lineTo(40, 0)\n  .lineTo(40, -10)\n  .lineTo(60, 10)\n  .lineTo(40, 30)\n  .lineTo(40, 20)\n  .lineTo(0, 20)\n  .closePath();\n\ng.path(arrow).fill(0x3498db);\ng.translateTransform(80, 0).path(arrow).fill(0xe74c3c);\n```\n\n`Graphics.path(graphicsPath)` (and `GraphicsContext.path()`) appends a prebuilt `GraphicsPath` onto the active path. Build once, draw many times.\n\n### Draw-time transforms\n\n`Graphics` has its own transform stack used **while drawing** that is separate from the `Container` transform applied to the rendered output. The drawing methods are renamed to avoid clashing with `Container.rotation`, `Container.scale`, `Container.position`:\n\n| Drawing transform                                         | Container transform       |\n| --------------------------------------------------------- | ------------------------- |\n| `g.rotateTransform(angle)`                                | `g.rotation`              |\n| `g.scaleTransform(x, y?)`                                 | `g.scale.set(x, y)`       |\n| `g.translateTransform(x, y?)`                             | `g.position.set(x, y)`    |\n| `g.setTransform(matrix)` or `setTransform(a,b,c,d,tx,ty)` | `g.setFromMatrix(matrix)` |\n| `g.transform(matrix)` or `transform(a,b,c,d,tx,ty)`       | n\u002Fa                       |\n| `g.getTransform()` \u002F `g.resetTransform()`                 | n\u002Fa                       |\n\n```ts\nconst g = new Graphics();\n\ng.translateTransform(100, 100)\n  .rotateTransform(Math.PI \u002F 4)\n  .rect(-25, -25, 50, 50)\n  .fill(0x3498db);\n\n\u002F\u002F The square is rotated 45 degrees as it is added to the geometry.\n\u002F\u002F Setting g.rotation later rotates the entire Graphics on screen.\n```\n\nThe drawing transform affects every subsequent shape and path command added to the context. Use `save()`\u002F`restore()` to scope it.\n\n### State save\u002Frestore\n\n```ts\ng.save();\ng.translateTransform(100, 100);\ng.rotateTransform(Math.PI \u002F 4);\ng.rect(0, 0, 50, 50).fill(0xff0000);\ng.restore();\n```\n\n`save()` pushes the drawing transform, fill style, and stroke style onto a stack; `restore()` pops them. `Graphics` exposes `save`\u002F`restore` directly, mirroring the underlying `GraphicsContext` calls.\n\n### Default styles via setFillStyle \u002F setStrokeStyle\n\n```ts\ng.setFillStyle({ color: 0x3498db, alpha: 0.8 }).setStrokeStyle({\n  width: 2,\n  color: 0x2c3e50,\n});\n\ng.rect(0, 0, 100, 100).fill().stroke();\ng.circle(150, 50, 40).fill().stroke();\n```\n\n`setFillStyle()` and `setStrokeStyle()` configure the default style used by subsequent `fill()` \u002F `stroke()` calls when no argument is passed. Read or replace the current style at any time via the `fillStyle` and `strokeStyle` getters\u002Fsetters. Override the library-wide defaults by mutating `GraphicsContext.defaultFillStyle` and `GraphicsContext.defaultStrokeStyle` once at startup.\n\n### Hit testing\n\n```ts\nconst g = new Graphics().star(100, 100, 5, 60, 30).fill(0xf39c12);\ng.eventMode = \"static\";\ng.on(\"pointermove\", (e) => {\n  if (g.containsPoint(g.toLocal(e.global))) {\n    \u002F* over the star, not just its bbox *\u002F\n  }\n});\n```\n\n`Graphics.containsPoint(pointInLocalSpace)` runs a topology-aware test against every filled and stroked shape in the context, including holes. Convert global pointer coordinates with `toLocal()` first.\n\n### Cloning, clearing, and bounds\n\n```ts\nconst g = new Graphics().rect(0, 0, 100, 100).fill(0xff0000);\n\nconst shallow = g.clone(); \u002F\u002F shares the same GraphicsContext\nconst deep = g.clone(true); \u002F\u002F creates an independent context\n\nconsole.log(g.bounds.width); \u002F\u002F 100 - geometry bounds before transforms\n\ng.clear(); \u002F\u002F wipes active path, instructions, and transform; fill\u002Fstroke styles persist\n```\n\n- `clone()` returns a new `Graphics` that shares the source context (cheap, geometry is reused). Both objects update together if the context changes.\n- `clone(true)` clones the context as well so the new `Graphics` can be edited independently.\n- `bounds` returns the geometry bounds before the `Container` transform. Useful for layout decisions.\n- `clear()` resets the context so the same `Graphics` can be reused. See **Common Mistakes** below for guidance on when to clear versus when to keep stable geometry.\n\n### GraphicsContext utilities\n\n| Member                                          | Behavior                                                                                             |\n| ----------------------------------------------- | ---------------------------------------------------------------------------------------------------- |\n| `ctx.path(graphicsPath)`                        | Apply a prebuilt `GraphicsPath` onto the active path. Reuse one path across many contexts or frames. |\n| `ctx.beginPath()`                               | Discard the current active path and start a new one without affecting committed instructions.        |\n| `ctx.setFillStyle(style)` \u002F `ctx.fillStyle`     | Set or read the default fill style used by subsequent shapes without calling `fill()`.               |\n| `ctx.setStrokeStyle(style)` \u002F `ctx.strokeStyle` | Set or read the default stroke style used by subsequent shapes without calling `stroke()`.           |\n| `ctx.bounds`                                    | Cached geometry bounds across all fill\u002Fstroke\u002Ftexture instructions.                                  |\n| `ctx.clear()`                                   | Wipe instructions, the active path, and the drawing transform.                                       |\n| `ctx.clone()`                                   | Deep copy including instructions, active path, transform, styles, and stack.                         |\n| `ctx.containsPoint(point)`                      | Topology-aware hit test against all filled and stroked shapes (including holes).                     |\n| `ctx.batchMode`                                 | One of `'auto'`, `'batch'`, `'no-batch'` — force or disable batching for the shapes in this context. |\n| `ctx.customShader`                              | Assign a `Shader` to override the default graphics shader.                                           |\n| `GraphicsContext.defaultFillStyle`              | Static fallback used when `fill()` is called without arguments and no fill style is set.             |\n| `GraphicsContext.defaultStrokeStyle`            | Static fallback used when `stroke()` is called without arguments and no stroke style is set.         |\n\n`GraphicsContext` is an `EventEmitter` that emits `update`, `destroy`, and `unload` events. Subscribe via `ctx.on('update' | 'destroy' | 'unload', cb)` when tooling or pools need to react to context lifecycle changes.\n\n## Common Mistakes\n\n### [CRITICAL] Using v7 beginFill\u002FdrawRect\u002FendFill\n\nWrong:\n\n```ts\nconst g = new Graphics().beginFill(0xff0000).drawRect(0, 0, 100, 100).endFill();\n```\n\nCorrect:\n\n```ts\nconst g = new Graphics().rect(0, 0, 100, 100).fill(0xff0000);\n```\n\nv8 replaced \"set style, draw, end\" with \"draw shape, then apply style\". `beginFill`\u002F`endFill` do not exist.\n\n\n### [CRITICAL] Using old shape method names\n\nWrong:\n\n```ts\ng.drawCircle(50, 50, 25);\n```\n\nCorrect:\n\n```ts\ng.circle(50, 50, 25);\n```\n\nAll `draw*` methods were renamed in v8: `drawRect` → `rect`, `drawCircle` → `circle`, `drawEllipse` → `ellipse`, `drawPolygon` → `poly`, `drawRoundedRect` → `roundRect`, `drawStar` → `star`.\n\n\n### [CRITICAL] Using lineStyle instead of stroke\n\nWrong:\n\n```ts\ng.lineStyle(2, 0xffffff);\ng.drawRect(0, 0, 100, 100);\n```\n\nCorrect:\n\n```ts\ng.rect(0, 0, 100, 100).stroke({ width: 2, color: 0xffffff });\n```\n\n`lineStyle` was removed. Use `stroke()` after drawing the shape. The stroke options object accepts `width`, `color`, `alpha`, `cap`, `join`, `alignment`, `miterLimit`, and `pixelLine`.\n\n\n### [HIGH] Using beginHole\u002FendHole for holes\n\nWrong:\n\n```ts\ng.beginFill(0x00ff00)\n  .drawRect(0, 0, 100, 100)\n  .beginHole()\n  .drawCircle(50, 50, 20)\n  .endHole()\n  .endFill();\n```\n\nCorrect:\n\n```ts\ng.rect(0, 0, 100, 100).fill(0x00ff00).circle(50, 50, 20).cut();\n```\n\n`beginHole`\u002F`endHole` were replaced by `cut()`. Draw the outer shape, fill it, then draw the hole shape and call `cut()`.\n\n\n### [HIGH] Using GraphicsGeometry instead of GraphicsContext\n\nWrong:\n\n```ts\nconst geom = g.geometry;\nconst clone = new Graphics(geom);\n```\n\nCorrect:\n\n```ts\nconst ctx = new GraphicsContext().rect(0, 0, 100, 100).fill(0xff0000);\nconst g1 = new Graphics(ctx);\nconst g2 = new Graphics(ctx);\n```\n\n`GraphicsGeometry` was replaced by `GraphicsContext` in v8. There is no `.geometry` property.\n\n\n### [HIGH] Destroying a shared GraphicsContext unexpectedly\n\n```ts\nconst ctx = new GraphicsContext().rect(0, 0, 50, 50).fill(0xff0000);\nconst g1 = new Graphics(ctx);\nconst g2 = new Graphics(ctx);\n\ng1.destroy({ context: true }); \u002F\u002F also nullifies g2's context reference\n```\n\nDestroying a shared `GraphicsContext` does not destroy sharing instances but breaks them by nullifying their context reference. When passing a context via the constructor, `destroy()` with no args preserves the context; use `destroy({ context: false })` to be explicit. Only destroy the context when all sharing instances are done with it. A self-owned context (not passed via constructor) is still destroyed by `destroy()` with no args.\n\n\n### [HIGH] Clearing and redrawing Graphics every frame\n\nGraphics are designed to be stable, not dynamic. Calling `clear()` and redrawing every frame rebuilds GPU geometry each time. For dynamic visuals:\n\n- Use `Sprite` with pre-rendered textures and transform changes.\n- Use `cacheAsTexture(true)` for complex static graphics.\n- For real-time shape changes, consider `Mesh` with custom geometry updates.\n\nThis is the opposite of HTML Canvas 2D, where redrawing each frame is normal. PixiJS tessellates shapes into GPU triangles, so initial draw is expensive but subsequent renders are fast. Treat `Graphics` more like SVG elements than canvas draw calls.\n\n\n### [MEDIUM] Do not nest children inside a Graphics\n\n`Graphics` sets `allowChildren = false`. Adding children logs a deprecation warning and will be a hard error in a future version. Wrap multiple graphics alongside other leaves in a plain `Container`:\n\n```ts\nconst group = new Container();\ngroup.addChild(graphics, sprite);\n```\n\n\n## API Reference\n\n- [Graphics](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.Graphics.html.md)\n- [GraphicsOptions](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.GraphicsOptions.html.md)\n- [GraphicsContext](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.GraphicsContext.html.md)\n- [GraphicsPath](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.GraphicsPath.html.md)\n- [graphicsContextToSvg](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.graphicsContextToSvg.html.md)\n- [FillGradient](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.FillGradient.html.md)\n- [FillPattern](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.FillPattern.html.md)\n- [FillStyle](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.FillStyle.html.md)\n- [FillInput](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.FillInput.html.md)\n","`Graphics` is the vector-drawing leaf of the PixiJS v8 scene graph. The v8 API follows a shape-then-style pattern: draw a shape or path with `rect`, `circle`, `moveTo`, etc., then apply `fill` and\u002For `stroke`. Every method returns `this` for chaining, and the drawing instructions live on a `GraphicsContext` that can be shared between instances.\n\nAssumes familiarity with `pixijs-scene-core-concepts`. `Graphics` is a leaf: do not nest children inside it. Wrap multiple `Graphics` objects in a `Container` to group them.\n\n## Quick Start\n\n```ts\nconst g = new Graphics();\n\ng.rect(10, 10, 200, 100)\n  .fill({ color: 0x3498db, alpha: 0.8 })\n  .stroke({ width: 3, color: 0x2c3e50 });\n\ng.circle(300, 60, 40).fill(0xe74c3c);\n\ng.moveTo(50, 200)\n  .lineTo(200, 200)\n  .bezierCurveTo(250, 250, 100, 300, 50, 250)\n  .closePath()\n  .fill(0x6c5ce7);\n\napp.stage.addChild(g);\n```\n\n**Related skills:** `pixijs-scene-core-concepts` (scene graph basics), `pixijs-scene-container` (group graphics with other objects), `pixijs-scene-core-concepts\u002Freferences\u002Fmasking.md` (Graphics as a stencil mask), `pixijs-filters` (effects), `pixijs-performance` (batching, `cacheAsTexture`).\n\n## Constructor options\n\nAll `Container` options (`position`, `scale`, `tint`, `label`, `filters`, `zIndex`, etc.) are also valid here — see `skills\u002Fpixijs-scene-core-concepts\u002Freferences\u002Fconstructor-options.md`.\n\nLeaf-specific options added by `GraphicsOptions`:\n\n| Option        | Type              | Default                 | Description                                                                                                                                                                                          |\n| ------------- | ----------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `context`     | `GraphicsContext` | new `GraphicsContext()` | Shared drawing context. Passing a context reuses its tessellated geometry across multiple `Graphics` nodes, avoiding duplicate GPU work. If omitted, each `Graphics` creates and owns a new context. |\n| `roundPixels` | `boolean`         | `false`                 | Rounds the final on-screen `x`\u002F`y` to the nearest pixel. Produces crisper lines for pixel-art styles at the cost of smooth sub-pixel movement.                                                       |\n\nThe constructor also accepts a `GraphicsContext` instance as its sole argument (`new Graphics(ctx)`), which is shorthand for `new Graphics({ context: ctx })`.\n\n## Core Patterns\n\n### Shape-then-fill workflow\n\n```ts\nconst g = new Graphics();\n\ng.rect(10, 10, 200, 100)\n  .fill({ color: 0x3498db, alpha: 0.8 })\n  .stroke({ width: 3, color: 0x2c3e50 });\n\ng.circle(150, 200, 40).fill(0xe74c3c);\ng.roundRect(300, 10, 150, 80, 12).fill(0x2ecc71);\ng.poly([0, 0, 60, 0, 30, 50], true).fill(0x9b59b6);\ng.star(400, 200, 5, 40, 20, 0).fill(0xf39c12);\ng.ellipse(100, 350, 60, 30).fill(0x1abc9c);\n```\n\n`fill()` accepts a `FillInput`: a color number\u002Fstring, `{ color, alpha, texture, matrix, textureSpace }`, a `FillGradient`, a `FillPattern`, or a `Texture`. When filling with a texture, `textureSpace` controls coordinate mapping:\n\n- `'local'` (default): texture is scaled to fit each shape's bounding box (normalized 0-1 coordinates).\n- `'global'`: texture position\u002Fscale are relative to the Graphics object's coordinate system, shared across all shapes.\n\n`FillInput` also supports a nested `fill` subfield: a `FillStyle` options object can embed a `FillGradient` or `FillPattern` under its `fill` key, which applies the gradient or pattern alongside the `color`, `alpha`, `texture`, and `matrix` modifiers on the outer object.\n\n`stroke()` accepts a color, a `FillGradient`, a `FillPattern`, or a `StrokeStyle` object that combines all `FillStyle` keys (`color`, `alpha`, `texture`, `matrix`, `fill`, `textureSpace`) with stroke attributes:\n\n| Attribute    | Default   | Notes                                                                   |\n| ------------ | --------- | ----------------------------------------------------------------------- |\n| `width`      | `1`       | Pixel width of the stroke.                                              |\n| `cap`        | `'butt'`  | One of `'butt'`, `'round'`, `'square'`. End style for open paths.       |\n| `join`       | `'miter'` | One of `'miter'`, `'round'`, `'bevel'`. Corner style.                   |\n| `miterLimit` | `10`      | Caps how far miter joins extend before falling back to bevel.           |\n| `alignment`  | `0.5`     | `1` = inside the shape, `0.5` = centered, `0` = outside.                |\n| `pixelLine`  | `false`   | Aligns 1-pixel lines to the pixel grid for crisp output. Graphics-only. |\n\nStrokes can use the same gradients and patterns as fills via `fill: gradient` or `texture: tex`:\n\n```ts\nconst grad = new FillGradient({\n  end: { x: 1, y: 0 },\n  colorStops: [\n    { offset: 0, color: 0xff0000 },\n    { offset: 1, color: 0x0000ff },\n  ],\n});\ng.rect(0, 0, 200, 100).stroke({\n  width: 8,\n  fill: grad,\n  join: \"round\",\n  cap: \"round\",\n});\n```\n\nBoth `fill()` and `stroke()` can be called after the same shape; calling `stroke()` immediately after `fill()` reuses the same path.\n\n### Advanced shape primitives\n\n```ts\ng.regularPoly(100, 100, 50, 6, 0).fill(0x3498db);\ng.roundPoly(250, 100, 50, 5, 10).fill(0xe74c3c);\ng.chamferRect(350, 50, 100, 80, 15).fill(0x2ecc71);\ng.filletRect(500, 50, 100, 80, 15).fill(0x9b59b6);\ng.roundShape(\n  [\n    { x: 50, y: 250, radius: 20 },\n    { x: 150, y: 250, radius: 5 },\n    { x: 150, y: 350, radius: 10 },\n    { x: 50, y: 350, radius: 15 },\n  ],\n  10,\n).fill(0xf39c12);\n```\n\n### Holes with cut()\n\n```ts\ng.rect(0, 0, 200, 200).fill(0x00ff00).circle(100, 100, 50).cut();\n```\n\n`cut()` subtracts the current active path from the previously drawn fill or stroke. Rules:\n\n- The hole must be **completely inside** the target shape. Holes that overlap edges or sit outside the shape will not render correctly because the renderer triangulates with the hole as an interior boundary.\n- `cut()` looks back at up to the **last two** instructions. When you `fill()` and then `stroke()` the same path, a single `cut()` adds the hole to the stroke first; a second `cut()` adds it to the fill underneath.\n- After `cut()`, the active path resets so you can start the next shape with `moveTo`, `rect`, etc.\n- `cut()` applies to strokes too — `g.rect(...).stroke(...).circle(...).cut()` cuts a hole through the stroke outline.\n\nPunch multiple holes with a single `cut()` by drawing several shapes into the active path before calling it. Each shape accumulates into the same hole path:\n\n```ts\nconst g = new Graphics();\n\ng.rect(350, 350, 150, 150).fill(0x00ff00);\n\n\u002F\u002F Draw three circles into the active path, then cut them all in one call\ng.circle(375, 375, 25);\ng.circle(425, 425, 25);\ng.circle(475, 475, 25);\ng.cut();\n```\n\nIf you need holes on **separate** filled shapes, give each shape its own `fill()` and matching `cut()`:\n\n```ts\ng.rect(0, 0, 100, 100).fill(0x3498db);\ng.circle(50, 50, 20).cut(); \u002F\u002F hole in the rect\n\ng.rect(120, 0, 100, 100).fill(0xe74c3c);\ng.circle(170, 50, 20).cut(); \u002F\u002F hole in the second rect\n```\n\nCalling `cut()` on a shape that already has a hole **adds** to the existing hole path rather than replacing it. Use this to layer holes additively.\n\n### Paths and complex shapes\n\n```ts\ng.moveTo(50, 50)\n  .lineTo(200, 50)\n  .bezierCurveTo(250, 100, 250, 150, 200, 200)\n  .quadraticCurveTo(100, 250, 50, 200)\n  .closePath()\n  .fill({ color: 0x6c5ce7, alpha: 0.7 })\n  .stroke({ width: 2, color: 0xdfe6e9 });\n```\n\nPath methods: `moveTo`, `lineTo`, `bezierCurveTo`, `quadraticCurveTo`, `arc`, `arcTo`, `arcToSvg`, `closePath`. Call `beginPath()` to discard the current path and start a new one.\n\n```ts\n\u002F\u002F arc(cx, cy, radius, startAngle, endAngle, counterclockwise?)\ng.moveTo(80, 50)\n  .arc(50, 50, 30, 0, Math.PI)\n  .stroke({ width: 4, color: 0x2c3e50 });\n\n\u002F\u002F arcTo(x1, y1, x2, y2, radius) — rounded corner between two line segments\ng.moveTo(150, 20)\n  .arcTo(200, 20, 200, 80, 20)\n  .lineTo(200, 80)\n  .stroke({ width: 2 });\n\n\u002F\u002F arcToSvg(rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y) — matches the SVG `A` command\ng.moveTo(250, 50).arcToSvg(40, 20, 0, 1, 0, 330, 50).stroke({ width: 2 });\n```\n\n### Gradients and patterns\n\n```ts\n\u002F\u002F Linear gradient\nconst linear = new FillGradient({\n  end: { x: 1, y: 0 },\n  colorStops: [\n    { offset: 0, color: 0xff0000 },\n    { offset: 1, color: 0x0000ff },\n  ],\n});\ng.rect(0, 0, 200, 100).fill(linear);\n\n\u002F\u002F Radial gradient — inner circle at center, outer circle reaches edges\nconst radial = new FillGradient({\n  type: \"radial\",\n  center: { x: 100, y: 100 },\n  innerRadius: 0,\n  outerCenter: { x: 100, y: 100 },\n  outerRadius: 100,\n  colorStops: [\n    { offset: 0, color: 0xffffff },\n    { offset: 1, color: 0x000000 },\n  ],\n});\ng.circle(100, 100, 100).fill(radial);\n\nconst brick = await Assets.load(\"brick.png\");\n\n\u002F\u002F Options-object form (preferred)\nconst pattern = new FillPattern({\n  texture: brick,\n  repetition: \"repeat\", \u002F\u002F 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat'\n  textureSpace: \"global\", \u002F\u002F 'global' (default) | 'local'\n});\n\n\u002F\u002F Legacy positional form is still supported\nconst pattern2 = new FillPattern(brick, \"repeat\");\n\ng.rect(0, 120, 200, 100).fill(pattern);\n```\n\n`FillGradient`'s default `type` is `'linear'` with `start {0,0}` to `end {0,1}`. Set `type: 'radial'` with `center`\u002F`innerRadius` and `outerCenter`\u002F`outerRadius` for radial gradients.\n\n`FillPattern` takes an options object (`{ texture, repetition?, textureSpace? }`) or the legacy positional form (`new FillPattern(texture, repetition?)`). `repetition` selects the tiling mode. `textureSpace` controls how tiles map to shapes:\n\n- `'global'` (default): tiles repeat continuously across the `Graphics` coordinate system, so adjacent shapes share one tiling grid. Best for backgrounds and seamless textures.\n- `'local'`: a single tile fits each shape's bounds. Combine with `setTransform` to subdivide a shape into a tile grid.\n\nNote `FillPattern` defaults `textureSpace` to `'global'`, unlike the `'local'` default for texture fills shown above.\n\n`setTransform(matrix)` copies the given matrix directly onto the pattern transform to scale, rotate, or offset the tiling; call `setTransform()` with no argument to reset to identity.\n\n### Drawing a texture directly\n\n```ts\nconst tex = await Assets.load(\"icon.png\");\n\n\u002F\u002F Draw the whole texture at (x, y) with optional tint\ng.texture(tex, 0xffffff, 20, 20);\n\n\u002F\u002F Draw a subregion (dx, dy, dw, dh)\ng.texture(tex, 0xff0000, 100, 20, 64, 64);\n```\n\n`Graphics.texture(texture, tint?, dx?, dy?, dw?, dh?)` is a shortcut for drawing a single textured rect without going through `fill()`. Useful for icons where you don't need the full sprite lifecycle.\n\n### GraphicsContext sharing\n\n```ts\nconst ctx = new GraphicsContext().rect(0, 0, 50, 50).fill(0xff0000);\n\nconst g1 = new Graphics(ctx);\nconst g2 = new Graphics(ctx);\ng2.x = 100;\n```\n\nContext sharing avoids duplicate GPU geometry; the expensive tessellation runs once. You can also assign a context after construction: `g.context = existingContext`.\n\n### SVG import and export\n\nParse SVG markup into the active context with `svg()`:\n\n```ts\ng.svg(`\u003Csvg viewBox=\"0 0 100 100\">\n    \u003Ccircle cx=\"50\" cy=\"50\" r=\"40\" fill=\"red\"\u002F>\n\u003C\u002Fsvg>`);\n```\n\n`svg()` supports paths, basic shapes, and inline styles; complex hole geometries may render inaccurately because Pixi's triangulation is performance-optimized.\n\nSerialize a `Graphics` or `GraphicsContext` back to a self-contained SVG document string with `graphicsContextToSvg`:\n\n```ts\nimport { Graphics, graphicsContextToSvg } from \"pixi.js\";\n\nconst g = new Graphics()\n  .rect(0, 0, 100, 50)\n  .fill({ color: 0xff0000 })\n  .circle(150, 25, 25)\n  .stroke({ color: 0x0000ff, width: 4 });\n\nconst svgString = graphicsContextToSvg(g, 2);\n```\n\n`graphicsContextToSvg(source, precision = 2)` is a pure function that reads the context's instructions and returns a complete `\u003Csvg>` string with an auto-computed `viewBox`. Pass a `Graphics` or a `GraphicsContext`; `precision` controls decimal places on emitted coordinates. Exports every shape-then-fill primitive (advanced ones like `regularPoly`\u002F`filletRect` fall back to a shape-path), all path methods, stroke attributes (`width`, `cap`, `join`, `miterLimit`), `fill-opacity`\u002F`stroke-opacity`, and `FillGradient` (linear and radial) via a `\u003Cdefs>` block. Holes collapse into one `\u003Cpath>` with `fill-rule=\"evenodd\"`. `FillPattern` and texture fills have no SVG equivalent: patterns fall through to the fill's solid `color`, and `texture()` instructions are skipped entirely. Exported markup roundtrips back through `g.svg(...)` without cleanup, so you can export, store, and later reimport a shape into another `Graphics`.\n\n### Reusing a GraphicsPath\n\n```ts\nconst arrow = new GraphicsPath()\n  .moveTo(0, 0)\n  .lineTo(40, 0)\n  .lineTo(40, -10)\n  .lineTo(60, 10)\n  .lineTo(40, 30)\n  .lineTo(40, 20)\n  .lineTo(0, 20)\n  .closePath();\n\ng.path(arrow).fill(0x3498db);\ng.translateTransform(80, 0).path(arrow).fill(0xe74c3c);\n```\n\n`Graphics.path(graphicsPath)` (and `GraphicsContext.path()`) appends a prebuilt `GraphicsPath` onto the active path. Build once, draw many times.\n\n### Draw-time transforms\n\n`Graphics` has its own transform stack used **while drawing** that is separate from the `Container` transform applied to the rendered output. The drawing methods are renamed to avoid clashing with `Container.rotation`, `Container.scale`, `Container.position`:\n\n| Drawing transform                                         | Container transform       |\n| --------------------------------------------------------- | ------------------------- |\n| `g.rotateTransform(angle)`                                | `g.rotation`              |\n| `g.scaleTransform(x, y?)`                                 | `g.scale.set(x, y)`       |\n| `g.translateTransform(x, y?)`                             | `g.position.set(x, y)`    |\n| `g.setTransform(matrix)` or `setTransform(a,b,c,d,tx,ty)` | `g.setFromMatrix(matrix)` |\n| `g.transform(matrix)` or `transform(a,b,c,d,tx,ty)`       | n\u002Fa                       |\n| `g.getTransform()` \u002F `g.resetTransform()`                 | n\u002Fa                       |\n\n```ts\nconst g = new Graphics();\n\ng.translateTransform(100, 100)\n  .rotateTransform(Math.PI \u002F 4)\n  .rect(-25, -25, 50, 50)\n  .fill(0x3498db);\n\n\u002F\u002F The square is rotated 45 degrees as it is added to the geometry.\n\u002F\u002F Setting g.rotation later rotates the entire Graphics on screen.\n```\n\nThe drawing transform affects every subsequent shape and path command added to the context. Use `save()`\u002F`restore()` to scope it.\n\n### State save\u002Frestore\n\n```ts\ng.save();\ng.translateTransform(100, 100);\ng.rotateTransform(Math.PI \u002F 4);\ng.rect(0, 0, 50, 50).fill(0xff0000);\ng.restore();\n```\n\n`save()` pushes the drawing transform, fill style, and stroke style onto a stack; `restore()` pops them. `Graphics` exposes `save`\u002F`restore` directly, mirroring the underlying `GraphicsContext` calls.\n\n### Default styles via setFillStyle \u002F setStrokeStyle\n\n```ts\ng.setFillStyle({ color: 0x3498db, alpha: 0.8 }).setStrokeStyle({\n  width: 2,\n  color: 0x2c3e50,\n});\n\ng.rect(0, 0, 100, 100).fill().stroke();\ng.circle(150, 50, 40).fill().stroke();\n```\n\n`setFillStyle()` and `setStrokeStyle()` configure the default style used by subsequent `fill()` \u002F `stroke()` calls when no argument is passed. Read or replace the current style at any time via the `fillStyle` and `strokeStyle` getters\u002Fsetters. Override the library-wide defaults by mutating `GraphicsContext.defaultFillStyle` and `GraphicsContext.defaultStrokeStyle` once at startup.\n\n### Hit testing\n\n```ts\nconst g = new Graphics().star(100, 100, 5, 60, 30).fill(0xf39c12);\ng.eventMode = \"static\";\ng.on(\"pointermove\", (e) => {\n  if (g.containsPoint(g.toLocal(e.global))) {\n    \u002F* over the star, not just its bbox *\u002F\n  }\n});\n```\n\n`Graphics.containsPoint(pointInLocalSpace)` runs a topology-aware test against every filled and stroked shape in the context, including holes. Convert global pointer coordinates with `toLocal()` first.\n\n### Cloning, clearing, and bounds\n\n```ts\nconst g = new Graphics().rect(0, 0, 100, 100).fill(0xff0000);\n\nconst shallow = g.clone(); \u002F\u002F shares the same GraphicsContext\nconst deep = g.clone(true); \u002F\u002F creates an independent context\n\nconsole.log(g.bounds.width); \u002F\u002F 100 - geometry bounds before transforms\n\ng.clear(); \u002F\u002F wipes active path, instructions, and transform; fill\u002Fstroke styles persist\n```\n\n- `clone()` returns a new `Graphics` that shares the source context (cheap, geometry is reused). Both objects update together if the context changes.\n- `clone(true)` clones the context as well so the new `Graphics` can be edited independently.\n- `bounds` returns the geometry bounds before the `Container` transform. Useful for layout decisions.\n- `clear()` resets the context so the same `Graphics` can be reused. See **Common Mistakes** below for guidance on when to clear versus when to keep stable geometry.\n\n### GraphicsContext utilities\n\n| Member                                          | Behavior                                                                                             |\n| ----------------------------------------------- | ---------------------------------------------------------------------------------------------------- |\n| `ctx.path(graphicsPath)`                        | Apply a prebuilt `GraphicsPath` onto the active path. Reuse one path across many contexts or frames. |\n| `ctx.beginPath()`                               | Discard the current active path and start a new one without affecting committed instructions.        |\n| `ctx.setFillStyle(style)` \u002F `ctx.fillStyle`     | Set or read the default fill style used by subsequent shapes without calling `fill()`.               |\n| `ctx.setStrokeStyle(style)` \u002F `ctx.strokeStyle` | Set or read the default stroke style used by subsequent shapes without calling `stroke()`.           |\n| `ctx.bounds`                                    | Cached geometry bounds across all fill\u002Fstroke\u002Ftexture instructions.                                  |\n| `ctx.clear()`                                   | Wipe instructions, the active path, and the drawing transform.                                       |\n| `ctx.clone()`                                   | Deep copy including instructions, active path, transform, styles, and stack.                         |\n| `ctx.containsPoint(point)`                      | Topology-aware hit test against all filled and stroked shapes (including holes).                     |\n| `ctx.batchMode`                                 | One of `'auto'`, `'batch'`, `'no-batch'` — force or disable batching for the shapes in this context. |\n| `ctx.customShader`                              | Assign a `Shader` to override the default graphics shader.                                           |\n| `GraphicsContext.defaultFillStyle`              | Static fallback used when `fill()` is called without arguments and no fill style is set.             |\n| `GraphicsContext.defaultStrokeStyle`            | Static fallback used when `stroke()` is called without arguments and no stroke style is set.         |\n\n`GraphicsContext` is an `EventEmitter` that emits `update`, `destroy`, and `unload` events. Subscribe via `ctx.on('update' | 'destroy' | 'unload', cb)` when tooling or pools need to react to context lifecycle changes.\n\n## Common Mistakes\n\n### [CRITICAL] Using v7 beginFill\u002FdrawRect\u002FendFill\n\nWrong:\n\n```ts\nconst g = new Graphics().beginFill(0xff0000).drawRect(0, 0, 100, 100).endFill();\n```\n\nCorrect:\n\n```ts\nconst g = new Graphics().rect(0, 0, 100, 100).fill(0xff0000);\n```\n\nv8 replaced \"set style, draw, end\" with \"draw shape, then apply style\". `beginFill`\u002F`endFill` do not exist.\n\n\n### [CRITICAL] Using old shape method names\n\nWrong:\n\n```ts\ng.drawCircle(50, 50, 25);\n```\n\nCorrect:\n\n```ts\ng.circle(50, 50, 25);\n```\n\nAll `draw*` methods were renamed in v8: `drawRect` → `rect`, `drawCircle` → `circle`, `drawEllipse` → `ellipse`, `drawPolygon` → `poly`, `drawRoundedRect` → `roundRect`, `drawStar` → `star`.\n\n\n### [CRITICAL] Using lineStyle instead of stroke\n\nWrong:\n\n```ts\ng.lineStyle(2, 0xffffff);\ng.drawRect(0, 0, 100, 100);\n```\n\nCorrect:\n\n```ts\ng.rect(0, 0, 100, 100).stroke({ width: 2, color: 0xffffff });\n```\n\n`lineStyle` was removed. Use `stroke()` after drawing the shape. The stroke options object accepts `width`, `color`, `alpha`, `cap`, `join`, `alignment`, `miterLimit`, and `pixelLine`.\n\n\n### [HIGH] Using beginHole\u002FendHole for holes\n\nWrong:\n\n```ts\ng.beginFill(0x00ff00)\n  .drawRect(0, 0, 100, 100)\n  .beginHole()\n  .drawCircle(50, 50, 20)\n  .endHole()\n  .endFill();\n```\n\nCorrect:\n\n```ts\ng.rect(0, 0, 100, 100).fill(0x00ff00).circle(50, 50, 20).cut();\n```\n\n`beginHole`\u002F`endHole` were replaced by `cut()`. Draw the outer shape, fill it, then draw the hole shape and call `cut()`.\n\n\n### [HIGH] Using GraphicsGeometry instead of GraphicsContext\n\nWrong:\n\n```ts\nconst geom = g.geometry;\nconst clone = new Graphics(geom);\n```\n\nCorrect:\n\n```ts\nconst ctx = new GraphicsContext().rect(0, 0, 100, 100).fill(0xff0000);\nconst g1 = new Graphics(ctx);\nconst g2 = new Graphics(ctx);\n```\n\n`GraphicsGeometry` was replaced by `GraphicsContext` in v8. There is no `.geometry` property.\n\n\n### [HIGH] Destroying a shared GraphicsContext unexpectedly\n\n```ts\nconst ctx = new GraphicsContext().rect(0, 0, 50, 50).fill(0xff0000);\nconst g1 = new Graphics(ctx);\nconst g2 = new Graphics(ctx);\n\ng1.destroy({ context: true }); \u002F\u002F also nullifies g2's context reference\n```\n\nDestroying a shared `GraphicsContext` does not destroy sharing instances but breaks them by nullifying their context reference. When passing a context via the constructor, `destroy()` with no args preserves the context; use `destroy({ context: false })` to be explicit. Only destroy the context when all sharing instances are done with it. A self-owned context (not passed via constructor) is still destroyed by `destroy()` with no args.\n\n\n### [HIGH] Clearing and redrawing Graphics every frame\n\nGraphics are designed to be stable, not dynamic. Calling `clear()` and redrawing every frame rebuilds GPU geometry each time. For dynamic visuals:\n\n- Use `Sprite` with pre-rendered textures and transform changes.\n- Use `cacheAsTexture(true)` for complex static graphics.\n- For real-time shape changes, consider `Mesh` with custom geometry updates.\n\nThis is the opposite of HTML Canvas 2D, where redrawing each frame is normal. PixiJS tessellates shapes into GPU triangles, so initial draw is expensive but subsequent renders are fast. Treat `Graphics` more like SVG elements than canvas draw calls.\n\n\n### [MEDIUM] Do not nest children inside a Graphics\n\n`Graphics` sets `allowChildren = false`. Adding children logs a deprecation warning and will be a hard error in a future version. Wrap multiple graphics alongside other leaves in a plain `Container`:\n\n```ts\nconst group = new Container();\ngroup.addChild(graphics, sprite);\n```\n\n\n## API Reference\n\n- [Graphics](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.Graphics.html.md)\n- [GraphicsOptions](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.GraphicsOptions.html.md)\n- [GraphicsContext](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.GraphicsContext.html.md)\n- [GraphicsPath](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.GraphicsPath.html.md)\n- [graphicsContextToSvg](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.graphicsContextToSvg.html.md)\n- [FillGradient](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.FillGradient.html.md)\n- [FillPattern](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.FillPattern.html.md)\n- [FillStyle](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.FillStyle.html.md)\n- [FillInput](https:\u002F\u002Fpixijs.download\u002Frelease\u002Fdocs\u002Fscene.FillInput.html.md)\n",{"name":5,"license":15,"description":7},"main","8859218955d9504cd18b59e7892100718039d3b4","data\u002Fskills\u002Fpixijs-pixijs-skills\u002Fpixijs-scene-graphics",1,"https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper","https:\u002F\u002Fgithub.com\u002Fom-scogo","SDE-1 @ Scogo ","2026-07-18 12:22:46",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add om-scogo\u002Fskillsh-scraper --skill pixijs-scene-graphics",{"tool":38,"command":39},"bunx","bunx skills add om-scogo\u002Fskillsh-scraper --skill pixijs-scene-graphics",{"tool":41,"command":42},"pnpm","pnpm dlx skills add om-scogo\u002Fskillsh-scraper --skill pixijs-scene-graphics","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fpixijs-pixijs-skills\u002Fpixijs-scene-graphics\u002FSkill.md",true,[46],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"metadata.json","REFERENCE","参考文档",469,"https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fpixijs-pixijs-skills\u002Fpixijs-scene-graphics\u002Fmetadata.json",[53,60,65,72,77,84],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7D6MC9FAAEV4CMNYX8W7JTG","arxiv-search","Search arXiv physics, math, and computer science preprints using natural language queries. Powered by Valyu semantic search.","https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fyorkeccak-scientific-skills\u002Farxiv-search\u002Fskills\u002Farxiv-search\u002FSKILL.md",[],[],{"skillNo":61,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M7D6M85CKKN87TA98VCQV4H7","https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fyorkeccak-scientific-skills\u002Farxiv-search\u002FSkill.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7D4ZTCS4DR3CE4JY06X84T2","working-with-legacy-code","Safely change and test untested codebases using Feathers' \"Working Effectively with Legacy Code\". Use when the user mentions \"legacy code\", \"no tests\", \"untested codebase\", \"how do I test this\", \"seams\", \"characterization tests\", \"golden master\", \"sprout method\", \"afraid to change this code\", \"monster method\", \"dependency breaking\", or \"inherited a messy codebase\". Also trigger when changing code without tests safely, getting a class under test when constructors, statics, or singletons block it, adding features to tangled modules, or planning incremental test coverage for an old codebase. Covers the legacy-code change algorithm, seams, characterization tests, sprout\u002Fwrap, and dependency-breaking techniques. For refactoring code that already has tests, see refactoring-patterns. For day-to-day code quality, see clean-code.","https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fwondelai-skills\u002Fworking-with-legacy-code\u002Fworking-with-legacy-code\u002FSKILL.md",[],[],{"skillNo":73,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M7D4ZHZKJD2RSNGAF63V14P4","https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fwondelai-skills\u002Fworking-with-legacy-code\u002FSkill.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M7D4ZB4CJBFW5JE67CPH2QRV","web-typography","Select, pair, and implement typefaces for web projects. Use when the user mentions \"font pairing\", \"which typeface\", \"line height\", \"responsive typography\", \"web font loading\", \"type hierarchy\", \"variable fonts\", \"FOUT\u002FFOIT\", \"typographic scale\", or \"the text is hard to read\". Also trigger when choosing between system fonts and web fonts, optimizing font-loading performance, or designing readable long-form content. Covers readability evaluation, CSS implementation, and performance optimization. For overall UI design systems, see refactoring-ui. For dramatic typographic experiences, see top-design.","https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fwondelai-skills\u002Fweb-typography\u002Fweb-typography\u002FSKILL.md",[],[],{"skillNo":85,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7D4Z4MVYVY3NMJ18BNV6WNA","https:\u002F\u002Fgithub.com\u002Fom-scogo\u002Fskillsh-scraper\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fwondelai-skills\u002Fweb-typography\u002FSkill.md",[],[]]