A modular JavaScript library for mathematical computations, graphics utilities, and interactive visualizations developed by the Makeability Lab at the University of Washington.
The library is organized into three main modules:
- Math - Vector operations and mathematical utilities (conversions, interpolation, random numbers)
- Graphics - Color manipulation and geometric primitives (line segments, color utilities)
- Logo - Interactive Makeability Lab logo components with animation support
Each module can be imported independently or as a complete bundle, allowing for optimized loading based on your needs.
The easiest way to use this library is via CDN. No installation required - just import directly in your HTML or JavaScript:
<!-- In your HTML file -->
<script type="module">
// Import specific modules
import { Vector, lerp } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.math.js';
import { lerpColor } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.graphics.js';
import { MakeabilityLabLogo } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.logo.js';
// Or import everything
import * as Makelab from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.all.js';
// Use the library
const v = new Vector(10, 20);
console.log(v.magnitude());
</script>The library is available via the jsdelivr CDN, which automatically serves files from this GitHub repository:
// Base URL pattern
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/{filename}
// Specific modules
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.math.js
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.graphics.js
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.logo.js
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.all.js
// Minified versions (recommended for production)
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.math.min.js
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.graphics.min.js
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.logo.min.js
https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.all.min.jsFor production use, it's recommended to pin to a specific commit or tag instead of @main:
// Pin to a specific version tag
import { Vector } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/[email protected]/dist/makelab.math.min.js';
// Pin to a specific commit
import { Vector } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@5baeb55/dist/makelab.math.min.js';<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Makelab Library CDN Example</title>
</head>
<body>
<canvas id="canvas" width="800" height="600"></canvas>
<script type="module">
// Import from CDN
import { Vector, lerp } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.math.min.js';
import { LineSegment, lerpColor } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.graphics.min.js';
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Create and draw a line
const line = new LineSegment(100, 100, 700, 500);
line.draw(ctx);
// Create vectors
const v1 = new Vector(10, 20);
const v2 = new Vector(30, 40);
console.log('Vector sum:', v1.add(v2));
</script>
</body>
</html>For local development or when you need to modify the library:
- Node.js (v14 or higher recommended)
- npm (comes with Node.js)
npm installThis will install all required dependencies including:
- Rollup (module bundler)
- Rollup plugins (node-resolve, alias, terser)
js/
├── src/
│ ├── lib/
│ │ ├── math/ # Math utilities and Vector class
│ │ ├── graphics/ # Graphics utilities (colors, line segments)
│ │ └── logo/ # Makeability Lab logo components
│ └── apps/ # Example applications
├── dist/ # Built output files
├── rollup.config.js # Rollup bundler configuration
└── package.json
Vector- 2D vector operations (add, subtract, multiply, normalize, etc.)convertToRadians()- Convert degrees to radiansconvertToDegrees()- Convert radians to degreeslerp()- Linear interpolation between valuesrandom()- Random number generation utilities
LineSegment- Line segment operations and intersectionslerpColor()- Interpolate between colorsconvertColorStringToObject()- Parse color strings to RGB objects
MakeabilityLabLogo- Main logo componentMakeabilityLabLogoExploder- Animated logo explosion effectTriangle,Cell,Grid- Logo building blocks- Color palette utilities
The project uses Rollup to create optimized bundles. The build process generates both standard and minified versions of each module.
npx rollup -c rollup.config.jsThis command generates the following files in the dist/ directory:
| Module | Standard | Minified |
|---|---|---|
| Math | makelab.math.js |
makelab.math.min.js |
| Graphics | makelab.graphics.js |
makelab.graphics.min.js |
| Logo | makelab.logo.js |
makelab.logo.min.js |
| All (Complete) | makelab.all.js |
makelab.all.min.js |
- Format: ES6 modules (ESM)
- Source Maps: Generated for non-minified versions
- Minification: Terser plugin for optimized builds
- Path Aliases: Configured for clean imports (@lib, @mathlib, @graphicslib, @apps, @dist)
For production use, reference the minified versions:
<script type="module">
import { Vector, lerp } from './dist/makelab.math.min.js';
import { lerpColor, LineSegment } from './dist/makelab.graphics.min.js';
// Or import everything
import * from './dist/makelab.all.min.js';
</script>This library follows Semantic Versioning (SemVer): MAJOR.MINOR.PATCH
- MAJOR: Breaking changes that are not backwards compatible
- MINOR: New features that are backwards compatible
- PATCH: Bug fixes and minor improvements
When you're ready to release a new version:
Edit package.json and update the version number:
{
"name": "makelab-lib",
"version": "1.2.3", // Update this
...
}npx rollup -c rollup.config.jsThis ensures all dist/ files are up to date with your latest changes.
git add .
git commit -m "Release v1.2.3: Brief description of changes"
git push origin mainCreate a new release on GitHub to tag the version:
- Go to your repository on GitHub
- Click on "Releases" (in the right sidebar)
- Click "Create a new release"
- Tag version: Enter the version number (e.g.,
v1.2.3) - Target: Select
mainbranch - Release title:
v1.2.3or descriptive title - Description: Describe what's new, changed, or fixed
- Click "Publish release"
After creating the release, verify that the CDN serves the new version:
// Test the new version tag
import { Vector } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/[email protected]/dist/makelab.math.min.js';The jsdelivr CDN may take a few minutes to update. You can check the status at:
https://www.jsdelivr.com/package/gh/makeabilitylab/js
For users of the library:
-
Development/Testing: Use
@mainfor the latest codeimport { Vector } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@main/dist/makelab.math.js';
-
Production: Always pin to a specific version tag
import { Vector } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/[email protected]/dist/makelab.math.min.js';
-
Specific Commit: Pin to a commit hash for absolute stability
import { Vector } from 'https://cdn.jsdelivr.net/gh/makeabilitylab/js@5baeb55/dist/makelab.math.min.js';
Before creating a release, ensure:
- All tests pass (if applicable)
- Version number updated in
package.json -
npx rollup -c rollup.config.jshas been run - All changes committed and pushed to
main - CHANGELOG updated (if you maintain one)
- GitHub Release created with tag
- CDN links tested and working
// Import only what you need
import { Vector, lerp } from './dist/makelab.math.js';
import { lerpColor } from './dist/makelab.graphics.js';
// Create a vector
const v1 = new Vector(10, 20);
const v2 = new Vector(30, 40);
const sum = v1.add(v2);
// Interpolate between values
const midpoint = lerp(0, 100, 0.5); // Returns 50
// Interpolate between colors
const blendedColor = lerpColor('#FF0000', '#0000FF', 0.5);import * as Makelab from './dist/makelab.all.js';
const vec = new Makelab.Vector(5, 10);
const line = new Makelab.LineSegment(0, 0, 100, 100);During development, you can import directly from source files:
import { Vector } from './src/lib/math/vector.js';
import { LineSegment } from './src/lib/graphics/line-segment.js';- Make Changes - Edit files in the
src/directory - Test Changes - Create test applications in
src/apps/ - Build - Run
npx rollup -c rollup.config.jsto generate distribution files - Verify - Test the built files in
dist/ - Commit - Commit both source and built files (the CDN serves from the repo)
For automatic rebuilds during development, you can run Rollup in watch mode:
npx rollup -c rollup.config.js --watchThis will automatically rebuild the distribution files whenever source files change.
Since the library is served via CDN directly from this GitHub repository, it's important to:
- Always run the build process before committing
- Commit both source files and the generated
dist/files - The
dist/directory should NOT be in.gitignore - Test the CDN links after pushing to ensure they work correctly
const v = new Vector(x, y)
v.add(other) // Vector addition
v.sub(other) // Vector subtraction
v.mult(scalar) // Scalar multiplication
v.magnitude() // Get magnitude
v.normalize() // Normalize to unit vector
v.heading() // Get angle in radiansconvertToRadians(degrees) // Degrees to radians
convertToDegrees(radians) // Radians to degrees
lerp(start, stop, amount) // Linear interpolation
random(min, max) // Random number generationconst line = new LineSegment(x1, y1, x2, y2)
line.draw(context) // Draw to canvas context
line.intersects(otherLine) // Check intersection
line.getIntersection(otherLine) // Get intersection pointlerpColor(color1, color2, amount) // Blend two colors
convertColorStringToObject(colorString) // Parse color to RGBSpecialized components for rendering and animating the Makeability Lab logo. See source files for detailed API documentation.
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Run the build process (
npx rollup -c rollup.config.js) - Commit both source and dist files
- Submit a pull request
MIT License - Copyright (c) 2024 UW Makeability Lab
See LICENSE file for full details.
Jon E. Froehlich
For questions, issues, or contributions, please visit the project repository.
Built with Rollup | Powered by JavaScript ES6+ Modules