Send paint to a living ink texture
Create a reaction-diffusion recipe and send a typed paint command on click.
APIs demonstrated
Section titled “APIs demonstrated”- reactionDiffusion from
@pibbl/core/textures - ReactionDiffusionOptions from
@pibbl/core/textures - InkMessage from
@pibbl/core/textures
Complete example
Section titled “Complete example”Plain source. Run as a browser module after the document body exists. TSX uses jsx: "react-jsx" and jsxImportSource: "@pibbl/core".
/** @jsxImportSource @pibbl/core */import { pibbl, Rectangle } from "@pibbl/core";import { reactionDiffusion, useTexture, type InkMessage, type ReactionDiffusionOptions,} from "@pibbl/core/textures";
const canvas = document.createElement("canvas");canvas.width = 320;canvas.height = 200;document.body.append(canvas);
function Ink() { const options: ReactionDiffusionOptions = { seed: 12, preset: "stripes" }; const texture = useTexture(reactionDiffusion(options), { resolution: { width: 128, height: 80 }, }); return ( <Rectangle style={{ width: 320, height: 200, fill: texture }} onClick={(event) => { const paint: InkMessage = { type: "paint", u: event.x / 320, v: event.y / 200, radius: 8, strength: 0.9, }; texture.send(paint); }} /> );}
const controller = pibbl(canvas, <Ink />);window.addEventListener("pagehide", () => controller.dispose(), { once: true });Usage notes
Section titled “Usage notes”- Messages are sent from the event handler, outside component evaluation.
Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.