Unlock custom brushes, natural fill effects and intuitive hatching in p5.js
Better fill() implementation
Alejandro80a782dfc7cf
diff --git a/examples.js b/examples.jsindex cbda408..43e547c 100644--- a/examples.js+++ b/examples.js@@ -96,7 +96,7 @@ function setup () {*//*- */+// Set your brush name, color, and weight. There are 9 standard brushes to select from.// Select colors with HEX codes, arrays of [r,g,b] or namesbrush.set("marker","black",1)@@ -212,35 +212,32 @@ function setup () {brush.fill("#002185",120)brush.circle(150,100,50)- /*+ */++brush.set("2B","#9c2128",1)- let num_cols = 12- let num_rows = 8+ let num_cols = 10+ let num_rows = 3let col_size = (width - 40) / num_colslet row_size = (height - 40) / num_rowsbrush.noStroke()brush.field("curved")+ let bleed = 0.4for (let i = 0; i < num_rows; i++) {for (let j = 0; j < num_cols; j++) {brush.fill(random(palette),random(75,130))- brush.bleed(random(0.05,0.4),random(0,0.3))+ brush.bleed(bleed,random(0,0.3))brush.rect(20 + col_size * j, 20 + row_size * i, col_size, row_size)}}- */}-let guardar = true;-function draw() {---//brush.set(random(brush.box()),random(palette),random(0.8,1.1))//brush.flowLine(width*random(0,1),height*random(0,1),width*random(0.5,0.8),random(0,360))@@ -278,6 +275,9 @@ function draw() {}+let stopped = false;+function mouseClicked() {- noLoop();+ if (stopped) loop(), stopped = false;+ else noLoop(), stopped = true;}\ No newline at end of filediff --git a/p5.brush.js b/p5.brush.jsindex cacef5e..d42e340 100644--- a/p5.brush.js+++ b/p5.brush.js@@ -131,6 +131,11 @@if (!_isReady) loadSystem();}+ /**+ * Automatically load the library before draw()+ */+ p5.prototype.registerMethod('afterSetup', () => _ensureReady());+// =============================================================================// Section: Randomness and other auxiliary functions// =============================================================================@@ -422,6 +427,7 @@if (_color) this.currentColor = this.getPigment(_color), this.isBlending = true;else return}+// Checks if newColor is the same than the cadhedColor// If it is the same, we wait before applying the shader for color mixing// If it's NOT the same, we apply the shader and cache the new color@@ -461,7 +467,7 @@* Register methods after setup() and post draw() for belding last buffered color*/p5.prototype.registerMethod('afterSetup', () => Mix.blend(false, true));- p5.prototype.registerMethod('post', () => Mix.blend(false, true));+ //p5.prototype.registerMethod('post', () => Mix.blend(false, true));// =============================================================================// Section: FlowField@@ -1666,6 +1672,7 @@let _step = B.spacing() // get last spacinglet vertices = []let side = (max + min) * F.b;+ //let side = (max + min) * 0.2;let linepoint = new Position(_x,_y);let numsteps = Math.round(this.length/_step);for (let steps = 0; steps < numsteps; steps++) {@@ -1932,7 +1939,7 @@* EXPORTED*/function setBleed(_i, _texture = 0) {- F.b = _i > 0.5 ? 0.5 : _i;+ F.b = R.constrain(_i,0.1,0.6);F.t = _texture > 1 ? 1 : _texture;}@@ -2103,9 +2110,8 @@pol3.grow(0.1).layer(i, intensityThird, false);// Erase after each set of layers is drawnpol.erase(texture);-}+ }Mix.mask.pop();-}/**