Unlock custom brushes, natural fill effects and intuitive hatching in p5.js
Imrpovements to documentation
Alejandro32dedf17e1e8
diff --git a/example.html b/index.htmlsimilarity index 100%rename from example.htmlrename to index.htmldiff --git a/p5.brush.js b/p5.brush.jsindex 003cb60..d9c6980 100644--- a/p5.brush.js+++ b/p5.brush.js@@ -948,7 +948,7 @@},/**- * Draws a shape with a flowing brush stroke.+ * Draws a predefined shape/plot with a flowing brush stroke.* @param {Object} p - An object representing the shape to draw.* @param {number} x - The x-coordinate of the starting position to draw the shape.* @param {number} y - The y-coordinate of the starting position to draw the shape.@@ -1571,7 +1571,7 @@* @param {number} y - The y-coordinate of the rectangle.* @param {number} w - The width of the rectangle.* @param {number} h - The height of the rectangle.- * @param {boolean} [mode=CORNER] - If true, the rectangle is drawn centered at (x, y).+ * @param {boolean} [mode=CORNER] - If CENTER, the rectangle is drawn centered at (x, y).*/function drawRectangle(x,y,w,h,mode = CORNER) {_ensureReady();@@ -1843,7 +1843,7 @@/*** Starts recording vertices for a custom shape. Optionally, a curvature can be defined.- * @param {number} [curvature] - Defines the curvature for the vertices being recorded (optional).+ * @param {number} [curvature] - From 0 to 1. Defines the curvature for the vertices being recorded (optional).* EXPORTED*/function _beginShape(curvature) {@@ -1864,7 +1864,7 @@/*** Finishes recording vertices for a custom shape and either closes it or leaves it open.- * It also triggers the drawing of the shape if the brush state is active.+ * It also triggers the drawing of the shape with the active stroke(), fill() and hatch() states.* @param {string} [a] - An optional argument to close the shape if set to CLOSE.*/function _endShape(a) {@@ -1903,7 +1903,7 @@* @param {number} length - The length of the segment.* @param {number} pressure - The pressure at the start of the segment, affecting properties like width.*/- function _move(angle, length, pressure) {+ function _segment(angle, length, pressure) {_strokeArray.addSegment(angle, length, pressure); // Add the new segment to the Plot}@@ -2370,7 +2370,7 @@// GEOMETRY Drawing Functionsexports.line = B.line; // Draws a line.exports.flowLine = B.flowLine; // Draws a line that follows the vector field.- exports.flowShape = B.flowShape; // Draws a shape that follows the vector field.+ exports.plot = B.flowShape; // Draws a shape that follows the vector field.exports.rect = drawRectangle; // Draws a rectangle.exports.circle = drawCircle; // Draws a circle.exports.polygon = drawPolygon; // Draws a polygon.@@ -2381,7 +2381,7 @@exports.endShape = _endShape; // Finishes recording vertices and draws the shape.// HandStroke - simulates a hand-drawn strokeexports.beginStroke = _beginStroke; // Begins a hand-drawn stroke.- exports.nextStroke = _move; // Moves to a specified point in the hand-drawn stroke.+ exports.segment = _segment; // Moves to a specified point in the hand-drawn stroke.exports.endStroke = _endStroke; // Ends a hand-drawn stroke.// HATCHING Operationsdiff --git a/sketch.js b/sketch.jsindex c33e7a8..5a1f8d4 100644--- a/sketch.js+++ b/sketch.js@@ -22,22 +22,14 @@ const C = {}};// SET CANVAS SIZE: width, height, pixelDensity, html_id for the canvas+// Here I'm working with mm units, so I want a big pixelDensity for high-res.C.setSize(250,280,10,'mainCanvas')function windowResized () {C.resize();}-let palette = ["#7b4800", "#002185", "#003c32", "#fcd300", "#ff2702", "#6b9404"]---//////////////////////////////////////////////////-// p5.brush-// YOU CAN SEED THE BRUSHBOX RANDOM NUMBER GENERATOR for determinism-brush.config({- R: function () { return random() },-})// YOU CAN CREATE YOU OWN BRUSHES@@ -77,6 +69,9 @@ function preload() {brush.preload();}++let palette = ["#7b4800", "#002185", "#003c32", "#fcd300", "#ff2702", "#6b9404"]+function setup () {C.createCanvas()@@ -86,14 +81,14 @@ function setup () {translate(-width/2,-height/2)// STANDARD PALETTE TEST- /*+let i = 0for (let b of brush.box()) {brush.set(b,random(palette),1)brush.line(30,30+i*10,220,30+i*10)i++}- */+/*@@ -212,7 +207,7 @@ function setup () {brush.fill("#002185",120)brush.circle(150,100,50)- */+brush.set("2B","#9c2128",1)@@ -238,6 +233,8 @@ function setup () {}}+ */+}function draw() {