npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@_lowi/substrate

v0.0.1

Published

A Jared Tarbell's Substate implementation

Readme

Substrate

A modern browser implementation of Jared Tarbell's Substrate algorithm using HTML5 Canvas and Svelte 5.

npm version License: MIT

About

Lines likes crystals grow on a computational substrate. A simple perpendicular growth rule creates intricate city-like structures. — Jared Tarbell

Features

  • Canvas-based rendering - High-performance drawing using HTML5 Canvas API
  • Obstacle detection - Automatically detects and avoids HTML elements with .obstacle class.

Installation

npm install @_lowi/substrate

Or with pnpm:

pnpm add @_lowi/substrate

Usage

Basic Setup

The simplest way to use Substrate is with the built-in Svelte component:

<script>
  import { GlCanvas } from '@_lowi/substrate';
</script>

<div style="width: 100%; height: 100vh;">
  <GlCanvas />
</div>

Advanced Usage

For more control, you can use the Substrate class directly:

import { Substrate } from '@_lowi/substrate';
import { Polygon, Segment, Vector, point } from '@flatten-js/core';

// Setup canvas
const canvas = document.getElementById('myCanvas') as HTMLCanvasElement;
const dimensions = new Vector(800, 600);

// Define bounds
const topEdge = new Segment(point(0, 0), point(dimensions.x, 0));
const rightEdge = new Segment(point(dimensions.x, 0), point(dimensions.x, dimensions.y));
const bottomEdge = new Segment(point(dimensions.x, dimensions.y), point(0, dimensions.y));
const leftEdge = new Segment(point(0, dimensions.y), point(0, 0));
const bounds = new Polygon([topEdge, rightEdge, bottomEdge, leftEdge]);

// Create substrate instance
const substrate = new Substrate(dimensions, bounds, canvas);

// Animation loop
const loop = async () => {
  await substrate.loop();
  requestAnimationFrame(loop);
};

// Control playback
substrate.play();  // Start animation
substrate.pause(); // Pause animation
substrate.step();  // Advance one step
substrate.clear(); // Clear canvas
substrate.reset(); // Reset to initial state

loop();

Using Obstacles

Add HTML elements with the .obstacle class to create no-grow zones:

<div id="canvas">
  <GlCanvas />
</div>

<div id="content" class="obstacle">
  <h1>This area will block crack growth</h1>
</div>

API

Exports

The library exports the following from @_lowi/substrate:

// Main exports
import { 
  Substrate,      // Main substrate class
  GlCanvas,       // Svelte component
  
  // Types
  type Obstacle,
  type Obstacles,
  type Intersection,
  type BoundaryStartingPoint,
  type CrackStartingPoint,
  type CrackOptions,
  
  // Color utilities
  Pallete,        // Color palette enum
  pallete,        // Color palette function
  
  // Advanced classes
  Crack,
  RootCrack,
  ChildCrack,
  Gradient,
  Squiggle
} from '@_lowi/substrate';

Substrate Class

Constructor

new Substrate(dimensions: Vector, bounds: Polygon, htmlCanvas: HTMLCanvasElement)
  • dimensions - Canvas dimensions as a Vector
  • bounds - Polygon defining the drawable area
  • htmlCanvas - HTML canvas element for rendering

Methods

  • play(): void - Start continuous animation
  • pause(): void - Pause animation
  • step(): void - Advance one generation step
  • clear(): void - Clear the canvas
  • reset(): void - Reset to initial state with new crack pattern
  • loop(): Promise<void> - Execute one iteration of the growth algorithm

Components

GlCanvas

A ready-to-use Svelte component that handles canvas setup and rendering:

<GlCanvas />

How It Works

The Substrate algorithm follows these principles:

  1. Initialization: Start with a random crack on the canvas
  2. Growth: Each crack extends perpendicular to nearby obstacles or boundaries
  3. Intersection Detection: Cracks stop growing when they hit another crack or boundary
  4. New Cracks: When a crack completes, a new crack spawns at a random point
  5. Rendering: Gradients fill the regions between cracks, creating organic patterns

Development

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm

Setup

# Clone the repository
git clone https://gitlab.com/lowi/substrate.git
cd substrate

# Install dependencies
pnpm install

# Start dev server
pnpm dev

# Build library
pnpm build

# Check types
pnpm check

Credits

License

MIT License - see LICENSE for details

Links