Unlock custom brushes, natural fill effects and intuitive hatching in p5.js
Update README.md
Alejandroc0b1a7f252e0
diff --git a/README.md b/README.mdindex 4734acd..c134b5d 100644--- a/README.md+++ b/README.md@@ -68,55 +68,54 @@ With p5.brush.js, your digital canvas becomes a playground for innovation and exp5.brush.js provides a comprehensive API for creating complex drawings and effects. Below are the categorized functions and classes available in the library.### Table of Contents-- [Optional: Configuration](#optional-configuration)- [Vector-Fields](#vector-fields)+- [Optional: Configuration](#optional-configuration)++### Vector Fields-### Optional: Configuration--This section covers functions for initializing the drawing system, preloading required assets, and configuring system behavior. By default, the library works without executing these functions, but you might want to configure them to your liking.+Vector Fields allow for dynamic control over brush stroke behavior, enabling the creation of complex and fluid motion within sketches.-- `brush.config(objct = {})`- - **Description**: Sets custom configuration for the drawing system. It allows the overriding of the default randomness source by specifying a custom function.- - **Parameters**:- - `objct` (Object): Configuration object with properties. Default is `{}`.- - `objct.R` (Function): Optional custom random number generator function.- - **Example**: To use a deterministic random number generator, such as one from a generative art platform like fx(hash), you might configure your system as follows:+#### Advanced vector-field functions+- `brush.addField(name, generatorFunction)`+ - **Description**: Adds a custom vector field to the list of available fields. This advanced function requires a unique name for the field and a generator function that defines the behavior of the vector field over time.+ - **Parameters**:+ - `name` (String): A unique identifier for the vector field.+ - `generatorFunction` (Function): A function that generates the field values. It takes a time parameter `t`, loops through the vector field cells, assigns angular values based on custom logic, and returns the modified `FF.field` array.+ - **Default Fields**: The library includes several pre-defined vector fields. Users can add their own to extend the functionality.+ - **Usage**: To add a vector field that creates wave-like motions:```javascript- brush.config({- R: () => $fx.random()+ brush.addField("waves", function(t) {+ let sinrange = R.randInt(10,15) + 5 * R.sin(t);+ let cosrange = R.randInt(3,6) + 3 * R.cos(t);+ let baseAngle = R.randInt(20,35);+ for (let column = 0; column < FF.num_columns; column++) {+ for (let row = 0; row < FF.num_rows; row++) {+ let angle = R.sin(sinrange * column) * (baseAngle * R.cos(row * cosrange)) + R.randInt(-3,3);+ FF.field[column][row] = angle;+ }+ }+ return FF.field;});```- Replace `$fx.random()` with the actual function provided by the platform. By default, if `objct.R` is not provided, `p5.brush.js` uses p5's `random()` function, which allows for the use of `randomSeed()` to set the seed for randomness.-+ This `generatorFunction` uses sinusoidal functions to create a time-varying wave pattern within the vector field. Each cell's angle is calculated and assigned, resulting in a dynamic field that can be used to influence brush strokes.-- `brush.load(canvasID)`- - **Description**: Initializes the drawing system and sets up the environment. If `canvasID` is not provided, the current window is used as the rendering context. If you want to load the library on a custom p5.Graphics element (or instanced canvas), you can do it by executing this function.- - **Parameters**:- - `canvasID` (string): Optional ID of the buffer/canvas element. If false, uses the window's rendering context.-- `brush.preload()`- - **Description**: Preloads necessary assets or configurations for brushes. If you are using custom image tip brushes, you need to include this question within the preload() function of your p5 sketch.- - **Parameters**: None- - **Example**: To use a deterministic random number generator, such as one from a generative art platform like fx(hash), you might configure your system as follows:+- `brush.field(name)`+ - **Description**: Activates a named vector field. When a vector field is active, it influences the flow and direction of the brush strokes for shapes drawn thereafter. It is important to note that certain shapes may be exempt from this influence; such exceptions will be clearly documented in the API for each specific geometry.+ - **Parameters**:+ - `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()`.+ - **Default Fields**: The library comes with a set of built-in vector fields: `curved`, `truncated`, `zigzag`, `seabed`, and `waves`. These, as well as any custom fields added, can be activated using this function.+ - **Usage**:```javascript- // Your p5 preload function- function preload () {- brush.preload() // Add this if you want to use custom img brushes- }- ```+ // To activate the "waves" vector field+ brush.field("waves");-- `brush.colorCache(bool = true)`- - **Description**: Enables or disables color caching for WebGL shaders. Color caching can increase performance but may produce less accurate textures when the same color is used repeatedly. It's set to _true_ by default- - **Parameters**:- - `bool` (boolean): Set to true to enable caching, or false to disable it.---### Vector Fields+ // 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-Operations for creating and managing vector fields.-- `addField(name, funct)`- - Adds a new vector field with a unique name and generator function.- `selectField(a)`- Activates a specific vector field by name.- `disableField()`@@ -160,6 +159,47 @@ Procedures for applying hatching patterns to areas.*(Insert Hatching Operations related functions here)*+### Optional: Configuration++This section covers functions for initializing the drawing system, preloading required assets, and configuring system behavior. By default, the library works without executing these functions, but you might want to configure them to your liking.++- `brush.config(objct = {})`+ - **Description**: Sets custom configuration for the drawing system. It allows the overriding of the default randomness source by specifying a custom function.+ - **Parameters**:+ - `objct` (Object): Configuration object with properties. Default is `{}`.+ - `objct.R` (Function): Optional custom random number generator function.+ - **Example**: To use a deterministic random number generator, such as one from a generative art platform like fx(hash), you might configure your system as follows:+ ```javascript+ brush.config({+ R: () => $fx.random()+ });+ ```+ Replace `$fx.random()` with the actual function provided by the platform. By default, if `objct.R` is not provided, `p5.brush.js` uses p5's `random()` function, which allows for the use of `randomSeed()` to set the seed for randomness.+++- `brush.load(canvasID)`+ - **Description**: Initializes the drawing system and sets up the environment. If `canvasID` is not provided, the current window is used as the rendering context. If you want to load the library on a custom p5.Graphics element (or instanced canvas), you can do it by executing this function.+ - **Parameters**:+ - `canvasID` (string): Optional ID of the buffer/canvas element. If false, uses the window's rendering context.+++- `brush.preload()`+ - **Description**: Preloads necessary assets or configurations for brushes. If you are using custom image tip brushes, you need to include this question within the preload() function of your p5 sketch.+ - **Parameters**: None+ - **Example**: To use a deterministic random number generator, such as one from a generative art platform like fx(hash), you might configure your system as follows:+ ```javascript+ // Your p5 preload function+ function preload () {+ brush.preload() // Add this if you want to use custom img brushes+ }+ ```+++- `brush.colorCache(bool = true)`+ - **Description**: Enables or disables color caching for WebGL shaders. Color caching can increase performance but may produce less accurate textures when the same color is used repeatedly. It's set to _true_ by default+ - **Parameters**:+ - `bool` (boolean): Set to true to enable caching, or false to disable it.+### Exposed ClassesClasses that are exposed for creating and manipulating objects.