Skip to content
Apexify.jsDocs
Apexify.js version v5.4.5

Node / Canvas · guide

Patterns & film noise

Current Apexify.js 6.0.0 documentation for Patterns & film noise.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

Use await painter.createCanvas(config) with fields on CanvasConfig (apexify.js). Patterns and noise are not separate ApexPainter methods — they are pure config: either top-level patternBg / noiseBg, or entries inside bgLayers[].


Paint order (what goes on top)

Inside CanvasCreator, after clipping and optional zoom, backgrounds are painted in this fixed order:

  1. Exactly one primary fill — videoBg, or customBg, or gradientBg, or colorBg, or transparentBase: true (no automatic fill), or default opaque #000 if you set none of those.
  2. bgLayers[] — each layer in array order (bottom → top). Supports color, gradient, image, pattern (tiled bitmap), presetPattern (procedural PatternOptions), and noise.
  3. patternBg — full-canvas procedural pattern (PatternOptions). Runs after every bgLayers row.
  4. noiseBg — film grain overlay (applyNoise). Runs last among background paints (still before canvas shadow / stroke).

So: patternBg is never “between” two bgLayers — if you need a pattern sandwiched between colors, model it as bgLayers (presetPattern / pattern) or reorder bgLayers + skip patternBg.

See also Paint order for the full pipeline.


Three pattern mechanisms (do not mix them up)

MechanismWhereWhat it drawsBlend default
patternBgTop-level CanvasConfigProcedural mesh from PatternOptions (EnhancedPatternRenderer)If pattern.blendMode is omitted → overlay
bgLayers[] presetPatternLayer stackSame procedural renderer as patternBg, but scoped like any other layerstackedInLayer: true → missing blendMode does not force overlay; uses normal source-over unless you set pattern.blendMode or layer.blendMode
bgLayers[] patternLayer stackcreatePattern over a loaded image (source path/URL); tiled (repeat)Standard layer opacity / blendMode

Summary

  • Want a dots / grid / stripes overlay drawn after all bgLayers? → patternBg.
  • Want that between an image wash and a vignette? → bgLayers with presetPattern (and optional blendMode per layer).
  • Want your own seamless PNG/JPG tiled? → bgLayers type: "pattern" with source + repeat.

patternBg — procedural overlay after bgLayers

Type: PatternOptions (see catalog below). Typical use: subtle texture on top of colorBg or stacked bgLayers.

SOURCEtypescript
typescript
Studio
import { ApexPainter } from "apexify.js"; const painter = new ApexPainter({ type: "buffer" }); const { buffer } = await painter.createCanvas({  width: 640,  height: 360,  colorBg: "#0f172a",  bgLayers: [    { type: "gradient", value: { type: "linear", rotate: 135, colors: [{ stop: 0, color: "#1e293b" }, { stop: 1, color: "#020617" }] } },  ],  patternBg: {    type: "dots",    color: "#ffffff",    size: 14,    spacing: 22,    opacity: 0.12,    blendMode: "soft-light",  },});

If you omit blendMode on patternBg, the renderer defaults to overlay so light textures sit on photographs or gradients without repainting the whole canvas math yourself.


bgLayers — presetPattern vs pattern

presetPattern (vector-style presets)

Same PatternOptions as patternBg, but honours stack order and per-layer opacity / blendMode.

SOURCEtypescript
typescript
Studio
await painter.createCanvas({  width: 400,  height: 240,  colorBg: "#020617",  bgLayers: [    {      type: "presetPattern",      opacity: 0.35,      blendMode: "multiply",      pattern: {        type: "stripes",        color: "#38bdf8",        secondaryColor: "#0ea5e9",        size: 12,        spacing: 8,        rotation: 12,      },    },    { type: "color", value: "rgba(2, 6, 23, 0.35)", blendMode: "source-over" },  ],});

pattern (tiled bitmap)

Loads source as an image (path / URL resolved like other backgrounds), builds a CanvasPattern, fills the canvas.

SOURCEtypescript
typescript
Studio
await painter.createCanvas({  width: 500,  height: 280,  colorBg: "#f8fafc",  bgLayers: [    {      type: "pattern",      source: "./assets/seamless-noise.png",      repeat: "repeat",      opacity: 0.4,    },  ],});

PatternOptions — type catalogue

Common fields across types (defaults vary per type): color, secondaryColor, opacity, size, spacing, rotation, offsetX, offsetY, blendMode, gradient. custom additionally uses customPatternImage, repeat, scale.

typeRole
gridLine grid (size ≈ cell feel; spacing gap between lines).
dotsFilled dots on a lattice.
diagonalDiagonal hatch lines.
stripesHorizontal stripes alternating color / secondaryColor.
wavesSinusoidal strokes.
crossesCross / plus motifs.
hexagonsHex lattice outline fill.
checkerboardChecker squares.
diamondsDiamond tessellation.
trianglesTriangle motif tiling.
starsStar shapes on a grid.
polkaLarger “polka” dots variant.
customTile customPatternImage manually (scale, repeat like repeat-x).

Import typings from apexify.js / apexify.js/types — PatternOptions ships with the package.


Noise — noiseBg vs bgLayers noise

Both call the same applyNoise helper: random grayscale pixels drawn into a scratch bitmap, then drawImage onto the canvas; intensity scales alpha (255 * intensity per pixel).

LocationDefault intensity if omitted
noiseBg0.05
bgLayers { type: "noise" }0.08

Top-level noiseBg runs after patternBg. A noise inside bgLayers runs where that layer sits in the stack — use it for grain between washes without affecting layers above.

SOURCEtypescript
typescript
Studio
await painter.createCanvas({  width: 480,  height: 270,  colorBg: "#111827",  patternBg: { type: "grid", color: "#94a3b8", opacity: 0.08, size: 24, spacing: 16 },  noiseBg: { intensity: 0.06 },});

Transparent canvases

With transparentBase: true, there is no automatic colorBg fill — compose visibility only via bgLayers, patternBg, and noiseBg. See Transparent base.


Types reference

  • PatternOptions — procedural / custom tiled presets.
  • BackgroundLayer — union for bgLayers (color, gradient, image, pattern, presetPattern, noise).
  • CanvasConfig — patternBg, noiseBg, bgLayers.

Next steps