Unlock custom brushes, natural fill effects and intuitive hatching in p5.js
Test profiling
acamposuribe66631ebf9c32
diff --git a/test/angle_mode_test.html b/test/angle_mode_test.htmlindex daab7bb..5b7e7a1 100644--- a/test/angle_mode_test.html+++ b/test/angle_mode_test.html@@ -6,6 +6,7 @@<title>p5.brush - Angle Mode Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>* {box-sizing: border-box;diff --git a/test/angle_mode_test.js b/test/angle_mode_test.jsindex 257c37b..ed499cf 100644--- a/test/angle_mode_test.js+++ b/test/angle_mode_test.js@@ -250,10 +250,8 @@ function renderFlowLinePanel(x, y, w, h, mode, angleValue) {angleMode(mode);brush.noField();- brush.clip([x, y, x + w, y + h]);brush.set("pen", INK, 1.8);brush.flowLine(startX, startY, len, angleValue);- brush.noClip();angleMode(DEGREES);}@@ -282,10 +280,8 @@ function renderManualStrokePanel(x, y, w, h, runner) {drawReferencePolyline(startX, startY, steps);- brush.clip([x, y, x + w, y + h]);brush.set("2B", INK, 1.7);runner(startX, startY, steps);- brush.noClip();angleMode(DEGREES);}@@ -301,12 +297,10 @@ function renderPositionPanel(x, y, w, h, runner) {brush.noField();const pts = runner(startX, startY, steps);- brush.clip([x, y, x + w, y + h]);brush.set("marker", INK, 1.05);for (let i = 0; i < pts.length - 1; i++) {brush.line(pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y);}- brush.noClip();drawReferencePolyline(startX, startY, steps, {dashed: true,@@ -350,9 +344,7 @@ function renderHatchPanel(x, y, w, h, setupHatch, referenceAngleDeg = 45) {brush.noFill();brush.hatchStyle("pen", INK, 1.35);setupHatch();- brush.clip([x, y, x + w, y + h]);brush.rect(rx, ry, rw, rh, "corner");- brush.noClip();brush.noHatch();angleMode(DEGREES);}@@ -364,13 +356,11 @@ function renderFieldPanel(x, y, w, h, mode, fieldName) {angleMode(mode);brush.field(fieldName);- brush.clip([x, y, x + w, y + h]);brush.set("pen", ALT, 1.45);for (let i = 0; i < lines; i++) {const sy = y + 12 + (i / (lines - 1)) * (h - 24);brush.flowLine(startX, sy, len, 0);}- brush.noClip();brush.noField();angleMode(DEGREES);}@@ -580,4 +570,5 @@ function draw() {]);image(labelBuf, 0, 0);+ window.reportP5FirstFrame?.("angle_mode_test");}diff --git a/test/field_explorer.html b/test/field_explorer.htmlindex 6855636..792e85a 100644--- a/test/field_explorer.html+++ b/test/field_explorer.html@@ -6,6 +6,7 @@<title>Flow Field Explorer</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>:root {--paper: #f3eee2;@@ -279,6 +280,7 @@needsRender = false;noLoop();renderExplorer();+ window.reportP5FirstFrame?.("field_explorer");}</script></main>diff --git a/test/fill_circle_explorer.html b/test/fill_circle_explorer.htmlindex d363cbf..b884066 100644--- a/test/fill_circle_explorer.html+++ b/test/fill_circle_explorer.html@@ -6,6 +6,7 @@<title>Fill Circle Explorer</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>:root {--paper: #f3eee2;diff --git a/test/fill_circle_explorer.js b/test/fill_circle_explorer.jsindex b950997..5251a98 100644--- a/test/fill_circle_explorer.js+++ b/test/fill_circle_explorer.js@@ -30,10 +30,7 @@ const controls = {let needsRender = true;let renderQueued = false;-let firstLoadReported = false;-const firstLoadStart =- performance.getEntriesByType("navigation")[0]?.domContentLoadedEventEnd ??- performance.now();+let urlSyncQueued = false;function formatValue(value) {return Number.isInteger(value) ? String(value) : value.toFixed(2).replace(/0$/, "").replace(/\.$/, "");@@ -60,7 +57,18 @@ function syncUrl() {color: state.color,seed: String(state.seed),});- history.replaceState(null, "", `?${qs.toString()}`);+ const nextSearch = `?${qs.toString()}`;+ if (location.search === nextSearch) return;+ history.replaceState(null, "", nextSearch);+}++function queueUrlSync() {+ if (urlSyncQueued) return;+ urlSyncQueued = true;+ requestAnimationFrame(() => {+ urlSyncQueued = false;+ syncUrl();+ });}function syncReadouts() {@@ -88,14 +96,7 @@ function queueRender() {}function reportFirstLoad() {- if (firstLoadReported) return;- firstLoadReported = true;- requestAnimationFrame(() => {- const total = performance.now() - firstLoadStart;- const text = `${total.toFixed(1)} ms`;- controls.firstLoadVal.textContent = text;- console.log(`fill_circle_explorer first load: ${text}`);- });+ window.reportP5FirstFrame?.("fill_circle_explorer");}function setupPalette() {@@ -109,7 +110,7 @@ function setupPalette() {btn.addEventListener("click", () => {state.color = color;syncPalette();- syncUrl();+ queueUrlSync();queueRender();});controls.palette.appendChild(btn);@@ -121,7 +122,7 @@ function bindSlider(key, input, readout) {input.addEventListener("input", () => {state[key] = Number(input.value);readout.textContent = formatValue(state[key]);- syncUrl();+ queueUrlSync();queueRender();});}@@ -148,7 +149,7 @@ bindSlider("border", controls.border, controls.borderVal);controls.refreshSeed.addEventListener("click", () => {state.seed = 100000 + Math.floor(Math.random() * 900000);syncReadouts();- syncUrl();+ queueUrlSync();queueRender();});diff --git a/test/hatch_test.html b/test/hatch_test.htmlindex 8eac72c..f4aa0b8 100644--- a/test/hatch_test.html+++ b/test/hatch_test.html@@ -6,6 +6,7 @@<title>p5.brush Hatch Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>* { box-sizing: border-box; }diff --git a/test/hatch_test.js b/test/hatch_test.jsindex ceab52b..bb31eae 100644--- a/test/hatch_test.js+++ b/test/hatch_test.js@@ -96,9 +96,7 @@ function hatchInPanel(x, y, w, h, polyFn, hatchSetup, brushName, brushColor) {brush.noFill();hatchSetup();brush.hatchStyle(brushName || "HB", brushColor || INK, 1);- brush.clip([x, y, x + w, y + h]);poly.hatch();- brush.noClip();brush.noHatch();}@@ -283,15 +281,13 @@ function draw() {brush.hatch(8, cp.a1);brush.hatchStyle("HB", col(i * 2), 1);- brush.clip([x, y, x + w, y + h]);poly.hatch();- brush.noClip(); brush.noHatch();+ brush.noHatch();brush.hatch(8, cp.a2);brush.hatchStyle("HB", col(i * 2 + 1), 1);- brush.clip([x, y, x + w, y + h]);poly.hatch();- brush.noClip(); brush.noHatch();+ brush.noHatch();},})));@@ -349,4 +345,5 @@ function draw() {// ================================================================image(labelBuf, 0, 0);console.log("Hatch test complete");+ window.reportP5FirstFrame?.("hatch_test");}diff --git a/test/instance_mode_test.html b/test/instance_mode_test.htmlindex 9b13c63..d06a6db 100644--- a/test/instance_mode_test.html+++ b/test/instance_mode_test.html@@ -6,6 +6,7 @@<title>p5.brush - Instance Mode Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>* {box-sizing: border-box;diff --git a/test/instance_mode_test.js b/test/instance_mode_test.jsindex 5250b94..68bf14a 100644--- a/test/instance_mode_test.js+++ b/test/instance_mode_test.js@@ -280,6 +280,7 @@ const sketch = (p) => {}p.image(labelBuf, 0, 0)+ window.reportP5FirstFrame?.("instance_mode_test")}}diff --git a/test/multi_instance_async_test.html b/test/multi_instance_async_test.htmlindex 5f74187..f6ab59e 100644--- a/test/multi_instance_async_test.html+++ b/test/multi_instance_async_test.html@@ -6,6 +6,7 @@<title>p5.brush - Async Multi-Instance Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>:root {--bg: #f4efe6;diff --git a/test/multi_instance_async_test.js b/test/multi_instance_async_test.jsindex 2f418f9..b4c99f9 100644--- a/test/multi_instance_async_test.js+++ b/test/multi_instance_async_test.js@@ -271,6 +271,9 @@ function createWorker(runId, scenario, index) {}scenario.completedPasses++;+ if (scenario.completedPasses === 1) {+ window.reportP5FirstFrame?.("multi_instance_async_test");+ }worker.nextPass++;worker.pendingSample = null;updateWorkerLog(diff --git a/test/offscreen_target_test.html b/test/offscreen_target_test.htmlindex 25b187a..181aa4e 100644--- a/test/offscreen_target_test.html+++ b/test/offscreen_target_test.html@@ -6,6 +6,7 @@<title>p5.brush - Offscreen Target Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>* {box-sizing: border-box;diff --git a/test/offscreen_target_test.js b/test/offscreen_target_test.jsindex 6efc971..2b53cdf 100644--- a/test/offscreen_target_test.js+++ b/test/offscreen_target_test.js@@ -381,4 +381,5 @@ function draw() {}image(labelBuf, 0, 0)+ window.reportP5FirstFrame?.("offscreen_target_test")}diff --git a/test/p5_first_frame_profiler.js b/test/p5_first_frame_profiler.jsnew file mode 100644index 0000000..3f73b14--- /dev/null+++ b/test/p5_first_frame_profiler.js@@ -0,0 +1,56 @@+(() => {+ const start =+ performance.getEntriesByType("navigation")[0]?.domContentLoadedEventEnd ??+ performance.now();++ let reported = false;+ let badge = null;++ function ensureBadge() {+ if (document.getElementById("firstLoadVal")) return null;+ if (badge) return badge;+ if (!document.body) return null;++ badge = document.createElement("div");+ badge.id = "p5-first-load-badge";+ badge.style.position = "fixed";+ badge.style.top = "12px";+ badge.style.right = "12px";+ badge.style.zIndex = "9999";+ badge.style.padding = "8px 10px";+ badge.style.border = "1px solid rgba(48, 41, 30, 0.14)";+ badge.style.borderRadius = "8px";+ badge.style.background = "rgba(255, 252, 245, 0.9)";+ badge.style.color = "#153e5c";+ badge.style.font = '11px/1.4 Menlo, Monaco, "Courier New", monospace';+ badge.style.boxShadow = "0 2px 10px rgba(0, 0, 0, 0.06)";+ badge.textContent = "First load -";+ document.body.appendChild(badge);+ return badge;+ }++ function setText(text) {+ const valueEl = document.getElementById("firstLoadVal");+ if (valueEl) {+ valueEl.textContent = text;+ return;+ }+ const el = ensureBadge();+ if (el) el.textContent = `First load ${text}`;+ }++ document.addEventListener("DOMContentLoaded", () => {+ ensureBadge();+ });++ window.reportP5FirstFrame = (label = document.title || "p5 test") => {+ if (reported) return;+ reported = true;+ requestAnimationFrame(() => {+ const total = performance.now() - start;+ const text = `${total.toFixed(1)} ms`;+ setText(text);+ console.log(`${label} first load: ${text}`);+ });+ };+})();diff --git a/test/pastel_hatching_test.html b/test/pastel_hatching_test.htmlindex 5683a0e..a6edd75 100644--- a/test/pastel_hatching_test.html+++ b/test/pastel_hatching_test.html@@ -6,6 +6,7 @@<title>Pastel Hatching Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>:root {--paper: #f3eee2;diff --git a/test/pastel_hatching_test.js b/test/pastel_hatching_test.jsindex 228c02e..76c4232 100644--- a/test/pastel_hatching_test.js+++ b/test/pastel_hatching_test.js@@ -113,4 +113,5 @@ function draw() {brush.noMass();}noLoop();+ window.reportP5FirstFrame?.("pastel_hatching_test");}diff --git a/test/pushpop_test.html b/test/pushpop_test.htmlindex 1b772a6..3b5dea7 100644--- a/test/pushpop_test.html+++ b/test/pushpop_test.html@@ -6,6 +6,7 @@<title>p5.brush - Push/Pop Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>* { box-sizing: border-box; }@@ -202,6 +203,7 @@translate(cx(2), Y_AFTER);brush.rect(-55, -35, 110, 70, "corner");pop();+ window.reportP5FirstFrame?.("pushpop_test");}</script></main>diff --git a/test/sketch.js b/test/sketch.jsindex 67f8977..ddc5604 100644--- a/test/sketch.js+++ b/test/sketch.js@@ -574,5 +574,6 @@ function draw() {// WEBGL resets transforms each frame; re-translate to top-lefttranslate(-width / 2, -height / 2);if (!nativeDebugStage) image(labelBuf, 0, 0, width, height);+ window.reportP5FirstFrame?.("visual_suite");noLoop(); // static sketch — draw only once}diff --git a/test/transform_test.html b/test/transform_test.htmlindex e1193fe..0178a63 100644--- a/test/transform_test.html+++ b/test/transform_test.html@@ -6,6 +6,7 @@<title>p5.brush - Transform Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>* { box-sizing: border-box; }@@ -256,6 +257,7 @@brushFill(OLIVE);pop();pop();+ window.reportP5FirstFrame?.("transform_test");}</script></main>diff --git a/test/visual_suite.html b/test/visual_suite.htmlindex 8cd5cc3..184a6c4 100644--- a/test/visual_suite.html+++ b/test/visual_suite.html@@ -6,6 +6,7 @@<title>p5.brush Visual Suite</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>* { box-sizing: border-box; }diff --git a/test/wash_test.html b/test/wash_test.htmlindex 71e521a..7204a4a 100644--- a/test/wash_test.html+++ b/test/wash_test.html@@ -6,6 +6,7 @@<title>Wash Test</title><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script><script src="../dist/p5.brush.js"></script>+ <script src="./p5_first_frame_profiler.js"></script><style>:root {--paper: #f3eee2;diff --git a/test/wash_test.js b/test/wash_test.jsindex ad4ae4c..f92a9b8 100644--- a/test/wash_test.js+++ b/test/wash_test.js@@ -55,6 +55,7 @@ function setup() {function draw() {drawRandomWashSet();+ window.reportP5FirstFrame?.("wash_test");}refreshSeedButton.addEventListener("click", () => {