
p5.brush.js is a versatile library for the p5.js ecosystem, tailored for artists, designers, and hobbyists who wish to explore natural textures in generative art. This library extends the drawing capabilities of p5.js by introducing a rich set of tools that allow for the creation of dynamic and customizable brushes, vector-fields, and fill modes.
With p5.brush.js, you can easily configure and manage intricate drawing systems, inject life into your sketches with organic movements, and apply complex vector fields to control the flow and form of strokes. The library is designed with texture quality in mind, and may only be suitable for high-resolution artworks, not real-time interactive pieces.
Whether you're looking to simulate natural media, create patterned backgrounds, or design intricate particle systems, p5.brush.js offers the functionalities to turn your vision into reality. The API is straightforward and modular, providing both high-level functions for quick setup and in-depth customization options for advanced users.
Embrace the full potential of your creative coding projects with p5.brush.js, where every stroke is a brush with possibility.
Visit the library website here! (more examples soon)
To set up your project, add p5.min.js p5.brush.js to your HTML file. You can download the last version of the p5.brush.js library in the dist folder.
Place the script tags in the following order:
<script src="https://github.com/acamposuribe/p5.brush/raw/v.1.1.4/path_to/p5.min.js"></script>
<script src="https://github.com/acamposuribe/p5.brush/raw/v.1.1.4/path_to/p5.brush.js"></script>
Replace path_to with the actual path to the script in your project directory or the URL if you are using a CDN.
Alternatively, you can link to a p5.brush.js file hosted online. All versions are stored in a CDN (Content Delivery Network). You can find a history of these versions in the p5.js CDN. In this case you can change the link to:
<script src="https://cdn.jsdelivr.net/npm/p5.brush@1.1.1/dist/p5.brush.js"></script>
Install the npm package. p5.brush requires p5.js as a peer dependency.
npm install p5.brush --save
After that, import p5.brush functions to your sketch:
import * as brush from 'p5.brush'
If you are using p5 and p5.brush as modules, you will need to use instance mode. Read below.
By default, all p5.js functions are in the global namespace (i.e. bound to the window object), meaning you can call them simply ellipse(), fill(), etc. However, this might be inconvenient if you are mixing with other JS libraries (synchronously or asynchronously) or writing long programs of your own. p5.js currently supports a way around this problem called "instance mode". In instance mode, all p5 functions are bound up in a single variable instead of polluting your global namespace.
If you plan to use p5 instance mode, you need to load p5.brush in a specific way:
brush.instance() before the setup and draw functions, pointing to your sketch id and the p5 function argumentExample:
```javascript let sketch = function(p) { let x = 100; let y = 100;
// Register instance method here, sending your function arg p
brush.instance(p)
p.setup = function() {
// Important to create the canvas in WEBGL mode
p.createCanvas(700, 410, p.WEBGL);
// Don't forget to load the library after canvas is created
brush.load()
};
p.draw = function() {
p.background(0);
brush.fill("red", 75);
brush.rect(x, y, 50, 50);
};
};
let myp5 = new p5(sketch); ```
p5.brush.js enhances the p5.js framework with a set of tools that allow for sophisticated drawing and rendering techniques.
With p5.brush.js, your digital canvas becomes a playground for innovation and expression, where each tool is fine-tuned to complement your unique creative process.
.
p5.brush.js provides a comprehensive API for creating complex drawings and effects. Below are the categorized functions and classes available in the library.
| Section | Functions | Section | Functions | |
|---|---|---|---|---|
| Utility | brush.push() | Hatch Operations | brush.hatch() | |
| brush.pop() | brush.noHatch() | |||
| brush.rotate() | brush.setHatch() | |||
| brush.scale() | Geometry | brush.line() | ||
| brush.reDraw() | brush.flowLine() | |||
| brush.reBlend() | brush.beginStroke() | |||
| Vector-Fields | brush.field() | brush.segment() | ||
| brush.noField() | brush.endStroke() | |||
| brush.refreshField() | brush.spline() | |||
| brush.listFields() | brush.plot() | |||
| brush.addField() | brush.rect() | |||
| Brush Management | brush.box() | brush.circle() | ||
| brush.add() | brush.beginShape() | |||
| brush.clip() | brush.vertex() | |||
| brush.noClip() | brush.endShape() | |||
| Stroke Operations | brush.set() | brush.polygon() | ||
| brush.pick() | Configuration | brush.seed() | ||
| brush.stroke() | brush.load() | |||
| brush.noStroke() | brush.preload() | |||
| brush.strokeWeight() | brush.colorCache() | |||
| Fill Operations | brush.fill() | brush.scaleBrushes() | ||
| brush.noFill() | brush.remove() | |||
| brush.bleed() | brush.instance() | |||
| brush.fillTexture() | Classes | brush.Polygon() | ||
| brush.Plot() | ||||
| brush.Position() |
brush.push()Description: The push() function saves the current brush, hatch, and fill settings and transformations, while pop() restores these settings. Note that these functions are always used together.
brush.pop()
brush.rotate(angle)brush.scale(scale)brush.reDraw()Description: p5.brush uses several buffers and caches to make the drawing operations more performant. Use the reDraw() function if you want to force noBlend brushes to be drawn into the canvas. This function is designed to help maintain the correct draw order for the different strokes and shapes.
brush.reBlend()
Vector Fields allow for dynamic control over brush stroke behavior, enabling the creation of complex and fluid motion within sketches.
#### Basic vector-field functions
brush.field(name)name (String): The identifier for the vector field to be activated. This can be a name of one of the predefined fields or a custom field created with brush.addField().curved, truncated, zigzag, seabed, and waves. These, as well as any custom fields added, can be activated using this function.Usage: ```javascript // To activate the "waves" vector field brush.field("waves");
// To activate a custom vector field named "myCustomField" brush.field("myCustomField"); ``` Once a vector field is activated, it affects how the subsequent shapes are drawn, aligning them with its directional flow, unless stated otherwise in the documentation
brush.noField()$ claude mcp add p5.brush \
-- python -m otcore.mcp_server <graph>