A JavaScript library for creating animated noise text effects on HTML5 canvas. Transform your text into dynamic, animated noise patterns with smooth transitions and responsive behavior.
npm install nosnap.js
<!-- ES Module -->
<script type="module">
import NoSnap from 'https://cdn.jsdelivr.net/npm/nosnap.js/dist/nosnap.esm.js';
</script>
<!-- UMD (Global) -->
<script src="https://cdn.jsdelivr.net/npm/nosnap.js/dist/nosnap.umd.min.js"></script>
import NoSnap from 'nosnap.js';
// Get your canvas element
const canvas = document.getElementById('myCanvas');
// Create the animation
const animation = new NoSnap(canvas, {
text: 'HELLO WORLD',
cellSize: 2,
stepMs: 32
});
// Start the animation
animation.start();
const animation = new NoSnap(canvas, {
text: 'BASIC EXAMPLE'
});
animation.start();
const animation = new NoSnap(canvas, {
text: 'CUSTOM STYLE',
cellSize: 3,
stepMs: 40,
fontSize: 48,
fontWeight: 'bold',
fontFamily: 'Arial, sans-serif'
});
// Change text without stopping animation
animation.setText('NEW TEXT');
// Update configuration
animation.updateConfig({
cellSize: 4,
stepMs: 50
});
// The library automatically handles canvas resizing
window.addEventListener('resize', () => {
// Canvas size changes are automatically detected
// No manual intervention required
});
import { useEffect, useRef } from 'react';
import NoSnap from 'nosnap.js';
function AnimatedText({ text = 'REACT EXAMPLE' }) {
const canvasRef = useRef(null);
const animationRef = useRef(null);
useEffect(() => {
if (canvasRef.current) {
animationRef.current = new NoSnap(canvasRef.current, {
text,
cellSize: 2,
stepMs: 32
});
animationRef.current.start();
}
return () => {
if (animationRef.current) {
animationRef.current.destroy();
}
};
}, []);
useEffect(() => {
if (animationRef.current) {
animationRef.current.setText(text);
}
}, [text]);
return <canvas ref={canvasRef} width={800} height={400} />;
}
<template>
<canvas ref="canvasRef" width="800" height="400"></canvas>
</template>
<script>
import { ref, onMounted, onUnmounted, watch } from 'vue';
import NoSnap from 'nosnap.js';
export default {
props: {
text: { type: String, default: 'VUE EXAMPLE' }
},
setup(props) {
const canvasRef = ref(null);
let animation = null;
onMounted(() => {
animation = new NoSnap(canvasRef.value, {
text: props.text,
cellSize: 2,
stepMs: 32
});
animation.start();
});
onUnmounted(() => {
if (animation) {
animation.destroy();
}
});
watch(() => props.text, (newText) => {
if (animation) {
animation.setText(newText);
}
});
return { canvasRef };
}
};
</script>
new NoSnap(canvas, options)
Parameters:
canvas (HTMLCanvasElement) - Required. Target canvas elementoptions (Object) - Optional. Configuration options| Method | Description |
|---|---|
start() |
Start the animation |
stop() |
Stop the animation |
destroy() |
Stop animation and clean up all resources |
setText(text) |
Update the displayed text dynamically |
updateConfig(options) |
Update configuration options |
| Option | Type | Default | Description |
|---|---|---|---|
text |
string | 'HELLO' |
Text to display |
cellSize |
number | 2 |
Size of noise cells (1-10) |
circleRadius |
number | 300 |
Radius of animated circle effect |
stepPixels |
number | 4 |
Pixels to move per animation step |
stepMs |
number | 32 |
Animation step interval (ms) |
maskBlockSize |
number | 2 |
Text mask block size |
fontSize |
number | null |
Font size (auto-calculated if null) |
fontWeight |
number|string | 900 |
Font weight |
fontFamily |
string | 'sans-serif' |
Font family |
const mobileAnimation = new NoSnap(canvas, {
text: 'MOBILE',
cellSize: 4, // Larger cells = better performance
stepMs: 50, // Slower updates = less CPU usage
maskBlockSize: 4 // Larger blocks = faster rendering
});
const qualityAnimation = new NoSnap(canvas, {
text: 'QUALITY',
cellSize: 1, // Fine detail
stepMs: 16, // 60fps animation
maskBlockSize: 1 // Sharp text edges
});
Required Features:
# Install dependencies
npm install
# Build the library
npm run build
# Run tests
npm test
# Watch mode for development
npm run build:watch
# Start development server for examples
npm run dev
# Or just serve files (after building)
npm run serve
The project includes a development server to easily test examples locally:
# Build and start server
npm run dev
This will:
http://localhost:3000You can then access examples at:
http://localhost:3000/examples/http://localhost:3000/docs/Create an HTML file in the examples/ directory:
<!DOCTYPE html>
<html>
<head>
<title>NoSnap.js Local Example</title>
</head>
<body>
<canvas id="canvas" width="800" height="400"></canvas>
<!-- Use local build -->
<script src="../dist/nosnap.umd.js"></script>
<script>
const canvas = document.getElementById('canvas');
const animation = new NoSnap(canvas, {
text: 'LOCAL DEV',
cellSize: 2
});
animation.start();
</script>
</body>
</html>
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)Hacker News submission
MIT License - see the LICENSE file for details.
Made with ❤️ for the web development community