> For the complete documentation index, see [llms.txt](https://viridian-games.gitbook.io/pixel-palette/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://viridian-games.gitbook.io/pixel-palette/core-components/brush-system.md).

# Brush System

**`IBrush` interface** — every tool implements `StrokeStart()`, `StrokeMove()`, `StrokeEnd()`. The input handler calls these as the user clicks, drags, and releases.

**`BrushSystem`** manages tool switching and brush size (1–16). It creates the right `IBrush` instance when you select a tool:

<table><thead><tr><th width="155">Tool</th><th width="257.333251953125">Class</th><th>What it does</th></tr></thead><tbody><tr><td><strong>Pen</strong></td><td><code>PixelPenBrush</code></td><td>Paints a square of pixels at brush size using the current pen color</td></tr><tr><td><strong>Eraser</strong></td><td><code>PixelPenBrush</code> (same class)</td><td>Same square, but writes transparent black (alpha=0) instead of the pen color. Detected by checking <code>brushSystem.CurrentBrushType == BrushType.Eraser</code></td></tr><tr><td><strong>Fill</strong></td><td><code>PixelFillBrush</code></td><td>Flood-fill from the clicked pixel using a radial queue (Burst-compiled). Replaces all connected pixels of the same color</td></tr><tr><td><strong>Color Picker</strong></td><td><code>ColorPickerBrush</code></td><td>Samples the pixel under the cursor and sets the pen color to match. No pixels are changed</td></tr><tr><td><strong>Select</strong></td><td><code>SelectionBrush</code></td><td>Creates a rectangular selection. Used by the selection manager for cut/copy/move/delete</td></tr></tbody></table>

**Pen & Eraser details:**

* `PaintPixelSquare(center, size)` — writes to the layer's `RawPixels` array directly, then uploads that region to the GPU via `Texture.SetPixels32()`
* Between strokes, draws Bresenham lines between consecutive pixels for smooth lines at any brush size
* **Quick shapes** — hold still for 1.5 seconds. The brush detects if the stroke looks like a line or an ellipse. Once detected, it switches to shape mode: the stroke restores original pixels, then redraws the shape preview (line, ellipse, or rectangle) from the anchor point. Toggle between ellipse/rectangle, or hold Shift for perfect aspect ratio

**Fill brush** uses a `NativeQueue` + `NativeList` for high-performance flood fill (Burst-compiled). It expands outward from the click point, replacing all connected pixels of the target color with the pen color. (Procreate anyone?)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://viridian-games.gitbook.io/pixel-palette/core-components/brush-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
