Unlock custom brushes, natural fill effects and intuitive hatching in p5.js
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<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;
--panel: rgba(255, 251, 244, 0.92);
--line: rgba(39, 52, 63, 0.12);
--ink: #24323b;
--muted: #60707c;
--accent: #9e6a39;
--ok: #2f7d54;
--bad: #b24337;
--warn: #8b6231;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
color: var(--ink);
background:
radial-gradient(circle at top left, rgba(158, 106, 57, 0.08), transparent 24%),
linear-gradient(180deg, #f8f3ea 0%, var(--bg) 100%);
font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
}
main {
width: min(1180px, calc(100vw - 24px));
margin: 0 auto;
padding: 18px 0 24px;
display: grid;
justify-items: center;
}
main > * { width: 100%; }
.nav {
margin-bottom: 14px;
font: 11px/1.2 Menlo, Monaco, "Courier New", monospace;
display: flex;
gap: 12px;
}
.nav a {
color: #254e71;
text-decoration: none;
}
.nav a:hover {
text-decoration: underline;
}
.nav .sep { color: #8a9aa8; }
h1 {
margin: 0 0 8px;
font-size: clamp(24px, 3.6vw, 34px);
letter-spacing: -0.04em;
}
p {
margin: 0 0 10px;
max-width: 860px;
color: var(--muted);
line-height: 1.45;
font-size: 13px;
}
.panel {
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel);
}
.toolbar {
display: grid;
gap: 14px;
padding: 16px;
margin: 20px 0 18px;
}
.controls {
display: flex;
gap: 10px;
flex-wrap: wrap;
align-items: center;
}
button {
border: 1px solid rgba(158, 106, 57, 0.35);
background: rgba(158, 106, 57, 0.08);
color: var(--ink);
border-radius: 8px;
padding: 9px 14px;
font: 11px/1.2 Menlo, Monaco, "Courier New", monospace;
cursor: pointer;
}
button:hover {
background: rgba(158, 106, 57, 0.14);
}
.status {
padding: 12px 14px;
border-radius: 8px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.5);
white-space: pre-wrap;
font: 11px/1.45 Menlo, Monaco, "Courier New", monospace;
}
.status.ok {
color: var(--ok);
}
.status.bad {
color: var(--bad);
}
.status.warn {
color: var(--warn);
}
.suite {
display: grid;
gap: 18px;
}
.scenario {
padding: 16px;
display: grid;
gap: 12px;
}
.scenario-head {
display: grid;
gap: 6px;
}
.scenario-head h2 {
margin: 0;
font-size: 18px;
}
.scenario-meta {
font: 11px/1.45 Menlo, Monaco, "Courier New", monospace;
color: var(--muted);
}
.worker-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
gap: 14px;
}
.worker {
border: 1px solid var(--line);
border-radius: 8px;
padding: 12px;
background: rgba(255, 255, 255, 0.58);
display: grid;
gap: 10px;
}
.worker h3 {
margin: 0;
font-size: 14px;
}
.worker p {
margin: 0;
font: 11px/1.45 Menlo, Monaco, "Courier New", monospace;
}
.canvas-shell {
min-height: 128px;
border-radius: 6px;
overflow: hidden;
border: 1px solid rgba(39, 52, 63, 0.08);
background: #f7f2e9;
display: grid;
justify-items: center;
}
.canvas-shell canvas {
display: block;
max-width: 100%;
height: auto !important;
}
.log {
min-height: 52px;
border-radius: 6px;
padding: 10px;
background: rgba(36, 50, 59, 0.04);
font: 11px/1.45 Menlo, Monaco, "Courier New", monospace;
color: var(--muted);
white-space: pre-wrap;
}
.log.ok {
color: var(--ok);
}
.log.bad {
color: var(--bad);
}
#stealer-host {
display: none;
}
</style>
</head>
<body>
<main>
<div class="nav">
<a href="../index.html">All tests</a>
<span class="sep">·</span>
<span style="color:#8a9aa8;">p5 specific</span>
</div>
<h1>Async Multi-Instance Test</h1>
<p>
This page stress-tests the old report about multiple instance-mode sketches racing on
shared global renderer state. Each worker sketch uses <b>brush.instance(p)</b>; while it
runs, tiny "stealer" sketches are created repeatedly to mimic asynchronous startup.
</p>
<p>
The first scenario matches the reported pattern more closely by binding the instance only
once in the sketch function. The second scenario rebinds before each render pass as a
control. Each worker checks both for thrown errors and for brush pixels landing on the
correct canvas.
</p>
<section class="panel toolbar">
<div class="controls">
<button type="button" onclick="runAsyncMultiInstanceSuite(6, 3)">Run 6 sketches</button>
<button type="button" onclick="runAsyncMultiInstanceSuite(10, 4)">Run 10 sketches</button>
<button type="button" onclick="runAsyncMultiInstanceSuite(14, 4)">Run 14 sketches</button>
</div>
<div id="page-status" class="status">Waiting to run.</div>
</section>
<section id="suite" class="suite"></section>
<div id="stealer-host"></div>
</main>
<script src="./multi_instance_async_test.js"></script>
<script src="../test-nav.js"></script>
</body>
</html>