Terrain

geometric

A heightmap is sampled with fractional Brownian motion. Character selection maps height to a density ramp (ground, rock, snow). The terrain scrolls horizontally.

Gallery

Live preview

Framework examples

TerrainBackground.tsx
import { useEffect, useRef } from 'react';
import { asciiBackground } from 'asciify-engine';

export function TerrainBackground() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (!ref.current) return;
    const { destroy } = asciiBackground(ref.current, {
      type: 'terrain',
      opacity: 0.15,
      colorScheme: 'auto',
    });
    return destroy;
  }, []);

  return (
    <div ref={ref} style={{ position: 'relative', minHeight: '100vh' }}>
      {/* your content goes here */}
    </div>
  );
}

Terrain-specific options

OptionTypeDefaultDescription
roughnessnumber0.55FBM roughness — higher = more jagged terrain.
heightScalenumber0.55Vertical height scale of the landscape.

Shared options

OptionTypeDefaultDescription
opacitynumber0.15Overall canvas opacity (0–1).
colorScheme'dark' | 'light' | 'auto''auto'Color palette. 'auto' follows prefers-color-scheme.
fontSizenumber14Character size in px — controls grid density.
speednumber1Animation speed multiplier.
interactivebooleantrueEnable mouse/pointer interaction.
zIndexnumber0CSS z-index of the injected canvas.

Direct renderer

Use the standalone render function directly in your own RAF loop for full control.

renderTerrainBackground.ts
import { renderTerrainBackground } from 'asciify-engine';

const canvas = document.querySelector('canvas')!;
const ctx = canvas.getContext('2d')!;

const colors = {
  primary:    '#d4ff00',
  secondary:  '#ffffff',
  background: '#0a0a0a',
};

const start = performance.now();

function tick() {
  const t = (performance.now() - start) / 1000;
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  renderTerrainBackground(ctx, canvas.width, canvas.height, t, colors, 0.9);
  requestAnimationFrame(tick);
}

requestAnimationFrame(tick);
Buy Me A Coffee