Skip to content

Unlock custom brushes, natural fill effects and intuitive hatching in p5.js

docs: clean up custom tip description, move standalone note to its own callout

acamposuribee1aaf8855f68
diff --git a/README.md b/README.md
index c4e0251..6323012 100644
--- a/README.md
+++ b/README.md
@@ -307,7 +307,6 @@ Functions for managing brush behaviors and properties.
---
- `brush.add(name, params)` — **[Design your brush visually with the Brush Maker ↗](https://acamposuribe.github.io/p5.brush/tools/brush-maker.html)**
-- `brush.addField(name, generatorFunction, options)` — **[Design your field visually with the Flow Field Generator ↗](https://acamposuribe.github.io/p5.brush/tools/flowfield-maker.html)**
- **Description**: Creates a new brush with your own settings. Once added, you use it just like any built-in brush with `brush.set("myBrush", color, size)`.
- **Parameters**:
- `name` (String): A name for your brush — pick anything you like.
@@ -326,7 +325,7 @@ Functions for managing brush behaviors and properties.
- These simple/custom pressure modes include a subtle amount of per-stroke variation automatically, so repeated strokes feel less mechanical.
- Advanced option for power users: use the library's built-in Gaussian pressure profile explicitly with an object like `{ mode: "gaussian", curve: [0.15, 0.2], min_max: [1.1, 0.9] }`.
`curve` adjusts the wobble and asymmetry of the pressure envelope, while `min_max` sets the mapped pressure range. This is the same family of pressure logic used by the built-in brushes.
- - `tip`: Only for `"custom"` type. A function `(_m) => { ... }` that draws the tip shape into a small buffer. The coordinate space is 100×100 units with the origin at the centre — dark fills become opaque, light/white becomes transparent. In the **p5 build** `_m` is a `p5.Graphics` object, so any p5 drawing function works. In the **standalone build** `_m` is a minimal 2D-canvas-backed surface that supports the same method names (`rect`, `circle`, `ellipse`, `line`, `beginShape`/`vertex`/`endShape`, `fill`, `noFill`, `stroke`, `noStroke`, `strokeWeight`, `push`, `pop`, `translate`, `scale`, `rotate`) but colors must be a grayscale number `(0–255)` or a CSS color string — not a `p5.Color` — and `rotate()` always takes radians regardless of `brush.angleMode()`.
+ - `tip`: Only for `"custom"` type. A function `(_m) => { ... }` that draws the tip shape using p5 drawing commands. The coordinate space is 100×100 units with the origin at the centre — dark fills become opaque, light/white becomes transparent.
- `image`: Only for `"image"` type. An object with a `src` property pointing to your image file: `{ src: "./tip.jpg" }`.
- `rotate`: How the tip rotates as it moves. `"none"` keeps it fixed, `"natural"` follows the stroke direction, `"random"` spins randomly.
- `markerTip`: Only for `"marker"`, `"custom"`, and `"image"` types. Set to `false` to disable the extra soft tip buildup those brushes add at the start and end of each stroke. Defaults to `true`.
@@ -357,23 +356,6 @@ Functions for managing brush behaviors and properties.
brush.line(100, 100, 400, 100);
}
- // Custom tip brush — no await needed, just call brush.add() normally
- brush.add("diamond", {
- type: "custom",
- weight: 5,
- scatter: 0.08,
- opacity: 23,
- spacing: 0.6,
- pressure: [0.5, 1.5, 0.5], // thin → thick → thin
- tip: (_m) => {
- // Use radians for rotate — works in both p5 and standalone builds
- _m.rotate(Math.PI / 4);
- _m.rect(-1.5, -1.5, 3, 3);
- },
- rotate: "natural",
- markerTip: false,
- });
-
// Advanced: explicitly use the built-in Gaussian pressure mode
brush.add("soft-pencil", {
type: "default",
@@ -393,6 +375,22 @@ Functions for managing brush behaviors and properties.
```
**Image brushes only**: `brush.add()` returns a Promise when `type` is `"image"` — you must `await` it so the image finishes loading before you start drawing. For this to work, your `setup()` function must be declared `async`. For all other brush types, no `await` is needed.
+ **Custom tips in the standalone build**: `_m` is a native 2D canvas surface, not a `p5.Graphics`. Use native-compatible drawing calls — the method names are the same (`rect`, `circle`, `fill`, `rotate`, …), but colors must be a grayscale number or a CSS string (no `p5.Color`), and `rotate()` always takes radians. The example below works in both builds:
+ ```javascript
+ brush.add("diamond", {
+ type: "custom",
+ weight: 5, scatter: 0.08, opacity: 23, spacing: 0.6,
+ pressure: [0.5, 1.5, 0.5],
+ tip: (_m) => {
+ _m.rotate(Math.PI / 4); // radians — safe in both builds
+ _m.rect(-1.5, -1.5, 3, 3);
+ },
+ rotate: "natural",
+ markerTip: false,
+ });
+ ```
+ For the full list of available methods and constraints see [docs/standalone.md](docs/standalone.md#custom-tip-brushes).
+
---
- `brush.clip(clippingRegion)`