Skip to content

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

New functions: push(), pop(), and rotate()

Alejandro76ad428e3f37
diff --git a/README.md b/README.md
index 77ca9ff..cf54a13 100644
--- a/README.md
+++ b/README.md
@@ -72,29 +72,59 @@ p5.brush.js provides a comprehensive API for creating complex drawings and effec
### Table of Functions
-| Section | Functions | | Section | Functions |
-|-----------------------------------------|---------------------|---|--------------------------------------------|---------------------|
-| [Vector-Fields](#vector-fields) | brush.field() | | [Geometry](#geometry) | brush.point() |
-| | brush.noField() | | | brush.line() |
-| | brush.refreshField()| | | brush.flowLine() |
-| | brush.listFields() | | | brush.beginStroke() |
-| | brush.addField() | | | brush.segment() |
-| [Brush Management](#brush-management) | brush.scale() | | | brush.endStroke() |
-| | brush.box() | | | brush.spline() |
-| | brush.add() | | | brush.plot() |
-| | brush.clip() | | | brush.rect() |
-| | brush.noClip() | | | brush.circle() |
-| [Stroke Operations](#stroke-operations) | brush.set() | | | brush.beginShape() |
-| | brush.pick() | | | brush.vertex() |
-| | brush.stroke() | | | brush.endShape() |
-| | brush.noStroke() | | | brush.polygon() |
-| | brush.strokeWeight()| | [Configuration](#optional-configuration) | brush.config() |
-| [Fill Operations](#fill-operations) | brush.fill() | | | brush.load() |
-| | brush.noFill() | | | brush.preload() |
-| | brush.bleed() | | | brush.colorCache() |
-| [Hatch Operations](#hatch-operations) | brush.hatch() | | [Classes](#exposed-classes) | brush.Polygon() |
-| | brush.noHatch() | | | brush.Plot() |
-| | brush.setHatch() | | | brush.Position() |
+| Section | Functions | | Section | Functions |
+|--------------------------------------------|---------------------|---|--------------------------------------------|---------------------|
+| [Utility](#utility-functions) | brush.push() | | [Hatch Operations](#hatch-operations) | brush.hatch() |
+| | brush.pop() | | | brush.noHatch() |
+| | brush.rotate() | | | brush.setHatch() |
+| | brush.reDraw() | | [Geometry](#geometry) | brush.point() |
+| | brush.reBlend() | | | brush.line() |
+| [Vector-Fields](#vector-fields) | brush.field() | | | brush.flowLine() |
+| | brush.noField() | | | brush.beginStroke() |
+| | brush.refreshField()| | | brush.segment() |
+| | brush.listFields() | | | brush.endStroke() |
+| | brush.addField() | | | brush.spline() |
+| [Brush Management](#brush-management) | brush.scale() | | | brush.plot() |
+| | brush.box() | | | brush.rect() |
+| | brush.add() | | | brush.circle() |
+| | brush.clip() | | | brush.beginShape() |
+| | brush.noClip() | | | brush.vertex() |
+| [Stroke Operations](#stroke-operations) | brush.set() | | | brush.endShape() |
+| | brush.pick() | | | brush.polygon() |
+| | brush.stroke() | | [Configuration](#optional-configuration) | brush.config() |
+| | brush.noStroke() | | | brush.load() |
+| | brush.strokeWeight()| | | brush.preload() |
+| [Fill Operations](#fill-operations) | brush.fill() | | | brush.colorCache() |
+| | brush.noFill() | | [Classes](#exposed-classes) | brush.Polygon() |
+| | brush.bleed() | | | brush.Plot() |
+| | | | | brush.Position() |
+
+---
+
+<sub>[back to table](#table-of-functions)</sub>
+### Utility Functions
+
+---
+
+- `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()`
+ - **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.rotate(angle)`
+ - **Description**: Rotates following shapes by the amount specified by the angle parameter. This function accounts for angleMode(), so angles can be entered in either RADIANS or DEGREES. Objects are always rotated around their relative position to the origin and positive numbers rotate objects in an anti-clockwise direction. Transformations apply to everything that happens after and subsequent calls to the function accumulate the effect. This function can be further controlled by brush.push() and brush.pop().
+
+---
+
+- `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()`
+ - **Description**: p5.brush uses several buffers and caches to make the drawing operations more performant. Use the reDraw() function if you want to force Blend brushes to be drawn into the canvas. This function is designed to help maintain the correct draw order for the different strokes and shapes.
+
---
diff --git a/index.html b/index.html
index afd75b4..68675de 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,8 @@
<head>
<title>p5.brush.js Example</title>
<script src="./dependencies/p5.min.js"></script>
- <script src="./p5.brush.min.js"></script>
+ <script src="./dependencies/spectral.min.js"></script>
+ <script src="./p5.brush.js"></script>
<link rel="stylesheet" href="./style.css">
</head>
<body>
diff --git a/p5.brush.js b/p5.brush.js
index ba02238..1d49a4d 100644
--- a/p5.brush.js
+++ b/p5.brush.js
@@ -266,25 +266,42 @@
R.s[i] = Math.sin(radians);
}
this.isPrecalculationDone = true;
- }
+ },
+
+ /**
+ * Changes angles to degrees and between 0-360
+ */
+ toDegrees: (a) => (((angleMode() === "radians") ? a * 180 / Math.PI : a) % 360 + 360) % 360,
}
// Perform the precalculation of trigonometric values for the R object
R.preCalculation();
/**
- * Captures the current translation values from the renderer's transformation matrix.
- *
- * Assumes that the renderer's transformation matrix (`uMVMatrix`) is a 4x4 matrix
- * where the translation components are in the 13th (index 12) and 14th (index 13) positions.
- *
- * @returns {number[]} An array containing the x (horizontal) and y (vertical) translation values.
+ * Object to perform matrix translation and rotation operations
*/
- let _matrix = [0,0];
- const _trans = function () {
- // Access the renderer's current model-view matrix and extract the translation components
- _matrix = [_r._renderer.uMVMatrix.mat4[12],_r._renderer.uMVMatrix.mat4[13]]
- // Return the translation components as a two-element array
- return _matrix;
+ const Matrix = {
+ translation: [0, 0],
+ rotation: 0,
+ /**
+ * Captures the desired rotation.
+ */
+ rotate (a) {
+ Matrix.rotation = R.toDegrees(a)
+ },
+ /**
+ * Captures the current translation values from the renderer's transformation matrix.
+ *
+ * Assumes that the renderer's transformation matrix (`uMVMatrix`) is a 4x4 matrix
+ * where the translation components are in the 13th (index 12) and 14th (index 13) positions.
+ *
+ * @returns {number[]} An array containing the x (horizontal) and y (vertical) translation values.
+ */
+ trans () {
+ // Access the renderer's current model-view matrix and extract the translation components
+ this.translation = [_r._renderer.uMVMatrix.mat4[12],_r._renderer.uMVMatrix.mat4[13]];
+ // Return the translation components as a two-element array
+ return this.translation
+ }
}
/**
@@ -344,6 +361,83 @@
let angleDegrees = angleRadians * (180 / Math.PI);
return (angleDegrees % 360 + 360) % 360;
}
+
+ /**
+ * Object that saves the current p5.brush state for push and pop operations
+ */
+ const _saveState = {
+ field: {},
+ stroke: {},
+ hatch: {},
+ fill: {},
+ others: {},
+ }
+
+ /**
+ * Saves current state to object
+ */
+ function _push () {
+ // Field
+ _saveState.field.isActive = FF.isActive;
+ _saveState.field.current = FF.current;
+
+ // Stroke
+ _saveState.stroke.isActive = B.isActive;
+ _saveState.stroke.brush = B.name;
+ _saveState.stroke.color = B.c;
+ _saveState.stroke.weight = B.w;
+ _saveState.stroke.globalScale = _gScale;
+ _saveState.stroke.clip = B.cr;
+
+ // Hatch
+ _saveState.hatch.isActive = H.isActive;
+ _saveState.hatch.hatchingParams = H.hatchingParams;
+ _saveState.hatch.hatchingBrush = H.hatchingBrush;
+
+ // Fill
+ _saveState.fill.isActive = F.isActive;
+ _saveState.fill.color = F.color;
+ _saveState.fill.opacity = F.opacity;
+ _saveState.fill.bleed_strength = F.bleed_strength;
+ _saveState.fill.texture_strength = F.texture_strength;
+ _saveState.fill.border_strength = F.border_strength;
+
+ // Rotate
+ _saveState.others.rotate = Matrix.rotation;
+ }
+
+ /**
+ * Restores previous state from object
+ */
+ function _pop() {
+ // Field
+ FF.isActive = _saveState.field.isActive;
+ FF.current = _saveState.field.current;
+
+ // Stroke
+ B.isActive = _saveState.stroke.isActive;
+ B.name = _saveState.stroke.brush;
+ B.c = _saveState.stroke.color;
+ B.w = _saveState.stroke.weight;
+ _gScale = _saveState.stroke.globalScale;
+ B.cr = _saveState.stroke.clip;
+
+ // Hatch
+ H.isActive = _saveState.hatch.isActive;
+ H.hatchingParams = _saveState.hatch.hatchingParams;
+ H.hatchingBrush = _saveState.hatch.hatchingBrush;
+
+ // Fill
+ F.isActive = _saveState.fill.isActive;
+ F.color = _saveState.fill.color;
+ F.opacity = _saveState.fill.opacity;
+ F.bleed_strength = _saveState.fill.bleed_strength;
+ F.texture_strength = _saveState.fill.texture_strength;
+ F.border_strength = _saveState.fill.border_strength;
+
+ // Rotate
+ Matrix.rotation = _saveState.others.rotate;
+ }
// =============================================================================
@@ -439,12 +533,22 @@
reDraw() {
_r.push();
// Copy info from noBlend buffer
- _r.translate(-_trans()[0],-_trans()[1])
+ _r.translate(-Matrix.trans()[0],-Matrix.trans()[1])
_r.image(Mix.noBlend, -_r.width/2, -_r.height/2)
Mix.noBlend.clear()
_r.pop();
},
+ /**
+ * This function forces marker-brushes and fills to be updated into the canvas
+ */
+ reBlend() {
+ _push()
+ B.set("marker","white",1)
+ B.line(-10,-10,-5,-5)
+ _pop();
+ },
+
/**
* There are two parallel blender instances: one uses the 2D mask, the other the WEBGL mask
* 2D Canvas API mask: for basi geometry (circles, polygons, etc), which is much faster with the 2D API
@@ -477,7 +581,7 @@
}
else {
_r.push();
- _r.translate(-_trans()[0],-_trans()[1])
+ _r.translate(-Matrix.trans()[0],-Matrix.trans()[1])
_r.image(this.noBlend,-_r.width/2, -_r.height/2)
this.noBlend.clear()
_r.pop();
@@ -493,7 +597,7 @@
if (newColor.toString() !== this.currentColor.toString() || _isLast || !this.isCaching) {
_r.push();
// Copy info from noBlend buffer
- _r.translate(-_trans()[0],-_trans()[1])
+ _r.translate(-Matrix.trans()[0],-Matrix.trans()[1])
_r.image(this.noBlend,-_r.width/2, -_r.height/2)
this.noBlend.clear()
// Use the blend shader for rendering
@@ -857,8 +961,8 @@
update (x,y) {
this.x = x , this.y = y;
if (FF.isActive) {
- this.x_offset = this.x - FF.left_x + _trans()[0];
- this.y_offset = this.y - FF.top_y + _trans()[1];
+ this.x_offset = this.x - FF.left_x + Matrix.trans()[0];
+ this.y_offset = this.y - FF.top_y + Matrix.trans()[1];
this.column_index = Math.round(this.x_offset / FF.R);
this.row_index = Math.round(this.y_offset / FF.R);
}
@@ -885,7 +989,7 @@
*/
isInCanvas() {
let w = 0.55 * _r.width, h = 0.55 * _r.height;
- return (this.x >= -w - _trans()[0] && this.x <= w - _trans()[0]) && (this.y >= -h - _trans()[1] && this.y <= h - _trans()[1])
+ return (this.x >= -w - Matrix.trans()[0] && this.x <= w - Matrix.trans()[0]) && (this.y >= -h - Matrix.trans()[1] && this.y <= h - Matrix.trans()[1])
}
/**
@@ -1127,9 +1231,8 @@
*/
flowLine(x,y,length,dir) {
_ensureReady();
- if (angleMode() === "radians") dir = dir * 180 / Math.PI;
B.initializeDrawingState(x, y, length, true, false);
- B.draw(dir, false);
+ B.draw(R.toDegrees(dir), false);
},
/**
@@ -1220,11 +1323,12 @@
this.c = _r.color(this.c);
// Select mask buffer for blend mode
this.mask = this.p.blend ? ((this.p.type === "image") ? Mix.mask2 : Mix.mask) : Mix.noBlend;
- _trans()
+ Matrix.trans()
// Set the blender
this.mask.push();
this.mask.noStroke();
- (this.p.type === "image") ? this.mask.translate(_matrix[0],_matrix[1]) : this.mask.translate(_matrix[0] + _r.width/2,_matrix[1] + _r.height/2);
+ (this.p.type === "image") ? this.mask.translate(Matrix.translation[0],Matrix.translation[1]) : this.mask.translate(Matrix.translation[0] + _r.width/2,Matrix.translation[1] + _r.height/2);
+ this.mask.rotate(-Matrix.rotation)
if (this.p.blend) {
if (this.p.type !== "image") Mix.blend(this.c);
else Mix.blend(this.c,false,true)
@@ -1530,7 +1634,7 @@
* @param {number} weight - The weight (size) to set for the brush.
* EXPORTED
*/
- function setHatch(brush, color, weight = 1) {
+ function setHatch(brush, color = "black", weight = 1) {
H.hatchingBrush = [brush, color, weight]
}
@@ -1569,8 +1673,8 @@
// Change state if hatch has been set to different params than stroke
if (H.hatchingBrush) B.set(H.hatchingBrush[0],H.hatchingBrush[1],H.hatchingBrush[2])
- // Check angleMode for calculations and transform to degrees
- angle = (((angleMode() === "radians") ? angle * 180 / Math.PI : angle) + 3 * 360) % 180
+ // Transform to degrees and between 0-180
+ angle = R.toDegrees(angle) % 180;
// Calculate the bounding area of the provided polygons
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
@@ -1827,14 +1931,12 @@
* @param {boolean} _degrees - Whether the angle is in degrees.
*/
addSegment (_a = 0,_length = 0,_pres = 1,_degrees = false) {
- // Convert angle to degrees if necessary
- if (angleMode() === "radians" && !_degrees) _a = _a * 180 / Math.PI
// Remove the last angle if the angles array is not empty
if (this.angles.length > 0) {
this.angles.splice(-1)
}
- // Normalize the angle between 0 and 360 degrees
- _a = (_a + 360) % 360;
+ // Convert to degrees and normalize between 0 and 360 degrees
+ _a = R.toDegrees(_a);
// Store the angle, pressure, and segment length
this.angles.push(_a);
this.pres.push(_pres);
@@ -1853,10 +1955,9 @@
*/
endPlot (_a = 0, _pres = 1, _degrees = false) {
// Convert angle to degrees if necessary
- if (angleMode() === "radians" && !_degrees) _a = _a * 180 / Math.PI
// Replace the last angle with the final angle
this.angles.splice(-1)
- this.angles.push(_a);
+ this.angles.push(R.toDegrees(_a));
// Store the final pressure
this.pres.push(_pres);
}
@@ -1866,8 +1967,7 @@
* @param {number} _a - The angle to rotate the plot.
*/
rotate (_a) {
- if (angleMode() === "radians") _a = _a * 180 / Math.PI;
- this.dir = _a;
+ this.dir = R.toDegrees(_a);
}
/**
@@ -2385,11 +2485,12 @@
const texture = tex * 3;
// Perform initial setup only once
- _trans();
+ Matrix.trans();
Mix.blend(color,false,false,true)
Mix.mask.push();
Mix.mask.noStroke();
- Mix.mask.translate(_matrix[0] + _r.width/2, _matrix[1] + _r.height/2);
+ Mix.mask.translate(Matrix.translation[0] + _r.width/2, Matrix.translation[1] + _r.height/2);
+ Mix.mask.rotate(Matrix.rotation)
let pol = this.grow()
let pol2 = pol.grow().grow(0.9);
@@ -2541,6 +2642,10 @@
exports.preload = preloadBrushAssets; // Preloads custom tips for the library.
exports.colorCache = enableCacheBlending; // Enables/disables cache color blending for improved performance
exports.reDraw = Mix.reDraw;
+ exports.reBlend = Mix.reBlend;
+ exports.push = _push;
+ exports.pop = _pop;
+ exports.rotate = Matrix.rotate;
// FLOWFIELD Management
exports.addField = addField; // Adds a new vector field.
@@ -2557,7 +2662,7 @@
exports.pick = B.setBrush; // Selects a brush to use.
exports.clip = B.clip; // Clips brushes with a rectangle.
exports.noClip = B.noClip;
- exports.tip = drawTip; // Draw tip of the brush with a custom pressure
+ exports.point = drawTip; // Draw tip of the brush with a custom pressure
// STROKE Properties
exports.stroke = B.setColor; // Activates and sets the stroke color.
diff --git a/p5.brush.min.js b/p5.brush.min.js
index b6acbc6..5885fcd 100644
--- a/p5.brush.min.js
+++ b/p5.brush.min.js
@@ -1,2 +1,2 @@
/*! p5.brush.js v1.0.3 2023 - by Alejandro Campos - MIT License */
-!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).brush={})}(this,(function(t){"use strict";let e,i=!1;function s(t=!1){i=!0,e=t||window.self,c.load(),m.create(),f(e.width/250)}function r(){i||s()}p5.prototype.registerMethod("afterSetup",(()=>r()));const o={source:()=>random(),random(t=0,e=1){return 1===arguments.length?this.map(this.source(),0,1,0,t):this.map(this.source(),0,1,t,e)},randInt(t,e){return Math.floor(this.random(t,e))},weightedRand(t){let e,i,s=[];for(e in t)for(i=0;i<10*t[e];i++)s.push(e);return s[Math.floor(this.source()*s.length)]},map(t,e,i,s,r,o=!1){let n=s+(t-e)/(i-e)*(r-s);return o?s<r?this.constrain(n,s,r):this.constrain(n,r,s):n},constrain:(t,e,i)=>Math.max(Math.min(t,i),e),cos(t){return this.c[Math.floor((t%360+360)%360*4)]},sin(t){return this.s[Math.floor((t%360+360)%360*4)]},isPrecalculationDone:!1,preCalculation(){if(this.isPrecalculationDone)return;const t=1440,e=2*Math.PI/t;this.c=new Float64Array(t),this.s=new Float64Array(t);for(let i=0;i<t;i++){const t=i*e;o.c[i]=Math.cos(t),o.s[i]=Math.sin(t)}this.isPrecalculationDone=!0}};o.preCalculation();let n=[0,0];const a=function(){return n=[e._renderer.uMVMatrix.mat4[12],e._renderer.uMVMatrix.mat4[13]],n};function h(t,e,i,s,r=!1){let o=t.x,n=t.y,a=e.x,h=e.y,l=i.x,c=i.y,d=s.x,m=s.y;if(o===a&&n===h||l===d&&c===m)return!1;let p=a-o,f=h-n,u=d-l,g=m-c,v=g*p-u*f;if(0===v)return!1;let x=(u*(n-c)-g*(o-l))/v,w=(p*(n-c)-f*(o-l))/v;return!(!r&&(w<0||w>1))&&{x:o+x*p,y:n+x*f}}function l(t,e,i,s){return(Math.atan2(-(s-e),i-t)*(180/Math.PI)%360+360)%360}const c={loaded:!1,isBlending:!1,isCaching:!0,currentColor:new Float32Array(3),load(){this.mask=createGraphics(e.width,e.height),this.mask.pixelDensity(e.pixelDensity()),this.mask.clear(),this.mask.noSmooth(),this.mask.angleMode(DEGREES),t.mask=this.mask,c.loaded||(this.frag=this.frag.replace('#include "spectral.glsl"',this.glsl())),this.shader=e.createShader(this.vert,this.frag),c.loaded=!0,this.noBlend=createGraphics(e.width,e.height),this.noBlend.pixelDensity(e.pixelDensity()),this.noBlend.noSmooth(),this.noBlend.clear(),this.noBlend.angleMode(DEGREES),this.mask2=createGraphics(e.width,e.height,WEBGL),this.mask2.pixelDensity(e.pixelDensity()),this.mask2.clear(),this.mask2.angleMode(DEGREES)},getPigment(t){let e=t.levels,i=new Float32Array(3);return i[0]=e[0]/255,i[1]=e[1]/255,i[2]=e[2]/255,i},reDraw(){e.push(),e.translate(-a()[0],-a()[1]),e.image(c.noBlend,-e.width/2,-e.height/2),c.noBlend.clear(),e.pop()},color1:new Float32Array(3),color2:new Float32Array(3),blending1:!1,blending2:!1,blend(t=!1,i=!1,s=!1,r=!1){if(this.isBlending=s?this.blending1:this.blending2,this.currentColor=s?this.color1:this.color2,!this.isBlending){if(!t)return e.push(),e.translate(-a()[0],-a()[1]),e.image(this.noBlend,-e.width/2,-e.height/2),this.noBlend.clear(),void e.pop();this.currentColor=this.getPigment(t),s?(this.blending1=!0,this.color1=this.currentColor):(this.blending2=!0,this.color2=this.currentColor)}if((t?this.getPigment(t):this.currentColor).toString()!==this.currentColor.toString()||i||!this.isCaching){e.push(),e.translate(-a()[0],-a()[1]),e.image(this.noBlend,-e.width/2,-e.height/2),this.noBlend.clear(),e.shader(this.shader),this.shader.setUniform("addColor",this.currentColor),this.shader.setUniform("source",e._renderer),this.shader.setUniform("active",r),this.shader.setUniform("random",[o.random(),o.random(),o.random()]);let n=s?this.mask2:this.mask;this.shader.setUniform("mask",n),e.fill(0,0,0,0),e.noStroke(),e.rect(-e.width/2,-e.height/2,e.width,e.height),e.pop(),n.clear(),i||(this.currentColor=this.getPigment(t),s?this.color1=this.currentColor:this.color2=this.currentColor)}i&&(this.isBlending=!1,s?this.blending1=this.isBlending:this.blending2=this.isBlending)},vert:"precision highp float;attribute vec3 aPosition;attribute vec2 aTexCoord;uniform mat4 uModelViewMatrix,uProjectionMatrix;varying vec2 vVertTexCoord;void main(){gl_Position=uProjectionMatrix*uModelViewMatrix*vec4(aPosition,1);vVertTexCoord=aTexCoord;}",frag:'precision highp float;varying vec2 vVertTexCoord;uniform sampler2D source,mask;uniform vec4 addColor;uniform vec3 random;uniform bool active;\n #include "spectral.glsl"\n float v(vec2 v,vec2 x,float y,out vec2 i){vec2 a=vec2(v.x+v.y*.5,v.y),m=floor(a),d=fract(a);float z=step(d.y,d.x);vec2 r=vec2(z,1.-z),f=m+r,e=m+1.,s=vec2(m.x-m.y*.5,m.y),k=vec2(s.x+r.x-r.y*.5,s.y+r.y),l=vec2(s.x+.5,s.y+1.),g=v-s,o=v-k,t=v-l;vec3 u,c,C,D;if(any(greaterThan(x,vec2(0)))){C=vec3(s.x,k.x,l);D=vec3(s.y,k.y,l.y);if(x.x>0.)C=mod(vec3(s.x,k.x,l),x.x);if(x.y>0.)D=mod(vec3(s.y,k.y,l.y),x.y);u=floor(C+.5*D+.5);c=floor(D+.5);}else u=vec3(m.x,f.x,e),c=vec3(m.y,f.y,e.y);vec3 b=mod(u,289.);b=mod((b*51.+2.)*b+c,289.);b=mod((b*34.+10.)*b,289.);vec3 h=b*.07482+y,E=cos(h),w=sin(h);vec2 A=vec2(E.x,w),B=vec2(E.y,w.y),F=vec2(E.z,w.z);vec3 G=.8-vec3(dot(g,g),dot(o,o),dot(t,t));G=max(G,0.);vec3 H=G*G,I=H*H,J=vec3(dot(A,g),dot(B,o),dot(F,t)),K=H*G,L=-8.*K*J;i=10.9*(I.x*A+L.x*g+(I.y*B+L.y*o)+(I.z*F+L.z*t));return 10.9*dot(I,J);}vec4 v(vec3 v,float f){return vec4(mix(v,vec3(dot(vec3(.299,.587,.114),v)),f),1);}float f(vec2 v,float x,float y,float f){return fract(sin(dot(v,vec2(x,y)))*f);}void main(){vec4 s=texture2D(mask,vVertTexCoord);if(s.x>0.){vec2 m=vec2(12.9898,78.233),k=vec2(7.9898,58.233),d=vec2(17.9898,3.233);float x=f(vVertTexCoord,m.x,m.y,43358.5453)*2.-1.,y=f(vVertTexCoord,k.x,k.y,43213.5453)*2.-1.,l=f(vVertTexCoord,d.x,d.y,33358.5453)*2.-1.;const vec2 z=vec2(0);vec2 o;vec4 b;if(active){float a=v(vVertTexCoord*10.,z,10.*random.x,o),c=v(vVertTexCoord*10.,z,10.*random.y,o),t=v(vVertTexCoord*10.,z,10.*random.z,o),w=.25+.25*v(vVertTexCoord*8.,z,3.*random.x,o);b=vec4(v(addColor.xyz,w).xyz+vec3(a,c,t)*.03,1);}else b=vec4(addColor.xyz,1);if(s.w>.7){float r=.5*(s.w-.7);b=b*(1.-r)-vec4(.5)*r;}vec3 a=spectral_mix(texture2D(source,vVertTexCoord).xyz,b.xyz,.9*s.w);gl_FragColor=vec4(a+.01*vec3(x,y,l),1);}}',glsl:()=>"float spectral_uncompand(float s){return s<.04045?s/12.92:pow((s+.055)/1.055,2.4);}float spectral_compand(float s){return s<.0031308?s*12.92:1.055*pow(s,1./2.4)-.055;}vec3 spectral_srgb_to_linear(vec3 s){return vec3(spectral_uncompand(s[0]),spectral_uncompand(s[1]),spectral_uncompand(s[2]));}vec3 spectral_linear_to_srgb(vec3 s){return clamp(vec3(spectral_compand(s[0]),spectral_compand(s[1]),spectral_compand(s[2])),0.,1.);}void spectral_upsampling(vec3 e,out float m,out float s,out float f,out float r,out float x,out float v,out float z){m=min(e.x,min(e.y,e.z));e-=m;s=min(e.y,e.z);f=min(e.x,e.z);r=min(e.x,e.y);x=min(max(0.,e.x-e.z),max(0.,e.x-e.y));v=min(max(0.,e.y-e.z),max(0.,e.y-e.x));z=min(max(0.,e.z-e.y),max(0.,e.z-e.x));}void spectral_linear_to_reflectance(vec3 s,inout float f[38]){float e,o,m,x,v,w,z;spectral_upsampling(s,e,o,m,x,v,w,z);f[0]=max(1e-4,e+o*.96853629+m*.51567122+x*.02055257+v*.03147571+w*.49108579+z*.97901834);f[1]=max(1e-4,e+o*.96855103+m*.5401552+x*.02059936+v*.03146636+w*.46944057+z*.97901649);f[2]=max(1e-4,e+o*.96859338+m*.62645502+x*.02062723+v*.03140624+w*.4016578+z*.97901118);f[3]=max(1e-4,e+o*.96877345+m*.75595012+x*.02073387+v*.03119611+w*.2449042+z*.97892146);f[4]=max(1e-4,e+o*.96942204+m*.92826996+x*.02114202+v*.03053888+w*.0682688+z*.97858555);f[5]=max(1e-4,e+o*.97143709+m*.97223624+x*.02233154+v*.02856855+w*.02732883+z*.97743705);f[6]=max(1e-4,e+o*.97541862+m*.98616174+x*.02556857+v*.02459485+w*.013606+z*.97428075);f[7]=max(1e-4,e+o*.98074186+m*.98955255+x*.03330189+v*.0192952+w*.01000187+z*.96663223);f[8]=max(1e-4,e+o*.98580992+m*.98676237+x*.05185294+v*.01423112+w*.01284127+z*.94822893);f[9]=max(1e-4,e+o*.98971194+m*.97312575+x*.10087639+v*.01033111+w*.02636635+z*.89937713);f[10]=max(1e-4,e+o*.99238027+m*.91944277+x*.24000413+v*.00765876+w*.07058713+z*.76070164);f[11]=max(1e-4,e+o*.99409844+m*.32564851+x*.53589066+v*.00593693+w*.70421692+z*.4642044);f[12]=max(1e-4,e+o*.995172+m*.13820628+x*.79874659+v*.00485616+w*.85473994+z*.20123039);f[13]=max(1e-4,e+o*.99576545+m*.05015143+x*.91186529+v*.00426186+w*.95081565+z*.08808402);f[14]=max(1e-4,e+o*.99593552+m*.02912336+x*.95399623+v*.00409039+w*.9717037+z*.04592894);f[15]=max(1e-4,e+o*.99564041+m*.02421691+x*.97137099+v*.00438375+w*.97651888+z*.02860373);f[16]=max(1e-4,e+o*.99464769+m*.02660696+x*.97939505+v*.00537525+w*.97429245+z*.02060067);f[17]=max(1e-4,e+o*.99229579+m*.03407586+x*.98345207+v*.00772962+w*.97012917+z*.01656701);f[18]=max(1e-4,e+o*.98638762+m*.04835936+x*.98553736+v*.0136612+w*.9425863+z*.01451549);f[19]=max(1e-4,e+o*.96829712+m*.0001172+x*.98648905+v*.03181352+w*.99989207+z*.01357964);f[20]=max(1e-4,e+o*.89228016+m*8.554e-5+x*.98674535+v*.10791525+w*.99989891+z*.01331243);f[21]=max(1e-4,e+o*.53740239+m*.85267882+x*.98657555+v*.46249516+w*.13823139+z*.01347661);f[22]=max(1e-4,e+o*.15360445+m*.93188793+x*.98611877+v*.84604333+w*.06968113+z*.01387181);f[23]=max(1e-4,e+o*.05705719+m*.94810268+x*.98559942+v*.94275572+w*.05628787+z*.01435472);f[24]=max(1e-4,e+o*.03126539+m*.94200977+x*.98507063+v*.96860996+w*.06111561+z*.01479836);f[25]=max(1e-4,e+o*.02205445+m*.91478045+x*.98460039+v*.97783966+w*.08987709+z*.0151525);f[26]=max(1e-4,e+o*.01802271+m*.87065445+x*.98425301+v*.98187757+w*.13656016+z*.01540513);f[27]=max(1e-4,e+o*.0161346+m*.78827548+x*.98403909+v*.98377315+w*.22169624+z*.01557233);f[28]=max(1e-4,e+o*.01520947+m*.65738359+x*.98388535+v*.98470202+w*.32176956+z*.0156571);f[29]=max(1e-4,e+o*.01475977+m*.59909403+x*.98376116+v*.98515481+w*.36157329+z*.01571025);f[30]=max(1e-4,e+o*.01454263+m*.56817268+x*.98368246+v*.98537114+w*.4836192+z*.01571916);f[31]=max(1e-4,e+o*.01444459+m*.54031997+x*.98365023+v*.98546685+w*.46488579+z*.01572133);f[32]=max(1e-4,e+o*.01439897+m*.52110241+x*.98361309+v*.98550011+w*.47440306+z*.01572502);f[33]=max(1e-4,e+o*.0143762+m*.51041094+x*.98357259+v*.98551031+w*.4857699+z*.01571717);f[34]=max(1e-4,e+o*.01436343+m*.50526577+x*.98353856+v*.98550741+w*.49267971+z*.01571905);f[35]=max(1e-4,e+o*.01435687+m*.5025508+x*.98351247+v*.98551323+w*.49625685+z*.01571059);f[36]=max(1e-4,e+o*.0143537+m*.50126452+x*.98350101+v*.98551563+w*.49807754+z*.01569728);f[37]=max(1e-4,e+o*.01435408+m*.50083021+x*.98350852+v*.98551547+w*.49889859+z*.0157002);}vec3 spectral_xyz_to_srgb(vec3 e){mat3 f;f[0]=vec3(3.24306333,-1.53837619,-.49893282);f[1]=vec3(-.96896309,1.87542451,.04154303);f[2]=vec3(.05568392,-.20417438,1.05799454);float s=dot(f[0],e),m=dot(f[1],e),z=dot(f[2],e);return spectral_linear_to_srgb(vec3(s,m,z));}vec3 spectral_reflectance_to_xyz(float f[38]){vec3 e=vec3(0);e+=f[0]*vec3(6.469e-5,1.84e-6,.00030502);e+=f[1]*vec3(.00021941,6.21e-6,.00103681);e+=f[2]*vec3(.00112057,3.101e-5,.00531314);e+=f[3]*vec3(.00376661,.00010475,.01795439);e+=f[4]*vec3(.01188055,.00035364,.05707758);e+=f[5]*vec3(.02328644,.00095147,.11365162);e+=f[6]*vec3(.03455942,.00228226,.17335873);e+=f[7]*vec3(.03722379,.00420733,.19620658);e+=f[8]*vec3(.03241838,.0066888,.18608237);e+=f[9]*vec3(.02123321,.0098884,.13995048);e+=f[10]*vec3(.01049099,.01524945,.08917453);e+=f[11]*vec3(.00329584,.02141831,.04789621);e+=f[12]*vec3(.00050704,.03342293,.02814563);e+=f[13]*vec3(.00094867,.05131001,.01613766);e+=f[14]*vec3(.00627372,.07040208,.0077591);e+=f[15]*vec3(.01686462,.08783871,.00429615);e+=f[16]*vec3(.02868965,.09424905,.00200551);e+=f[17]*vec3(.04267481,.09795667,.00086147);e+=f[18]*vec3(.05625475,.09415219,.00036904);e+=f[19]*vec3(.0694704,.08678102,.00019143);e+=f[20]*vec3(.08305315,.07885653,.00014956);e+=f[21]*vec3(.0861261,.0635267,9.231e-5);e+=f[22]*vec3(.09046614,.05374142,6.813e-5);e+=f[23]*vec3(.08500387,.04264606,2.883e-5);e+=f[24]*vec3(.07090667,.03161735,1.577e-5);e+=f[25]*vec3(.05062889,.02088521,3.94e-6);e+=f[26]*vec3(.03547396,.01386011,1.58e-6);e+=f[27]*vec3(.02146821,.00810264,0);e+=f[28]*vec3(.01251646,.0046301,0);e+=f[29]*vec3(.00680458,.00249138,0);e+=f[30]*vec3(.00346457,.0012593,0);e+=f[31]*vec3(.00149761,.00054165,0);e+=f[32]*vec3(.0007697,.00027795,0);e+=f[33]*vec3(.00040737,.00014711,0);e+=f[34]*vec3(.00016901,6.103e-5,0);e+=f[35]*vec3(9.522e-5,3.439e-5,0);e+=f[36]*vec3(4.903e-5,1.771e-5,0);e+=f[37]*vec3(2e-5,7.22e-6,0);return e;}float spectral_linear_to_concentration(float v,float m,float s){float z=m*pow(s,2.);return z/(v*pow(1.-s,2.)+z);}vec3 spectral_mix(vec3 s,vec3 f,float e){vec3 v=spectral_srgb_to_linear(s),m=spectral_srgb_to_linear(f);float z[38],o[38];spectral_linear_to_reflectance(v,z);spectral_linear_to_reflectance(m,o);float x=spectral_reflectance_to_xyz(z)[1],w=spectral_reflectance_to_xyz(o)[1];e=spectral_linear_to_concentration(x,w,e);float r[38];for(int c=0;c<38;c++){float y=(1.-e)*(pow(1.-z[c],2.)/(2.*z[c]))+e*(pow(1.-o[c],2.)/(2.*o[c]));r[c]=1.+y-sqrt(pow(y,2.)+2.*y);}return spectral_xyz_to_srgb(spectral_reflectance_to_xyz(r));}vec4 spectral_mix(vec4 s,vec4 e,float z){return vec4(spectral_mix(s.xyz,e.xyz,z),mix(s.w,e.w,z));}"};function d(t,e){r(),m.list.set(t,{gen:e}),m.current=t,m.refresh()}p5.prototype.registerMethod("afterSetup",(()=>c.blend(!1,!0))),p5.prototype.registerMethod("afterSetup",(()=>c.blend(!1,!0,!0))),p5.prototype.registerMethod("post",(()=>c.blend(!1,!0))),p5.prototype.registerMethod("post",(()=>c.blend(!1,!0,!0)));const m={isActive:!1,list:new Map,current:"",step_length:()=>Math.min(e.width,e.height)/1e3,create(){this.R=.01*e.width,this.left_x=-1*e.width,this.top_y=-1*e.height,this.num_columns=Math.round(2*e.width/this.R),this.num_rows=Math.round(2*e.height/this.R),this.addStandard()},flow_field(){return this.list.get(this.current).field},refresh(t=0){this.list.get(this.current).field=this.list.get(this.current).gen(t,this.genField())},genField(){let t=new Array(this.num_columns);for(let e=0;e<this.num_columns;e++)t[e]=new Float64Array(this.num_rows);return t},addStandard(){d("curved",(function(t,e){let i=o.randInt(-25,-15);o.randInt(0,100)%2==0&&(i*=-1);for(let s=0;s<m.num_columns;s++)for(let r=0;r<m.num_rows;r++){let n=noise(.02*s+.03*t,.02*r+.03*t),a=o.map(n,0,1,-i,i);e[s][r]=3*a}return e})),d("truncated",(function(t,e){let i=o.randInt(-25,-15)+5*o.sin(t);o.randInt(0,100)%2==0&&(i*=-1);let s=o.randInt(5,10);for(let t=0;t<m.num_columns;t++)for(let r=0;r<m.num_rows;r++){let n=noise(.02*t,.02*r),a=Math.round(o.map(n,0,1,-i,i)/s)*s;e[t][r]=4*a}return e})),d("zigzag",(function(t,e){let i=o.randInt(-30,-15)+Math.abs(44*o.sin(t));o.randInt(0,100)%2==0&&(i*=-1);let s=i,r=0;for(let t=0;t<m.num_columns;t++){for(let i=0;i<m.num_rows;i++)e[t][i]=r,r+=s,s*=-1;r+=s,s*=-1}return e})),d("waves",(function(t,e){let i=o.randInt(10,15)+5*o.sin(t),s=o.randInt(3,6)+3*o.cos(t),r=o.randInt(20,35);for(let t=0;t<m.num_columns;t++)for(let n=0;n<m.num_rows;n++){let a=o.sin(i*t)*(r*o.cos(n*s))+o.randInt(-3,3);e[t][n]=a}return e})),d("seabed",(function(t,e){let i=o.random(.4,.8),s=o.randInt(18,26);for(let r=0;r<m.num_columns;r++)for(let n=0;n<m.num_rows;n++){let a=o.randInt(15,20),h=s*o.sin(i*n*r+a);e[r][n]=1.1*h*o.cos(t)}return e}))}};class p{constructor(t,e){this.update(t,e),this.plotted=0}update(t,e){this.x=t,this.y=e,m.isActive&&(this.x_offset=this.x-m.left_x+a()[0],this.y_offset=this.y-m.top_y+a()[1],this.column_index=Math.round(this.x_offset/m.R),this.row_index=Math.round(this.y_offset/m.R))}reset(){this.plotted=0}isIn(){return m.isActive?this.column_index>=0&&this.row_index>=0&&this.column_index<m.num_columns&&this.row_index<m.num_rows:this.isInCanvas()}isInCanvas(){let t=.55*e.width,i=.55*e.height;return this.x>=-t-a()[0]&&this.x<=t-a()[0]&&this.y>=-i-a()[1]&&this.y<=i-a()[1]}angle(){return this.isIn()&&m.isActive?m.flow_field()[this.column_index][this.row_index]:0}moveTo(t,e,i=m.step_length(),s=!0){if(this.isIn()){let r,n;s||(r=o.cos(-e),n=o.sin(-e));for(let a=0;a<t/i;a++){if(s){let t=this.angle();r=o.cos(t-e),n=o.sin(t-e)}let t=i*r,a=i*n;this.plotted+=i,this.update(this.x+t,this.y+a)}}else this.plotted+=i}plotTo(t,e,i,s){if(this.isIn()){const r=1/s;for(let s=0;s<e/i;s++){let e=this.angle(),s=t.angle(this.plotted),n=i*o.cos(e-s),a=i*o.sin(e-s);this.plotted+=i*r,this.update(this.x+n,this.y+a)}}else this.plotted+=i/scale}}function f(t){for(let e of D){let i=g.list.get(e[0]).param;i.weight*=t,i.vibration*=t,i.spacing*=t}u=t}let u=1;const g={isActive:!0,list:new Map,c:"#000000",w:1,cr:null,name:"HB",add:(t,e)=>{const i="marker"===e.type||"custom"===e.type||"image"===e.type;"image"===e.type&&(v.add(e.image.src),e.tip=()=>g.mask.image(v.tips.get(g.p.image.src),-g.p.weight/2,-g.p.weight/2,g.p.weight,g.p.weight)),e.blend=!!(i&&!1!==e.blend||e.blend),g.list.set(t,{param:e,colors:[],buffers:[]})},set(t,e,i=1){g.name=t,g.c=e,g.w=i,g.isActive=!0},setBrush(t){g.name=t},setColor(t,e,i){arguments.length>0&&(g.c=arguments.length<2?t:[t,e,i]),g.isActive=!0},setWeight(t){g.w=t},clip(t){g.cr=t},noClip(){g.cr=null},line(t,e,i,s){r();let o=dist(t,e,i,s);if(0==o)return;g.initializeDrawingState(t,e,o,!1,!1);let n=l(t,e,i,s);g.draw(n,!1)},flowLine(t,e,i,s){r(),"radians"===angleMode()&&(s=180*s/Math.PI),g.initializeDrawingState(t,e,i,!0,!1),g.draw(s,!1)},flowShape(t,e,i,s){r(),g.initializeDrawingState(e,i,t.length,!0,t),g.draw(s,!0)},spacing(){return this.p=this.list.get(this.name).param,this.p.spacing*this.w},initializeDrawingState(t,e,i,s,r){this.position=new p(t,e),this.length=i,this.flow=s,this.plot=r,r&&r.calcIndex(0)},draw(t,e){e||(this.dir=t),this.pushState();const i=this.spacing(),s=e?Math.round(this.length*t/i):Math.round(this.length/i);for(let r=0;r<s;r++)this.tip(),e?this.position.plotTo(this.plot,i,i,t):this.position.moveTo(i,t,i,this.flow);this.popState()},drawTip(t){this.pushState(!0),this.tip(t),this.popState(!0)},pushState(t=!1){if(this.p=this.list.get(this.name).param,!t){this.a="custom"!==this.p.pressure.type?o.random(-1,1):0,this.b="custom"!==this.p.pressure.type?o.random(1,1.5):0,this.cp="custom"!==this.p.pressure.type?o.random(3,3.5):o.random(-.2,.2);const[t,e]=this.p.pressure.min_max;this.min=t,this.max=e}this.c=e.color(this.c),this.mask=this.p.blend?"image"===this.p.type?c.mask2:c.mask:c.noBlend,a(),this.mask.push(),this.mask.noStroke(),"image"===this.p.type?this.mask.translate(n[0],n[1]):this.mask.translate(n[0]+e.width/2,n[1]+e.height/2),this.p.blend&&("image"!==this.p.type?c.blend(this.c):c.blend(this.c,!1,!0),t||this.markerTip())},popState(t=!1){this.p.blend&&!t&&this.markerTip(),this.mask.pop()},tip(t=!1){let e=t||this.calculatePressure(),i=this.calculateAlpha(e);if(this.applyColor(i),this.isInsideClippingArea())switch(this.p.type){case"spray":this.drawSpray(e);break;case"marker":this.drawMarker(e);break;case"custom":case"image":this.drawCustomOrImage(e,i);break;default:this.drawDefault(e)}},calculatePressure(){return this.plot?this.simPressure()*this.plot.pressure(this.position.plotted):this.simPressure()},simPressure(){return"custom"===this.p.pressure.type?o.map(this.p.pressure.curve(this.position.plotted/this.length)+this.cp,0,1,this.min,this.max,!0):this.gauss()},gauss(t=.5+g.p.pressure.curve[0]*g.a,e=1-g.p.pressure.curve[1]*g.b,i=g.cp,s=g.min,r=g.max){return o.map(1/(1+Math.pow(Math.abs((this.position.plotted-t*this.length)/(e*this.length/2)),2*i)),0,1,s,r)},calculateAlpha(t){return Math.floor(this.p.opacity*Math.pow(t,"marker"===this.p.type?.7:1.5))},applyColor(t){this.p.blend?this.mask.fill(255,0,0,t/2):(this.c.setAlpha(t),this.mask.fill(this.c))},isInsideClippingArea(){return!g.cr||this.position.x>=g.cr[0]&&this.position.x<=g.cr[2]&&this.position.y>=g.cr[1]&&this.position.y<=g.cr[3]},drawSpray(t){let e=this.w*this.p.vibration*t+this.w*randomGaussian()*this.p.vibration/3,i=this.p.weight*o.random(.9,1.1);const s=this.p.quality/t;for(let t=0;t<s;t++){let t=o.random(.9,1.1),s=t*e*o.random(-1,1),r=o.random(-1,1),n=Math.pow(t*e,2),a=Math.sqrt(n-Math.pow(s,2));this.mask.circle(this.position.x+s,this.position.y+r*a,i)}},drawMarker(t,e=!0){let i=e?this.w*this.p.vibration:0,s=e?i*o.random(-1,1):0,r=e?i*o.random(-1,1):0;this.mask.circle(this.position.x+s,this.position.y+r,this.w*this.p.weight*t)},drawCustomOrImage(t,e,i=!0){this.mask.push();let s=i?this.w*this.p.vibration:0,r=i?s*o.random(-1,1):0,n=i?s*o.random(-1,1):0;this.mask.translate(this.position.x+r,this.position.y+n),this.adjustSizeAndRotation(this.w*t,e),this.p.tip(),this.mask.pop()},drawDefault(t){let e=this.w*this.p.vibration*(this.p.definition+(1-this.p.definition)*randomGaussian()*this.gauss(.5,.9,5,.2,1.2)/t);o.random(0,this.p.quality)>.4&&this.mask.circle(this.position.x+.7*e*o.random(-1,1),this.position.y+e*o.random(-1,1),t*this.p.weight*this.w*o.random(.85,1.15))},adjustSizeAndRotation(t,e){if(this.mask.scale(t),"image"===this.p.type&&(this.p.blend?this.mask.tint(255,0,0,e/2):this.mask.tint(this.mask.red(this.c),this.mask.green(this.c),this.mask.blue(this.c),e)),"random"===this.p.rotate)this.mask.rotate(o.randInt(0,360));else if("natural"===this.p.rotate){let t=(this.plot?-this.plot.angle(this.position.plotted):-this.dir)+(this.flow?this.position.angle():0);t=this.plot?-this.plot.angle(this.position.plotted):-this.dir,this.mask.rotate(t)}},markerTip(){if(this.isInsideClippingArea()){let t=this.calculatePressure(),e=this.calculateAlpha(t);if(this.mask.fill(255,0,0,e/1.5),"marker"===g.p.type)for(let e=1;e<5;e++)this.drawMarker(t*e/5,!1);else if("custom"===g.p.type||"image"===g.p.type)for(let i=1;i<5;i++)this.drawCustomOrImage(t*i/5,e,!1)}}};const v={tips:new Map,add(t){this.tips.set(t,!1)},imageToWhite(t){t.loadPixels();for(let e=0;e<4*t.width*t.height;e+=4){let i=(t.pixels[e]+t.pixels[e+1]+t.pixels[e+2])/3;t.pixels[e]=t.pixels[e+1]=t.pixels[e+2]=255,t.pixels[e+3]=255-i}t.updatePixels()},load(){if(0===this.tips.size)return console.log("There are no custom tips to load !");for(let t of this.tips.keys()){let e=loadImage(t,(()=>v.imageToWhite(e)));this.tips.set(t,e)}}};function x(t=5,e=45,i={rand:!1,continuous:!1,gradient:!1}){w.isActive=!0,w.hatchingParams=[t,e,i]}const w={isActive:!1,hatchingParams:[5,45,{}],hatchingBrush:!1,hatch(t){let e=w.hatchingParams[0],i=w.hatchingParams[1],s=w.hatchingParams[2],r=g.c,n=g.name,a=g.w,h=g.isActive;w.hatchingBrush&&g.set(w.hatchingBrush[0],w.hatchingBrush[1],w.hatchingBrush[2]),i=(("radians"===angleMode()?180*i/Math.PI:i)+1080)%180;let l=1/0,c=-1/0,d=1/0,m=-1/0,p=t=>{for(let e of t.a)l=e[0]<l?e[0]:l,c=e[0]>c?e[0]:c,d=e[1]<d?e[1]:d,m=e[1]>m?e[1]:m};Array.isArray(t)||(t=[t]);for(let e of t)p(e);let f=new y([[l,d],[c,d],[c,m],[l,m]]),u=i<=90&&i>=0?d:m,v=s.gradient?map(s.gradient,0,1,1,1.1,!0):1,x=[],_=0,k=e,z=t=>({point1:{x:l+k*t*o.cos(90-i),y:u+k*t*o.sin(90-i)},point2:{x:l+k*t*o.cos(90-i)+o.cos(-i),y:u+k*t*o.sin(90-i)+o.sin(-i)}});for(;f.intersect(z(_)).length>0;){let e=[];for(let i of t)e.push(i.intersect(z(_)));x[_]=e.flat().sort(((t,e)=>t.x===e.x?t.y-e.y:t.x-e.x)),k*=v,_++}let b=[];for(let t of x)void 0!==t[0]&&b.push(t);let M=s.rand||0;for(let t=0;t<b.length;t++){let i=b[t],r=t>0&&s.continuous;for(let s=0;s<i.length-1;s+=2)0!==M&&(i[s].x+=M*e*o.random(-1,1),i[s].y+=M*e*o.random(-1,1),i[s+1].x+=M*e*o.random(-1,1),i[s+1].y+=M*e*o.random(-1,1)),g.line(i[s].x,i[s].y,i[s+1].x,i[s+1].y),r&&g.line(b[t-1][1].x,b[t-1][1].y,i[s].x,i[s].y)}g.set(n,r,a),g.isActive=h}};class y{constructor(t){this.a=t,this.vertices=t.map((t=>({x:t[0],y:t[1]}))),this.sides=this.vertices.map(((t,e,i)=>[t,i[(e+1)%i.length]]))}intersect(t){let e=`${t.point1.x},${t.point1.y}-${t.point2.x},${t.point2.y}`;if(this._intersectionCache&&this._intersectionCache[e])return this._intersectionCache[e];let i=[];for(let e of this.sides){let s=h(t.point1,t.point2,e[0],e[1]);!1!==s&&i.push(s)}return this._intersectionCache||(this._intersectionCache={}),this._intersectionCache[e]=i,i}draw(t=!1,e,i){let s=g.isActive;if(t&&g.set(t,e,i),g.isActive){r();for(let t of this.sides)g.line(t[0].x,t[0].y,t[1].x,t[1].y)}g.isActive=s}fill(t=!1,e,i,s,o){let n=I.isActive;t&&(S(t,e),P(i,s,o)),I.isActive&&(r(),I.fill(this)),I.isActive=n}hatch(t=!1,e,i){let s=w.isActive;t&&x(t,e,i),w.isActive&&(r(),w.hatch(this)),w.isActive=s}}class _{constructor(t){this.segments=[],this.angles=[],this.pres=[],this.type=t,this.dir=0,this.calcIndex(0),this.pol=!1}addSegment(t=0,e=0,i=1,s=!1){"radians"!==angleMode()||s||(t=180*t/Math.PI),this.angles.length>0&&this.angles.splice(-1),t=(t+360)%360,this.angles.push(t),this.pres.push(i),this.segments.push(e),this.length=this.segments.reduce(((t,e)=>t+e),0),this.angles.push(t)}endPlot(t=0,e=1,i=!1){"radians"!==angleMode()||i||(t=180*t/Math.PI),this.angles.splice(-1),this.angles.push(t),this.pres.push(e)}rotate(t){"radians"===angleMode()&&(t=180*t/Math.PI),this.dir=t}pressure(t){return t>this.length?this.pres[this.pres.length-1]:this.curving(this.pres,t)}angle(t){return t>this.length?this.angles[this.angles.length-1]:(this.calcIndex(t),"curve"===this.type?this.curving(this.angles,t)+this.dir:this.angles[this.index]+this.dir)}curving(t,e){let i=t[this.index],s=t[this.index+1];return void 0===s&&(s=i),Math.abs(s-i)>180&&(s>i?s=-(360-s):i=-(360-i)),o.map(e-this.suma,0,this.segments[this.index],i,s,!0)}calcIndex(t){this.index=-1,this.suma=0;let e=0;for(;e<=t;)this.suma=e,e+=this.segments[this.index+1],this.index++}genPol(t,e,i=1,s=!1){r();let o=0,n=9999;for(let t of this.segments)t*=i,0!==t&&(o=Math.max(o,t),n=Math.min(n,t));let a=g.spacing(),h=[],l=(o+n)*(s?.03:I.isAnimated?.25:I.b),c=new p(t,e),d=Math.round(this.length/a);for(let t=0;t<d;t++)c.x&&(h[Math.floor(c.plotted/l)]=[c.x,c.y]),c.plotTo(this,a,a,1);return this.calcIndex(0),new y(h)}draw(t,e,i){g.isActive&&(r(),this.origin&&(t=this.origin[0],e=this.origin[1],i=1),g.flowShape(this,t,e,i))}fill(t,e,i){I.isActive&&(r(),this.origin&&(t=this.origin[0],e=this.origin[1],i=1),this.pol||(this.pol=this.genPol(t,e,i)),this.pol.fill())}hatch(t,e,i){w.isActive&&(r(),this.origin&&(t=this.origin[0],e=this.origin[1],i=1),this.pol||(this.pol=this.genPol(t,e,i,!0)),this.pol.hatch())}}let k,z=!1;function b(t){k=t,z=[]}function M(t,e,i){z.push([t,e,i])}function C(t){t===CLOSE&&z.push(z[0]);let e=A(z,k);(I.isActive||w.isActive)&&(e.fill(),e.hatch()),g.isActive&&e.draw(),z=!1}function A(t,e=.5){let i=new _(0===e?"segments":"curve");if(t&&t.length>0){i.origin=t[0];let s=0;for(let r=0;r<t.length-1;r++)if(e>0&&r<t.length-2){let n=t[r],a=t[r+1],c=t[r+2],d=dist(n[0],n[1],a[0],a[1]),m=dist(a[0],a[1],c[0],c[1]),p=l(n[0],n[1],a[0],a[1]),f=l(a[0],a[1],c[0],c[1]),u=e*Math.min(Math.min(d,m),.5*Math.min(d,m)),g=Math.max(d,m),v=d-u,x=m-u;if(Math.floor(p)===Math.floor(f))i.addSegment(p,v,n[2],!0),i.addSegment(f,m,a[2],!0);else{let e={x:a[0]-u*o.cos(-p),y:a[1]-u*o.sin(-p)},l={x:e.x+g*o.cos(90-p),y:e.y+g*o.sin(90-p)},c={x:a[0]+u*o.cos(-f),y:a[1]+u*o.sin(-f)},d=h(e,l,c,{x:c.x+g*o.cos(90-f),y:c.y+g*o.sin(90-f)},!0),m=dist(e.x,e.y,d.x,d.y),w=dist(e.x,e.y,c.x,c.y)/2,y=2*asin(w/m),_=2*Math.PI*m*y/360;i.addSegment(p,v-s,n[2],!0),i.addSegment(p,_,n[2],!0),i.addSegment(f,r===t.length-3?x:0,a[2],!0),s=u}r==t.length-3&&i.endPlot(f,a[2],!0)}else if(0===e){let e=t[r],s=t[r+1],o=dist(e[0],e[1],s[0],s[1]),n=l(e[0],e[1],s[0],s[1]);i.addSegment(n,o,1,!0),r==t.length-2&&i.endPlot(n,1,!0)}}return i}function S(t,e,i,s){I.opacity=arguments.length<4?arguments.length<3?e:1:s,I.color=arguments.length<3?color(t):color(t,e,i),I.isActive=!0}function P(t,e=.4,i=.4){I.bleed_strength=o.constrain(t,0,.6),I.texture_strength=o.constrain(e,0,1),I.border_strength=o.constrain(i,0,1)}const I={isActive:!1,isAnimated:!1,color:"#002185",opacity:80,bleed_strength:.07,texture_strength:.4,border_strength:.4,fill(t){this.v=t.a.map((t=>createVector(t[0],t[1])));const e=this.v.length*o.random(.4);I.m=this.v.map(((t,i)=>{let s=o.random(.8,1.2)*this.bleed_strength;return i<e?constrain(2*s,0,.9):s}));let i=o.randInt(0,this.v.length);this.v=[...this.v.slice(i),...this.v.slice(0,i)],new B(this.v,this.m,this.calcCenter()).fill(this.color,int(map(this.opacity,0,155,0,20,!0)),this.texture_strength)},calcCenter(){let t=0,e=0;for(let i=0;i<this.v.length;++i)t+=this.v[i].x,e+=this.v[i].y;return t/=this.v.length,e/=this.v.length,createVector(t,e)}};class B{constructor(t,e,i){this.v=t,this.m=e,this.midP=i,this.size=p5.Vector.sub(this.midP,this.v[0]).mag()}grow(t,e=!1){const i=[],s=[];let r=t>=.2?Math.floor(t*this.v.length):this.v.length;const o=t=>t+.1*(randomGaussian(.5,.1)-.5),n="radians"===angleMode()?Math.PI/180:1;for(let a=0;a<r;a++){const h=this.v[a],l=this.v[(a+1)%r];let c=.1===t?.75:this.m[a];e&&(c*=-.5),i.push(h),s.push(o(c));let d=p5.Vector.lerp(h,l,constrain(randomGaussian(.5,.2),.1,.9)),m=p5.Vector.sub(l,h),p=m.copy().normalize(),f=45*randomGaussian(0,.4)-90;p.rotate(f*n),p.mult(randomGaussian(.5,.2)*random(.6,1.4)*m.mag()*c),d.add(p),i.push(d),s.push(o(c))}return new B(i,s,this.midP)}fill(t,i,s){const r=i/5+s*i/6,o=i/4+s*i/3,h=i/7+s*i/3,l=i/5,d=3*s;a(),c.blend(t,!1,!1,!0),c.mask.push(),c.mask.noStroke(),c.mask.translate(n[0]+e.width/2,n[1]+e.height/2);let m=this.grow(),p=m.grow().grow(.9),f=p.grow(.75),u=this.grow(.85);for(let t=0;t<24;t++)t!==Math.floor(6)&&t!==Math.floor(12)&&t!==Math.floor(18)||(m=m.grow(),p=p.grow(.75),f=f.grow(.75),u=u.grow(.1,!0)),m.grow().layer(t,l),u.grow(.1,!0).grow(.1).layer(t,h,!1),p.grow(.1).grow(.1).layer(t,o,!1),f.grow(.8).grow(.1).layer(t,r,!1),0!==d&&m.erase(d);c.mask.pop()}layer(t,e,i=!0){c.mask.fill(255,0,0,e),i?(c.mask.stroke(255,0,0,.5+1.5*I.border_strength),c.mask.strokeWeight(o.map(t,0,24,6,.5))):c.mask.noStroke(),c.mask.beginShape();for(let t of this.v)c.mask.vertex(t.x,t.y);c.mask.endShape(CLOSE)}erase(t){const e=o.random(80,110),i=this.size/2,s=.025*this.size,r=.19*this.size;c.mask.erase(3.5*t,0);for(let t=0;t<e;t++){const t=this.midP.x+randomGaussian(0,i),e=this.midP.y+randomGaussian(0,i),n=o.random(s,r);c.mask.circle(t,e,n)}c.mask.noErase()}}p5.RendererGL.prototype.erase=function(t,e){this._isErasing||(this._cachedBlendMode=this.curBlendMode,this._isErasing=!0,this.blendMode("destination-out"),this._cachedFillStyle=this.curFillColor.slice(),this.curFillColor=[1,1,1,t/255],this._cachedStrokeStyle=this.curStrokeColor.slice(),this.curStrokeColor=[1,1,1,e/255])},p5.RendererGL.prototype.noErase=function(){if(this._isErasing){this.curFillColor=this._cachedFillStyle.slice(),this.curStrokeColor=this._cachedStrokeStyle.slice();let t=this.curBlendMode;this.blendMode(this._cachedBlendMode),this._cachedBlendMode=t,this._isErasing=!1,this._applyBlendMode()}};const D=[["pen",{weight:.35,vibration:.12,definition:.5,quality:8,opacity:200,spacing:.3,pressure:{curve:[.15,.2],min_max:[1.3,1]}}],["rotring",{weight:.2,vibration:.05,definition:1,quality:3,opacity:250,spacing:.15,pressure:{curve:[.05,.2],min_max:[1.2,.95]}}],["2B",{weight:.35,vibration:.5,definition:.1,quality:8,opacity:180,spacing:.2,pressure:{curve:[.15,.2],min_max:[1.3,1]}}],["HB",{weight:.3,vibration:.5,definition:.4,quality:4,opacity:180,spacing:.25,pressure:{curve:[.15,.2],min_max:[1.2,.9]}}],["2H",{weight:.2,vibration:.4,definition:.3,quality:2,opacity:150,spacing:.2,pressure:{curve:[.15,.2],min_max:[1.2,.9]}}],["cpencil",{weight:.4,vibration:.6,definition:.8,quality:7,opacity:120,spacing:.15,pressure:{curve:[.15,.2],min_max:[.95,1.15]}}],["charcoal",{weight:.5,vibration:2,definition:.8,quality:300,opacity:110,spacing:.06,pressure:{curve:[.15,.2],min_max:[1.15,.85]}}],["hatch_brush",{weight:.2,vibration:.4,definition:.3,quality:2,opacity:150,spacing:.15,pressure:{curve:[.5,.7],min_max:[1,1.5]}}],["spray",{type:"spray",weight:.3,vibration:12,definition:15,quality:40,opacity:120,spacing:.65,pressure:{curve:[0,.1],min_max:[.15,1.2]}}],["marker",{type:"marker",weight:2.5,vibration:.12,opacity:30,spacing:.4,pressure:{curve:[.35,.25],min_max:[1.35,1]}}],["marker2",{type:"custom",weight:2.5,vibration:.12,opacity:25,spacing:.35,pressure:{curve:[.35,.25],min_max:[1.15,.95]},tip:function(){let t=u;g.mask.rect(-1.5*t,-1.5*t,3*t,3*t),g.mask.rect(1*t,1*t,1*t,1*t)},rotate:"natural"}]];for(let t of D)g.add(t[0],t[1]);t.config=function(t={}){t.R&&(o.source=t.R)},t.load=s,t.preload=function(){v.load()},t.colorCache=function(t=!0){c.isCaching=t},t.reDraw=c.reDraw,t.addField=d,t.field=function(t){r(),m.isActive=!0,m.current=t},t.noField=function(){m.isActive=!1},t.refreshField=function(t){m.refresh(t)},t.listFields=function(){return Array.from(m.list.keys())},t.scale=f,t.add=g.add,t.box=function(){return Array.from(g.list.keys())},t.set=g.set,t.pick=g.setBrush,t.clip=g.clip,t.noClip=g.noClip,t.tip=function(t,e,i){r(),g.position=new p(t,e),g.drawTip(i)},t.stroke=g.setColor,t.strokeWeight=g.setWeight,t.noStroke=function(){g.isActive=!1},t.fill=S,t.bleed=P,t.noFill=function(){I.isActive=!1},t.fillAnimatedMode=function(t){I.isAnimated=t},t.line=g.line,t.flowLine=g.flowLine,t.plot=g.flowShape,t.rect=function(t,e,i,s,r=CORNER){if(r==CENTER&&(t-=i/2,e-=s/2),m.isActive)b(0),M(t,e),M(t+i,e),M(t+i,e+s),M(t,e+s),C(CLOSE);else{let r=new y([[t,e],[t+i,e],[t+i,e+s],[t,e+s]]);r.fill(),r.hatch(),r.draw()}},t.circle=function(t,e,i,s=!1){let r=new _("curve"),n=Math.PI*i/2,a=()=>s?o.random(-1,1):0;r.addSegment(0+a(),n+a(),1,!0),r.addSegment(-90+a(),n+a(),1,!0),r.addSegment(-180+a(),n+a(),1,!0),r.addSegment(-270+a(),n+a(),1,!0);let h=s?o.randInt(-5,5):0;if(s&&r.addSegment(0,h*(Math.PI/180)*i,!0),r.endPlot(h+0,1,!0),I.isActive||w.isActive){let s=r.genPol(t-i*o.sin(0),e-i*o.cos(-0));s.fill(),s.hatch()}g.isActive&&r.draw(t-i*o.sin(0),e-i*o.cos(-0),1)},t.polygon=function(t){if(!Array.isArray(t)||t.length<3)return void console.error("Invalid input for polygon: An array with at least 3 points is required.");let e=new y(t);e.fill(),e.hatch(),e.draw()},t.spline=function(t,e=.5){A(t,e).draw()},t.beginShape=b,t.vertex=M,t.endShape=C,t.beginStroke=function(t,e,i){k=[e,i],z=new _(t)},t.segment=function(t,e,i){z.addSegment(t,e,i)},t.endStroke=function(t,e){z.endPlot(t,e),z.draw(k[0],k[1],1),z=!1},t.hatchArray=w.hatch,t.hatch=x,t.setHatch=function(t,e,i=1){w.hatchingBrush=[t,e,i]},t.noHatch=function(){w.isActive=!1,w.hatchingBrush=!1},t.Polygon=y,t.Plot=_,t.Position=p}));
\ No newline at end of file
+!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).brush={})}(this,(function(t){"use strict";let e,i=!1;function s(t=!1){i=!0,e=t||window.self,p.load(),f.create(),g(e.width/250)}function r(){i||s()}p5.prototype.registerMethod("afterSetup",(()=>r()));const n={source:()=>random(),random(t=0,e=1){return 1===arguments.length?this.map(this.source(),0,1,0,t):this.map(this.source(),0,1,t,e)},randInt(t,e){return Math.floor(this.random(t,e))},weightedRand(t){let e,i,s=[];for(e in t)for(i=0;i<10*t[e];i++)s.push(e);return s[Math.floor(this.source()*s.length)]},map(t,e,i,s,r,n=!1){let o=s+(t-e)/(i-e)*(r-s);return n?s<r?this.constrain(o,s,r):this.constrain(o,r,s):o},constrain:(t,e,i)=>Math.max(Math.min(t,i),e),cos(t){return this.c[Math.floor((t%360+360)%360*4)]},sin(t){return this.s[Math.floor((t%360+360)%360*4)]},isPrecalculationDone:!1,preCalculation(){if(this.isPrecalculationDone)return;const t=1440,e=2*Math.PI/t;this.c=new Float64Array(t),this.s=new Float64Array(t);for(let i=0;i<t;i++){const t=i*e;n.c[i]=Math.cos(t),n.s[i]=Math.sin(t)}this.isPrecalculationDone=!0},toDegrees:t=>(("radians"===angleMode()?180*t/Math.PI:t)%360+360)%360};n.preCalculation();const o={translation:[0,0],rotation:0,rotate(t){o.rotation=n.toDegrees(t)},trans(){return this.translation=[e._renderer.uMVMatrix.mat4[12],e._renderer.uMVMatrix.mat4[13]],this.translation}};function a(t,e,i,s,r=!1){let n=t.x,o=t.y,a=e.x,h=e.y,l=i.x,c=i.y,d=s.x,p=s.y;if(n===a&&o===h||l===d&&c===p)return!1;let m=a-n,f=h-o,u=d-l,g=p-c,v=g*m-u*f;if(0===v)return!1;let x=(u*(o-c)-g*(n-l))/v,y=(m*(o-c)-f*(n-l))/v;return!(!r&&(y<0||y>1))&&{x:n+x*m,y:o+x*f}}function h(t,e,i,s){return(Math.atan2(-(s-e),i-t)*(180/Math.PI)%360+360)%360}const l={field:{},stroke:{},hatch:{},fill:{},others:{}};function c(){l.field.isActive=f.isActive,l.field.current=f.current,l.stroke.isActive=x.isActive,l.stroke.brush=x.name,l.stroke.color=x.c,l.stroke.weight=x.w,l.stroke.globalScale=v,l.stroke.clip=x.cr,l.hatch.isActive=_.isActive,l.hatch.hatchingParams=_.hatchingParams,l.hatch.hatchingBrush=_.hatchingBrush,l.fill.isActive=D.isActive,l.fill.color=D.color,l.fill.opacity=D.opacity,l.fill.bleed_strength=D.bleed_strength,l.fill.texture_strength=D.texture_strength,l.fill.border_strength=D.border_strength,l.others.rotate=o.rotation}function d(){f.isActive=l.field.isActive,f.current=l.field.current,x.isActive=l.stroke.isActive,x.name=l.stroke.brush,x.c=l.stroke.color,x.w=l.stroke.weight,v=l.stroke.globalScale,x.cr=l.stroke.clip,_.isActive=l.hatch.isActive,_.hatchingParams=l.hatch.hatchingParams,_.hatchingBrush=l.hatch.hatchingBrush,D.isActive=l.fill.isActive,D.color=l.fill.color,D.opacity=l.fill.opacity,D.bleed_strength=l.fill.bleed_strength,D.texture_strength=l.fill.texture_strength,D.border_strength=l.fill.border_strength,o.rotation=l.others.rotate}const p={loaded:!1,isBlending:!1,isCaching:!0,currentColor:new Float32Array(3),load(){this.mask=createGraphics(e.width,e.height),this.mask.pixelDensity(e.pixelDensity()),this.mask.clear(),this.mask.noSmooth(),this.mask.angleMode(DEGREES),t.mask=this.mask,p.loaded||(this.frag=this.frag.replace('#include "spectral.glsl"',this.glsl())),this.shader=e.createShader(this.vert,this.frag),p.loaded=!0,this.noBlend=createGraphics(e.width,e.height),this.noBlend.pixelDensity(e.pixelDensity()),this.noBlend.noSmooth(),this.noBlend.clear(),this.noBlend.angleMode(DEGREES),this.mask2=createGraphics(e.width,e.height,WEBGL),this.mask2.pixelDensity(e.pixelDensity()),this.mask2.clear(),this.mask2.angleMode(DEGREES)},getPigment(t){let e=t.levels,i=new Float32Array(3);return i[0]=e[0]/255,i[1]=e[1]/255,i[2]=e[2]/255,i},reDraw(){e.push(),e.translate(-o.trans()[0],-o.trans()[1]),e.image(p.noBlend,-e.width/2,-e.height/2),p.noBlend.clear(),e.pop()},reBlend(){c(),x.set("marker","white",1),x.line(-10,-10,-5,-5),d()},color1:new Float32Array(3),color2:new Float32Array(3),blending1:!1,blending2:!1,blend(t=!1,i=!1,s=!1,r=!1){if(this.isBlending=s?this.blending1:this.blending2,this.currentColor=s?this.color1:this.color2,!this.isBlending){if(!t)return e.push(),e.translate(-o.trans()[0],-o.trans()[1]),e.image(this.noBlend,-e.width/2,-e.height/2),this.noBlend.clear(),void e.pop();this.currentColor=this.getPigment(t),s?(this.blending1=!0,this.color1=this.currentColor):(this.blending2=!0,this.color2=this.currentColor)}if((t?this.getPigment(t):this.currentColor).toString()!==this.currentColor.toString()||i||!this.isCaching){e.push(),e.translate(-o.trans()[0],-o.trans()[1]),e.image(this.noBlend,-e.width/2,-e.height/2),this.noBlend.clear(),e.shader(this.shader),this.shader.setUniform("addColor",this.currentColor),this.shader.setUniform("source",e._renderer),this.shader.setUniform("active",r),this.shader.setUniform("random",[n.random(),n.random(),n.random()]);let a=s?this.mask2:this.mask;this.shader.setUniform("mask",a),e.fill(0,0,0,0),e.noStroke(),e.rect(-e.width/2,-e.height/2,e.width,e.height),e.pop(),a.clear(),i||(this.currentColor=this.getPigment(t),s?this.color1=this.currentColor:this.color2=this.currentColor)}i&&(this.isBlending=!1,s?this.blending1=this.isBlending:this.blending2=this.isBlending)},vert:"precision highp float;attribute vec3 aPosition;attribute vec2 aTexCoord;uniform mat4 uModelViewMatrix,uProjectionMatrix;varying vec2 vVertTexCoord;void main(){gl_Position=uProjectionMatrix*uModelViewMatrix*vec4(aPosition,1);vVertTexCoord=aTexCoord;}",frag:'precision highp float;varying vec2 y;uniform sampler2D v,x;uniform vec4 d;uniform vec3 f;uniform bool m;\n #include "spectral.glsl"\n float t(vec2 v,vec2 y,float x,out vec2 i){vec2 d=vec2(v.x+v.y*.5,v.y),f=floor(d),m=fract(d);float z=step(m.y,m.x);vec2 s=vec2(z,1.-z),l=f+s,o=f+1.,a=vec2(f.x-f.y*.5,f.y),r=vec2(a.x+s.x-s.y*.5,a.y+s.y),t=vec2(a.x+.5,a.y+1.),g=v-a,w=v-r,C=v-t;vec3 u,c,D,F;if(any(greaterThan(y,vec2(0)))){D=vec3(a.x,r.x,t);F=vec3(a.y,r.y,t.y);if(y.x>0.)D=mod(vec3(a.x,r.x,t),y.x);if(y.y>0.)F=mod(vec3(a.y,r.y,t.y),y.y);u=floor(D+.5*F+.5);c=floor(F+.5);}else u=vec3(f.x,l.x,o),c=vec3(f.y,l.y,o.y);vec3 b=mod(u,289.);b=mod((b*51.+2.)*b+c,289.);b=mod((b*34.+10.)*b,289.);vec3 h=b*.07482+x,B=cos(h),A=sin(h);vec2 E=vec2(B.x,A),G=vec2(B.y,A.y),H=vec2(B.z,A.z);vec3 I=.8-vec3(dot(g,g),dot(w,w),dot(C,C));I=max(I,0.);vec3 J=I*I,K=J*J,L=vec3(dot(E,g),dot(G,w),dot(H,C)),M=J*I,N=-8.*M*L;i=10.9*(K.x*E+N.x*g+(K.y*G+N.y*w)+(K.z*H+N.z*C));return 10.9*dot(K,L);}vec4 t(vec3 y,float v){return vec4(mix(y,vec3(dot(vec3(.299,.587,.114),y)),v),1);}float s(vec2 y,float v,float x,float f){return fract(sin(dot(y,vec2(v,x)))*f);}void main(){vec4 a=texture2D(x,y);if(a.x>0.){vec2 r=vec2(12.9898,78.233),l=vec2(7.9898,58.233),o=vec2(17.9898,3.233);float z=s(y,r.x,r.y,43358.5453)*2.-1.,c=s(y,l.x,l.y,43213.5453)*2.-1.,w=s(y,o.x,o.y,33358.5453)*2.-1.;const vec2 b=vec2(0);vec2 C;vec4 i;if(m){float u=t(y*10.,b,10.*f.x,C),I=t(y*10.,b,10.*f.y,C),g=t(y*10.,b,10.*f.z,C),L=.25+.25*t(y*8.,b,3.*f.x,C);i=vec4(t(d.xyz,L).xyz+vec3(u,I,g)*.03,1);}else i=vec4(d.xyz,1);if(a.w>.7){float L=.5*(a.w-.7);i=i*(1.-L)-vec4(.5)*L;}vec3 u=spectral_mix(texture2D(v,y).xyz,i.xyz,.9*a.w);gl_FragColor=vec4(u+.01*vec3(z,c,w),1);}}',glsl:()=>"float spectral_uncompand(float s){return s<.04045?s/12.92:pow((s+.055)/1.055,2.4);}float spectral_compand(float s){return s<.0031308?s*12.92:1.055*pow(s,1./2.4)-.055;}vec3 spectral_srgb_to_linear(vec3 s){return vec3(spectral_uncompand(s[0]),spectral_uncompand(s[1]),spectral_uncompand(s[2]));}vec3 spectral_linear_to_srgb(vec3 s){return clamp(vec3(spectral_compand(s[0]),spectral_compand(s[1]),spectral_compand(s[2])),0.,1.);}void spectral_upsampling(vec3 e,out float m,out float s,out float f,out float r,out float x,out float v,out float z){m=min(e.x,min(e.y,e.z));e-=m;s=min(e.y,e.z);f=min(e.x,e.z);r=min(e.x,e.y);x=min(max(0.,e.x-e.z),max(0.,e.x-e.y));v=min(max(0.,e.y-e.z),max(0.,e.y-e.x));z=min(max(0.,e.z-e.y),max(0.,e.z-e.x));}void spectral_linear_to_reflectance(vec3 s,inout float f[38]){float e,o,m,x,v,w,z;spectral_upsampling(s,e,o,m,x,v,w,z);f[0]=max(1e-4,e+o*.96853629+m*.51567122+x*.02055257+v*.03147571+w*.49108579+z*.97901834);f[1]=max(1e-4,e+o*.96855103+m*.5401552+x*.02059936+v*.03146636+w*.46944057+z*.97901649);f[2]=max(1e-4,e+o*.96859338+m*.62645502+x*.02062723+v*.03140624+w*.4016578+z*.97901118);f[3]=max(1e-4,e+o*.96877345+m*.75595012+x*.02073387+v*.03119611+w*.2449042+z*.97892146);f[4]=max(1e-4,e+o*.96942204+m*.92826996+x*.02114202+v*.03053888+w*.0682688+z*.97858555);f[5]=max(1e-4,e+o*.97143709+m*.97223624+x*.02233154+v*.02856855+w*.02732883+z*.97743705);f[6]=max(1e-4,e+o*.97541862+m*.98616174+x*.02556857+v*.02459485+w*.013606+z*.97428075);f[7]=max(1e-4,e+o*.98074186+m*.98955255+x*.03330189+v*.0192952+w*.01000187+z*.96663223);f[8]=max(1e-4,e+o*.98580992+m*.98676237+x*.05185294+v*.01423112+w*.01284127+z*.94822893);f[9]=max(1e-4,e+o*.98971194+m*.97312575+x*.10087639+v*.01033111+w*.02636635+z*.89937713);f[10]=max(1e-4,e+o*.99238027+m*.91944277+x*.24000413+v*.00765876+w*.07058713+z*.76070164);f[11]=max(1e-4,e+o*.99409844+m*.32564851+x*.53589066+v*.00593693+w*.70421692+z*.4642044);f[12]=max(1e-4,e+o*.995172+m*.13820628+x*.79874659+v*.00485616+w*.85473994+z*.20123039);f[13]=max(1e-4,e+o*.99576545+m*.05015143+x*.91186529+v*.00426186+w*.95081565+z*.08808402);f[14]=max(1e-4,e+o*.99593552+m*.02912336+x*.95399623+v*.00409039+w*.9717037+z*.04592894);f[15]=max(1e-4,e+o*.99564041+m*.02421691+x*.97137099+v*.00438375+w*.97651888+z*.02860373);f[16]=max(1e-4,e+o*.99464769+m*.02660696+x*.97939505+v*.00537525+w*.97429245+z*.02060067);f[17]=max(1e-4,e+o*.99229579+m*.03407586+x*.98345207+v*.00772962+w*.97012917+z*.01656701);f[18]=max(1e-4,e+o*.98638762+m*.04835936+x*.98553736+v*.0136612+w*.9425863+z*.01451549);f[19]=max(1e-4,e+o*.96829712+m*.0001172+x*.98648905+v*.03181352+w*.99989207+z*.01357964);f[20]=max(1e-4,e+o*.89228016+m*8.554e-5+x*.98674535+v*.10791525+w*.99989891+z*.01331243);f[21]=max(1e-4,e+o*.53740239+m*.85267882+x*.98657555+v*.46249516+w*.13823139+z*.01347661);f[22]=max(1e-4,e+o*.15360445+m*.93188793+x*.98611877+v*.84604333+w*.06968113+z*.01387181);f[23]=max(1e-4,e+o*.05705719+m*.94810268+x*.98559942+v*.94275572+w*.05628787+z*.01435472);f[24]=max(1e-4,e+o*.03126539+m*.94200977+x*.98507063+v*.96860996+w*.06111561+z*.01479836);f[25]=max(1e-4,e+o*.02205445+m*.91478045+x*.98460039+v*.97783966+w*.08987709+z*.0151525);f[26]=max(1e-4,e+o*.01802271+m*.87065445+x*.98425301+v*.98187757+w*.13656016+z*.01540513);f[27]=max(1e-4,e+o*.0161346+m*.78827548+x*.98403909+v*.98377315+w*.22169624+z*.01557233);f[28]=max(1e-4,e+o*.01520947+m*.65738359+x*.98388535+v*.98470202+w*.32176956+z*.0156571);f[29]=max(1e-4,e+o*.01475977+m*.59909403+x*.98376116+v*.98515481+w*.36157329+z*.01571025);f[30]=max(1e-4,e+o*.01454263+m*.56817268+x*.98368246+v*.98537114+w*.4836192+z*.01571916);f[31]=max(1e-4,e+o*.01444459+m*.54031997+x*.98365023+v*.98546685+w*.46488579+z*.01572133);f[32]=max(1e-4,e+o*.01439897+m*.52110241+x*.98361309+v*.98550011+w*.47440306+z*.01572502);f[33]=max(1e-4,e+o*.0143762+m*.51041094+x*.98357259+v*.98551031+w*.4857699+z*.01571717);f[34]=max(1e-4,e+o*.01436343+m*.50526577+x*.98353856+v*.98550741+w*.49267971+z*.01571905);f[35]=max(1e-4,e+o*.01435687+m*.5025508+x*.98351247+v*.98551323+w*.49625685+z*.01571059);f[36]=max(1e-4,e+o*.0143537+m*.50126452+x*.98350101+v*.98551563+w*.49807754+z*.01569728);f[37]=max(1e-4,e+o*.01435408+m*.50083021+x*.98350852+v*.98551547+w*.49889859+z*.0157002);}vec3 spectral_xyz_to_srgb(vec3 e){mat3 f;f[0]=vec3(3.24306333,-1.53837619,-.49893282);f[1]=vec3(-.96896309,1.87542451,.04154303);f[2]=vec3(.05568392,-.20417438,1.05799454);float s=dot(f[0],e),m=dot(f[1],e),z=dot(f[2],e);return spectral_linear_to_srgb(vec3(s,m,z));}vec3 spectral_reflectance_to_xyz(float f[38]){vec3 e=vec3(0);e+=f[0]*vec3(6.469e-5,1.84e-6,.00030502);e+=f[1]*vec3(.00021941,6.21e-6,.00103681);e+=f[2]*vec3(.00112057,3.101e-5,.00531314);e+=f[3]*vec3(.00376661,.00010475,.01795439);e+=f[4]*vec3(.01188055,.00035364,.05707758);e+=f[5]*vec3(.02328644,.00095147,.11365162);e+=f[6]*vec3(.03455942,.00228226,.17335873);e+=f[7]*vec3(.03722379,.00420733,.19620658);e+=f[8]*vec3(.03241838,.0066888,.18608237);e+=f[9]*vec3(.02123321,.0098884,.13995048);e+=f[10]*vec3(.01049099,.01524945,.08917453);e+=f[11]*vec3(.00329584,.02141831,.04789621);e+=f[12]*vec3(.00050704,.03342293,.02814563);e+=f[13]*vec3(.00094867,.05131001,.01613766);e+=f[14]*vec3(.00627372,.07040208,.0077591);e+=f[15]*vec3(.01686462,.08783871,.00429615);e+=f[16]*vec3(.02868965,.09424905,.00200551);e+=f[17]*vec3(.04267481,.09795667,.00086147);e+=f[18]*vec3(.05625475,.09415219,.00036904);e+=f[19]*vec3(.0694704,.08678102,.00019143);e+=f[20]*vec3(.08305315,.07885653,.00014956);e+=f[21]*vec3(.0861261,.0635267,9.231e-5);e+=f[22]*vec3(.09046614,.05374142,6.813e-5);e+=f[23]*vec3(.08500387,.04264606,2.883e-5);e+=f[24]*vec3(.07090667,.03161735,1.577e-5);e+=f[25]*vec3(.05062889,.02088521,3.94e-6);e+=f[26]*vec3(.03547396,.01386011,1.58e-6);e+=f[27]*vec3(.02146821,.00810264,0);e+=f[28]*vec3(.01251646,.0046301,0);e+=f[29]*vec3(.00680458,.00249138,0);e+=f[30]*vec3(.00346457,.0012593,0);e+=f[31]*vec3(.00149761,.00054165,0);e+=f[32]*vec3(.0007697,.00027795,0);e+=f[33]*vec3(.00040737,.00014711,0);e+=f[34]*vec3(.00016901,6.103e-5,0);e+=f[35]*vec3(9.522e-5,3.439e-5,0);e+=f[36]*vec3(4.903e-5,1.771e-5,0);e+=f[37]*vec3(2e-5,7.22e-6,0);return e;}float spectral_linear_to_concentration(float v,float m,float s){float z=m*pow(s,2.);return z/(v*pow(1.-s,2.)+z);}vec3 spectral_mix(vec3 s,vec3 f,float e){vec3 v=spectral_srgb_to_linear(s),m=spectral_srgb_to_linear(f);float z[38],o[38];spectral_linear_to_reflectance(v,z);spectral_linear_to_reflectance(m,o);float x=spectral_reflectance_to_xyz(z)[1],w=spectral_reflectance_to_xyz(o)[1];e=spectral_linear_to_concentration(x,w,e);float r[38];for(int c=0;c<38;c++){float y=(1.-e)*(pow(1.-z[c],2.)/(2.*z[c]))+e*(pow(1.-o[c],2.)/(2.*o[c]));r[c]=1.+y-sqrt(pow(y,2.)+2.*y);}return spectral_xyz_to_srgb(spectral_reflectance_to_xyz(r));}vec4 spectral_mix(vec4 s,vec4 e,float z){return vec4(spectral_mix(s.xyz,e.xyz,z),mix(s.w,e.w,z));}"};function m(t,e){r(),f.list.set(t,{gen:e}),f.current=t,f.refresh()}p5.prototype.registerMethod("afterSetup",(()=>p.blend(!1,!0))),p5.prototype.registerMethod("afterSetup",(()=>p.blend(!1,!0,!0))),p5.prototype.registerMethod("post",(()=>p.blend(!1,!0))),p5.prototype.registerMethod("post",(()=>p.blend(!1,!0,!0)));const f={isActive:!1,list:new Map,current:"",step_length:()=>Math.min(e.width,e.height)/1e3,create(){this.R=.01*e.width,this.left_x=-1*e.width,this.top_y=-1*e.height,this.num_columns=Math.round(2*e.width/this.R),this.num_rows=Math.round(2*e.height/this.R),this.addStandard()},flow_field(){return this.list.get(this.current).field},refresh(t=0){this.list.get(this.current).field=this.list.get(this.current).gen(t,this.genField())},genField(){let t=new Array(this.num_columns);for(let e=0;e<this.num_columns;e++)t[e]=new Float64Array(this.num_rows);return t},addStandard(){m("curved",(function(t,e){let i=n.randInt(-25,-15);n.randInt(0,100)%2==0&&(i*=-1);for(let s=0;s<f.num_columns;s++)for(let r=0;r<f.num_rows;r++){let o=noise(.02*s+.03*t,.02*r+.03*t),a=n.map(o,0,1,-i,i);e[s][r]=3*a}return e})),m("truncated",(function(t,e){let i=n.randInt(-25,-15)+5*n.sin(t);n.randInt(0,100)%2==0&&(i*=-1);let s=n.randInt(5,10);for(let t=0;t<f.num_columns;t++)for(let r=0;r<f.num_rows;r++){let o=noise(.02*t,.02*r),a=Math.round(n.map(o,0,1,-i,i)/s)*s;e[t][r]=4*a}return e})),m("zigzag",(function(t,e){let i=n.randInt(-30,-15)+Math.abs(44*n.sin(t));n.randInt(0,100)%2==0&&(i*=-1);let s=i,r=0;for(let t=0;t<f.num_columns;t++){for(let i=0;i<f.num_rows;i++)e[t][i]=r,r+=s,s*=-1;r+=s,s*=-1}return e})),m("waves",(function(t,e){let i=n.randInt(10,15)+5*n.sin(t),s=n.randInt(3,6)+3*n.cos(t),r=n.randInt(20,35);for(let t=0;t<f.num_columns;t++)for(let o=0;o<f.num_rows;o++){let a=n.sin(i*t)*(r*n.cos(o*s))+n.randInt(-3,3);e[t][o]=a}return e})),m("seabed",(function(t,e){let i=n.random(.4,.8),s=n.randInt(18,26);for(let r=0;r<f.num_columns;r++)for(let o=0;o<f.num_rows;o++){let a=n.randInt(15,20),h=s*n.sin(i*o*r+a);e[r][o]=1.1*h*n.cos(t)}return e}))}};class u{constructor(t,e){this.update(t,e),this.plotted=0}update(t,e){this.x=t,this.y=e,f.isActive&&(this.x_offset=this.x-f.left_x+o.trans()[0],this.y_offset=this.y-f.top_y+o.trans()[1],this.column_index=Math.round(this.x_offset/f.R),this.row_index=Math.round(this.y_offset/f.R))}reset(){this.plotted=0}isIn(){return f.isActive?this.column_index>=0&&this.row_index>=0&&this.column_index<f.num_columns&&this.row_index<f.num_rows:this.isInCanvas()}isInCanvas(){let t=.55*e.width,i=.55*e.height;return this.x>=-t-o.trans()[0]&&this.x<=t-o.trans()[0]&&this.y>=-i-o.trans()[1]&&this.y<=i-o.trans()[1]}angle(){return this.isIn()&&f.isActive?f.flow_field()[this.column_index][this.row_index]:0}moveTo(t,e,i=f.step_length(),s=!0){if(this.isIn()){let r,o;s||(r=n.cos(-e),o=n.sin(-e));for(let a=0;a<t/i;a++){if(s){let t=this.angle();r=n.cos(t-e),o=n.sin(t-e)}let t=i*r,a=i*o;this.plotted+=i,this.update(this.x+t,this.y+a)}}else this.plotted+=i}plotTo(t,e,i,s){if(this.isIn()){const r=1/s;for(let s=0;s<e/i;s++){let e=this.angle(),s=t.angle(this.plotted),o=i*n.cos(e-s),a=i*n.sin(e-s);this.plotted+=i*r,this.update(this.x+o,this.y+a)}}else this.plotted+=i/scale}}function g(t){for(let e of F){let i=x.list.get(e[0]).param;i.weight*=t,i.vibration*=t,i.spacing*=t}v=t}let v=1;const x={isActive:!0,list:new Map,c:"#000000",w:1,cr:null,name:"HB",add:(t,e)=>{const i="marker"===e.type||"custom"===e.type||"image"===e.type;"image"===e.type&&(y.add(e.image.src),e.tip=()=>x.mask.image(y.tips.get(x.p.image.src),-x.p.weight/2,-x.p.weight/2,x.p.weight,x.p.weight)),e.blend=!!(i&&!1!==e.blend||e.blend),x.list.set(t,{param:e,colors:[],buffers:[]})},set(t,e,i=1){x.name=t,x.c=e,x.w=i,x.isActive=!0},setBrush(t){x.name=t},setColor(t,e,i){arguments.length>0&&(x.c=arguments.length<2?t:[t,e,i]),x.isActive=!0},setWeight(t){x.w=t},clip(t){x.cr=t},noClip(){x.cr=null},line(t,e,i,s){r();let n=dist(t,e,i,s);if(0==n)return;x.initializeDrawingState(t,e,n,!1,!1);let o=h(t,e,i,s);x.draw(o,!1)},flowLine(t,e,i,s){r(),x.initializeDrawingState(t,e,i,!0,!1),x.draw(n.toDegrees(s),!1)},flowShape(t,e,i,s){r(),x.initializeDrawingState(e,i,t.length,!0,t),x.draw(s,!0)},spacing(){return this.p=this.list.get(this.name).param,this.p.spacing*this.w},initializeDrawingState(t,e,i,s,r){this.position=new u(t,e),this.length=i,this.flow=s,this.plot=r,r&&r.calcIndex(0)},draw(t,e){e||(this.dir=t),this.pushState();const i=this.spacing(),s=e?Math.round(this.length*t/i):Math.round(this.length/i);for(let r=0;r<s;r++)this.tip(),e?this.position.plotTo(this.plot,i,i,t):this.position.moveTo(i,t,i,this.flow);this.popState()},drawTip(t){this.pushState(!0),this.tip(t),this.popState(!0)},pushState(t=!1){if(this.p=this.list.get(this.name).param,!t){this.a="custom"!==this.p.pressure.type?n.random(-1,1):0,this.b="custom"!==this.p.pressure.type?n.random(1,1.5):0,this.cp="custom"!==this.p.pressure.type?n.random(3,3.5):n.random(-.2,.2);const[t,e]=this.p.pressure.min_max;this.min=t,this.max=e}this.c=e.color(this.c),this.mask=this.p.blend?"image"===this.p.type?p.mask2:p.mask:p.noBlend,o.trans(),this.mask.push(),this.mask.noStroke(),"image"===this.p.type?this.mask.translate(o.translation[0],o.translation[1]):this.mask.translate(o.translation[0]+e.width/2,o.translation[1]+e.height/2),this.mask.rotate(-o.rotation),this.p.blend&&("image"!==this.p.type?p.blend(this.c):p.blend(this.c,!1,!0),t||this.markerTip())},popState(t=!1){this.p.blend&&!t&&this.markerTip(),this.mask.pop()},tip(t=!1){let e=t||this.calculatePressure(),i=this.calculateAlpha(e);if(this.applyColor(i),this.isInsideClippingArea())switch(this.p.type){case"spray":this.drawSpray(e);break;case"marker":this.drawMarker(e);break;case"custom":case"image":this.drawCustomOrImage(e,i);break;default:this.drawDefault(e)}},calculatePressure(){return this.plot?this.simPressure()*this.plot.pressure(this.position.plotted):this.simPressure()},simPressure(){return"custom"===this.p.pressure.type?n.map(this.p.pressure.curve(this.position.plotted/this.length)+this.cp,0,1,this.min,this.max,!0):this.gauss()},gauss(t=.5+x.p.pressure.curve[0]*x.a,e=1-x.p.pressure.curve[1]*x.b,i=x.cp,s=x.min,r=x.max){return n.map(1/(1+Math.pow(Math.abs((this.position.plotted-t*this.length)/(e*this.length/2)),2*i)),0,1,s,r)},calculateAlpha(t){return Math.floor(this.p.opacity*Math.pow(t,"marker"===this.p.type?.7:1.5))},applyColor(t){this.p.blend?this.mask.fill(255,0,0,t/2):(this.c.setAlpha(t),this.mask.fill(this.c))},isInsideClippingArea(){return!x.cr||this.position.x>=x.cr[0]&&this.position.x<=x.cr[2]&&this.position.y>=x.cr[1]&&this.position.y<=x.cr[3]},drawSpray(t){let e=this.w*this.p.vibration*t+this.w*randomGaussian()*this.p.vibration/3,i=this.p.weight*n.random(.9,1.1);const s=this.p.quality/t;for(let t=0;t<s;t++){let t=n.random(.9,1.1),s=t*e*n.random(-1,1),r=n.random(-1,1),o=Math.pow(t*e,2),a=Math.sqrt(o-Math.pow(s,2));this.mask.circle(this.position.x+s,this.position.y+r*a,i)}},drawMarker(t,e=!0){let i=e?this.w*this.p.vibration:0,s=e?i*n.random(-1,1):0,r=e?i*n.random(-1,1):0;this.mask.circle(this.position.x+s,this.position.y+r,this.w*this.p.weight*t)},drawCustomOrImage(t,e,i=!0){this.mask.push();let s=i?this.w*this.p.vibration:0,r=i?s*n.random(-1,1):0,o=i?s*n.random(-1,1):0;this.mask.translate(this.position.x+r,this.position.y+o),this.adjustSizeAndRotation(this.w*t,e),this.p.tip(),this.mask.pop()},drawDefault(t){let e=this.w*this.p.vibration*(this.p.definition+(1-this.p.definition)*randomGaussian()*this.gauss(.5,.9,5,.2,1.2)/t);n.random(0,this.p.quality)>.4&&this.mask.circle(this.position.x+.7*e*n.random(-1,1),this.position.y+e*n.random(-1,1),t*this.p.weight*this.w*n.random(.85,1.15))},adjustSizeAndRotation(t,e){if(this.mask.scale(t),"image"===this.p.type&&(this.p.blend?this.mask.tint(255,0,0,e/2):this.mask.tint(this.mask.red(this.c),this.mask.green(this.c),this.mask.blue(this.c),e)),"random"===this.p.rotate)this.mask.rotate(n.randInt(0,360));else if("natural"===this.p.rotate){let t=(this.plot?-this.plot.angle(this.position.plotted):-this.dir)+(this.flow?this.position.angle():0);t=this.plot?-this.plot.angle(this.position.plotted):-this.dir,this.mask.rotate(t)}},markerTip(){if(this.isInsideClippingArea()){let t=this.calculatePressure(),e=this.calculateAlpha(t);if(this.mask.fill(255,0,0,e/1.5),"marker"===x.p.type)for(let e=1;e<5;e++)this.drawMarker(t*e/5,!1);else if("custom"===x.p.type||"image"===x.p.type)for(let i=1;i<5;i++)this.drawCustomOrImage(t*i/5,e,!1)}}};const y={tips:new Map,add(t){this.tips.set(t,!1)},imageToWhite(t){t.loadPixels();for(let e=0;e<4*t.width*t.height;e+=4){let i=(t.pixels[e]+t.pixels[e+1]+t.pixels[e+2])/3;t.pixels[e]=t.pixels[e+1]=t.pixels[e+2]=255,t.pixels[e+3]=255-i}t.updatePixels()},load(){if(0===this.tips.size)return console.log("There are no custom tips to load !");for(let t of this.tips.keys()){let e=loadImage(t,(()=>y.imageToWhite(e)));this.tips.set(t,e)}}};function w(t=5,e=45,i={rand:!1,continuous:!1,gradient:!1}){_.isActive=!0,_.hatchingParams=[t,e,i]}const _={isActive:!1,hatchingParams:[5,45,{}],hatchingBrush:!1,hatch(t){let e=_.hatchingParams[0],i=_.hatchingParams[1],s=_.hatchingParams[2],r=x.c,o=x.name,a=x.w,h=x.isActive;_.hatchingBrush&&x.set(_.hatchingBrush[0],_.hatchingBrush[1],_.hatchingBrush[2]),i=n.toDegrees(i)%180;let l=1/0,c=-1/0,d=1/0,p=-1/0,m=t=>{for(let e of t.a)l=e[0]<l?e[0]:l,c=e[0]>c?e[0]:c,d=e[1]<d?e[1]:d,p=e[1]>p?e[1]:p};Array.isArray(t)||(t=[t]);for(let e of t)m(e);let f=new k([[l,d],[c,d],[c,p],[l,p]]),u=i<=90&&i>=0?d:p,g=s.gradient?map(s.gradient,0,1,1,1.1,!0):1,v=[],y=0,w=e,b=t=>({point1:{x:l+w*t*n.cos(90-i),y:u+w*t*n.sin(90-i)},point2:{x:l+w*t*n.cos(90-i)+n.cos(-i),y:u+w*t*n.sin(90-i)+n.sin(-i)}});for(;f.intersect(b(y)).length>0;){let e=[];for(let i of t)e.push(i.intersect(b(y)));v[y]=e.flat().sort(((t,e)=>t.x===e.x?t.y-e.y:t.x-e.x)),w*=g,y++}let z=[];for(let t of v)void 0!==t[0]&&z.push(t);let M=s.rand||0;for(let t=0;t<z.length;t++){let i=z[t],r=t>0&&s.continuous;for(let s=0;s<i.length-1;s+=2)0!==M&&(i[s].x+=M*e*n.random(-1,1),i[s].y+=M*e*n.random(-1,1),i[s+1].x+=M*e*n.random(-1,1),i[s+1].y+=M*e*n.random(-1,1)),x.line(i[s].x,i[s].y,i[s+1].x,i[s+1].y),r&&x.line(z[t-1][1].x,z[t-1][1].y,i[s].x,i[s].y)}x.set(o,r,a),x.isActive=h}};class k{constructor(t){this.a=t,this.vertices=t.map((t=>({x:t[0],y:t[1]}))),this.sides=this.vertices.map(((t,e,i)=>[t,i[(e+1)%i.length]]))}intersect(t){let e=`${t.point1.x},${t.point1.y}-${t.point2.x},${t.point2.y}`;if(this._intersectionCache&&this._intersectionCache[e])return this._intersectionCache[e];let i=[];for(let e of this.sides){let s=a(t.point1,t.point2,e[0],e[1]);!1!==s&&i.push(s)}return this._intersectionCache||(this._intersectionCache={}),this._intersectionCache[e]=i,i}draw(t=!1,e,i){let s=x.isActive;if(t&&x.set(t,e,i),x.isActive){r();for(let t of this.sides)x.line(t[0].x,t[0].y,t[1].x,t[1].y)}x.isActive=s}fill(t=!1,e,i,s,n){let o=D.isActive;t&&(I(t,e),B(i,s,n)),D.isActive&&(r(),D.fill(this)),D.isActive=o}hatch(t=!1,e,i){let s=_.isActive;t&&w(t,e,i),_.isActive&&(r(),_.hatch(this)),_.isActive=s}}class b{constructor(t){this.segments=[],this.angles=[],this.pres=[],this.type=t,this.dir=0,this.calcIndex(0),this.pol=!1}addSegment(t=0,e=0,i=1,s=!1){this.angles.length>0&&this.angles.splice(-1),t=n.toDegrees(t),this.angles.push(t),this.pres.push(i),this.segments.push(e),this.length=this.segments.reduce(((t,e)=>t+e),0),this.angles.push(t)}endPlot(t=0,e=1,i=!1){this.angles.splice(-1),this.angles.push(n.toDegrees(t)),this.pres.push(e)}rotate(t){this.dir=n.toDegrees(t)}pressure(t){return t>this.length?this.pres[this.pres.length-1]:this.curving(this.pres,t)}angle(t){return t>this.length?this.angles[this.angles.length-1]:(this.calcIndex(t),"curve"===this.type?this.curving(this.angles,t)+this.dir:this.angles[this.index]+this.dir)}curving(t,e){let i=t[this.index],s=t[this.index+1];return void 0===s&&(s=i),Math.abs(s-i)>180&&(s>i?s=-(360-s):i=-(360-i)),n.map(e-this.suma,0,this.segments[this.index],i,s,!0)}calcIndex(t){this.index=-1,this.suma=0;let e=0;for(;e<=t;)this.suma=e,e+=this.segments[this.index+1],this.index++}genPol(t,e,i=1,s=!1){r();let o=0,a=9999;for(let t of this.segments)t*=i,0!==t&&(o=Math.max(o,t),a=Math.min(a,t));let h=x.spacing(),l=[],c=n.constrain(D.bleed_strength,.05,1),d=(o+a)*(s?.03:D.isAnimated?.25:c),p=new u(t,e),m=Math.round(this.length/h);for(let t=0;t<m;t++)p.x&&(l[Math.floor(p.plotted/d)]=[p.x,p.y]),p.plotTo(this,h,h,1);return this.calcIndex(0),new k(l)}draw(t,e,i){x.isActive&&(r(),this.origin&&(t=this.origin[0],e=this.origin[1],i=1),x.flowShape(this,t,e,i))}fill(t,e,i){D.isActive&&(r(),this.origin&&(t=this.origin[0],e=this.origin[1],i=1),this.pol||(this.pol=this.genPol(t,e,i)),this.pol.fill())}hatch(t,e,i){_.isActive&&(r(),this.origin&&(t=this.origin[0],e=this.origin[1],i=1),this.pol||(this.pol=this.genPol(t,e,i,!0)),this.pol.hatch())}}let z,M=!1;function A(t){z=t,M=[]}function S(t,e,i){M.push([t,e,i])}function C(t){t===CLOSE&&M.push(M[0]);let e=P(M,z);(D.isActive||_.isActive)&&(e.fill(),e.hatch()),x.isActive&&e.draw(),M=!1}function P(t,e=.5){let i=new b(0===e?"segments":"curve");if(t&&t.length>0){i.origin=t[0];let s=0;for(let r=0;r<t.length-1;r++)if(e>0&&r<t.length-2){let o=t[r],l=t[r+1],c=t[r+2],d=dist(o[0],o[1],l[0],l[1]),p=dist(l[0],l[1],c[0],c[1]),m=h(o[0],o[1],l[0],l[1]),f=h(l[0],l[1],c[0],c[1]),u=e*Math.min(Math.min(d,p),.5*Math.min(d,p)),g=Math.max(d,p),v=d-u,x=p-u;if(Math.floor(m)===Math.floor(f))i.addSegment(m,v,o[2],!0),i.addSegment(f,p,l[2],!0);else{let e={x:l[0]-u*n.cos(-m),y:l[1]-u*n.sin(-m)},h={x:e.x+g*n.cos(90-m),y:e.y+g*n.sin(90-m)},c={x:l[0]+u*n.cos(-f),y:l[1]+u*n.sin(-f)},d=a(e,h,c,{x:c.x+g*n.cos(90-f),y:c.y+g*n.sin(90-f)},!0),p=dist(e.x,e.y,d.x,d.y),y=dist(e.x,e.y,c.x,c.y)/2,w=2*asin(y/p),_=2*Math.PI*p*w/360;i.addSegment(m,v-s,o[2],!0),i.addSegment(m,_,o[2],!0),i.addSegment(f,r===t.length-3?x:0,l[2],!0),s=u}r==t.length-3&&i.endPlot(f,l[2],!0)}else if(0===e){let e=t[r],s=t[r+1],n=dist(e[0],e[1],s[0],s[1]),o=h(e[0],e[1],s[0],s[1]);i.addSegment(o,n,1,!0),r==t.length-2&&i.endPlot(o,1,!0)}}return i}function I(t,e,i,s){D.opacity=arguments.length<4?arguments.length<3?e:1:s,D.color=arguments.length<3?color(t):color(t,e,i),D.isActive=!0}function B(t,e=.4,i=.4){D.bleed_strength=n.constrain(t,0,.6),D.texture_strength=n.constrain(e,0,1),D.border_strength=n.constrain(i,0,1)}const D={isActive:!1,isAnimated:!1,color:"#002185",opacity:80,bleed_strength:.07,texture_strength:.4,border_strength:.4,fill(t){this.v=t.a.map((t=>createVector(t[0],t[1])));const e=this.v.length*n.random(.4);D.m=this.v.map(((t,i)=>{let s=n.random(.8,1.2)*this.bleed_strength;return i<e?constrain(2*s,0,.9):s}));let i=n.randInt(0,this.v.length);this.v=[...this.v.slice(i),...this.v.slice(0,i)],new E(this.v,this.m,this.calcCenter()).fill(this.color,int(map(this.opacity,0,155,0,20,!0)),this.texture_strength)},calcCenter(){let t=0,e=0;for(let i=0;i<this.v.length;++i)t+=this.v[i].x,e+=this.v[i].y;return t/=this.v.length,e/=this.v.length,createVector(t,e)}};class E{constructor(t,e,i){this.v=t,this.m=e,this.midP=i,this.size=p5.Vector.sub(this.midP,this.v[0]).mag()}grow(t,e=!1){const i=[],s=[];let r=t>=.2&&this.v.length>=10?Math.floor(t*this.v.length):this.v.length;const n=t=>t+.1*(randomGaussian(.5,.1)-.5),o="radians"===angleMode()?Math.PI/180:1;for(let a=0;a<r;a++){const h=this.v[a],l=this.v[(a+1)%r];let c=.1===t?D.bleed_strength<=.1?.25:.75:this.m[a];e&&(c*=-.5),i.push(h),s.push(n(c));let d=p5.Vector.lerp(h,l,constrain(randomGaussian(.5,.2),.1,.9)),p=p5.Vector.sub(l,h),m=p.copy().normalize(),f=45*randomGaussian(0,.4)-90;m.rotate(f*o),m.mult(randomGaussian(.5,.2)*random(.6,1.4)*p.mag()*c),d.add(m),i.push(d),s.push(n(c))}return new E(i,s,this.midP)}fill(t,i,s){const r=i/5+s*i/6,n=i/4+s*i/3,a=i/7+s*i/3,h=i/5,l=3*s;o.trans(),p.blend(t,!1,!1,!0),p.mask.push(),p.mask.noStroke(),p.mask.translate(o.translation[0]+e.width/2,o.translation[1]+e.height/2),p.mask.rotate(o.rotation);let c=this.grow(),d=c.grow().grow(.9),m=d.grow(.75),f=this.grow(.85);for(let t=0;t<24;t++)t!==Math.floor(6)&&t!==Math.floor(12)&&t!==Math.floor(18)||(c=c.grow(),d=d.grow(.75),m=m.grow(.75),f=f.grow(.1,!0)),c.grow().layer(t,h),f.grow(.1,!0).grow(.1).layer(t,a,!1),d.grow(.1).grow(.1).layer(t,n,!1),m.grow(.8).grow(.1).layer(t,r,!1),0!==l&&c.erase(l);p.mask.pop()}layer(t,e,i=!0){p.mask.fill(255,0,0,e),i?(p.mask.stroke(255,0,0,.5+1.5*D.border_strength),p.mask.strokeWeight(n.map(t,0,24,6,.5))):p.mask.noStroke(),p.mask.beginShape();for(let t of this.v)p.mask.vertex(t.x,t.y);p.mask.endShape(CLOSE)}erase(t){const e=n.random(80,110),i=this.size/2,s=.025*this.size,r=.19*this.size;p.mask.erase(3.5*t,0);for(let t=0;t<e;t++){const t=this.midP.x+randomGaussian(0,i),e=this.midP.y+randomGaussian(0,i),o=n.random(s,r);p.mask.circle(t,e,o)}p.mask.noErase()}}p5.RendererGL.prototype.erase=function(t,e){this._isErasing||(this._cachedBlendMode=this.curBlendMode,this._isErasing=!0,this.blendMode("destination-out"),this._cachedFillStyle=this.curFillColor.slice(),this.curFillColor=[1,1,1,t/255],this._cachedStrokeStyle=this.curStrokeColor.slice(),this.curStrokeColor=[1,1,1,e/255])},p5.RendererGL.prototype.noErase=function(){if(this._isErasing){this.curFillColor=this._cachedFillStyle.slice(),this.curStrokeColor=this._cachedStrokeStyle.slice();let t=this.curBlendMode;this.blendMode(this._cachedBlendMode),this._cachedBlendMode=t,this._isErasing=!1,this._applyBlendMode()}};const F=[["pen",{weight:.35,vibration:.12,definition:.5,quality:8,opacity:200,spacing:.3,pressure:{curve:[.15,.2],min_max:[1.3,1]}}],["rotring",{weight:.2,vibration:.05,definition:1,quality:3,opacity:250,spacing:.15,pressure:{curve:[.05,.2],min_max:[1.2,.95]}}],["2B",{weight:.35,vibration:.5,definition:.1,quality:8,opacity:180,spacing:.2,pressure:{curve:[.15,.2],min_max:[1.3,1]}}],["HB",{weight:.3,vibration:.5,definition:.4,quality:4,opacity:180,spacing:.25,pressure:{curve:[.15,.2],min_max:[1.2,.9]}}],["2H",{weight:.2,vibration:.4,definition:.3,quality:2,opacity:150,spacing:.2,pressure:{curve:[.15,.2],min_max:[1.2,.9]}}],["cpencil",{weight:.4,vibration:.6,definition:.8,quality:7,opacity:120,spacing:.15,pressure:{curve:[.15,.2],min_max:[.95,1.15]}}],["charcoal",{weight:.5,vibration:2,definition:.8,quality:300,opacity:110,spacing:.06,pressure:{curve:[.15,.2],min_max:[1.15,.85]}}],["hatch_brush",{weight:.2,vibration:.4,definition:.3,quality:2,opacity:150,spacing:.15,pressure:{curve:[.5,.7],min_max:[1,1.5]}}],["spray",{type:"spray",weight:.3,vibration:12,definition:15,quality:40,opacity:120,spacing:.65,pressure:{curve:[0,.1],min_max:[.15,1.2]}}],["marker",{type:"marker",weight:2.5,vibration:.12,opacity:30,spacing:.4,pressure:{curve:[.35,.25],min_max:[1.35,1]}}],["marker2",{type:"custom",weight:2.5,vibration:.12,opacity:25,spacing:.35,pressure:{curve:[.35,.25],min_max:[1.15,.95]},tip:function(){let t=v;x.mask.rect(-1.5*t,-1.5*t,3*t,3*t),x.mask.rect(1*t,1*t,1*t,1*t)},rotate:"natural"}]];for(let t of F)x.add(t[0],t[1]);t.config=function(t={}){t.R&&(n.source=t.R)},t.load=s,t.preload=function(){y.load()},t.colorCache=function(t=!0){p.isCaching=t},t.reDraw=p.reDraw,t.reBlend=p.reBlend,t.push=c,t.pop=d,t.rotate=o.rotate,t.addField=m,t.field=function(t){r(),f.isActive=!0,f.current=t},t.noField=function(){f.isActive=!1},t.refreshField=function(t){f.refresh(t)},t.listFields=function(){return Array.from(f.list.keys())},t.scale=g,t.add=x.add,t.box=function(){return Array.from(x.list.keys())},t.set=x.set,t.pick=x.setBrush,t.clip=x.clip,t.noClip=x.noClip,t.point=function(t,e,i){r(),x.position=new u(t,e),x.drawTip(i)},t.stroke=x.setColor,t.strokeWeight=x.setWeight,t.noStroke=function(){x.isActive=!1},t.fill=I,t.bleed=B,t.noFill=function(){D.isActive=!1},t.fillAnimatedMode=function(t){D.isAnimated=t},t.line=x.line,t.flowLine=x.flowLine,t.plot=x.flowShape,t.rect=function(t,e,i,s,r=CORNER){if(r==CENTER&&(t-=i/2,e-=s/2),f.isActive)A(0),S(t,e),S(t+i,e),S(t+i,e+s),S(t,e+s),C(CLOSE);else{let r=new k([[t,e],[t+i,e],[t+i,e+s],[t,e+s]]);r.fill(),r.hatch(),r.draw()}},t.circle=function(t,e,i,s=!1){let r=new b("curve"),o=Math.PI*i/2,a=random(0,360),h=()=>s?n.random(-1,1):0;r.addSegment(0+a+h(),o+h(),1,!0),r.addSegment(-90+a+h(),o+h(),1,!0),r.addSegment(-180+a+h(),o+h(),1,!0),r.addSegment(-270+a+h(),o+h(),1,!0);let l=s?n.randInt(-5,5):0;s&&r.addSegment(0+a,l*(Math.PI/180)*i,!0),r.endPlot(l+a,1,!0),r.fill(t-i*n.sin(a),e-i*n.cos(-a),1),r.hatch(t-i*n.sin(a),e-i*n.cos(-a),1),r.draw(t-i*n.sin(a),e-i*n.cos(-a),1)},t.polygon=function(t){if(!Array.isArray(t)||t.length<3)return void console.error("Invalid input for polygon: An array with at least 3 points is required.");let e=new k(t);e.fill(),e.hatch(),e.draw()},t.spline=function(t,e=.5){P(t,e).draw()},t.beginShape=A,t.vertex=S,t.endShape=C,t.beginStroke=function(t,e,i){z=[e,i],M=new b(t)},t.segment=function(t,e,i){M.addSegment(t,e,i)},t.endStroke=function(t,e){M.endPlot(t,e),M.draw(z[0],z[1],1),M=!1},t.hatchArray=_.hatch,t.hatch=w,t.setHatch=function(t,e="black",i=1){_.hatchingBrush=[t,e,i]},t.noHatch=function(){_.isActive=!1,_.hatchingBrush=!1},t.Polygon=k,t.Plot=b,t.Position=u}));
\ No newline at end of file