Glitch
Digital glitch artifacts with horizontal slice displacement, RGB channel splits, scanlines, and random noise blocks. Creates a screen corruption aesthetic perfect for cyberpunk or error-themed visuals.
Examples
Basic
Default settings.
<template>
<EffectDemo>
<canvas ref="canvasRef"></canvas>
</EffectDemo>
</template>
<script
setup
lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import { createGlitch } from '@basmilius/sparkle';
const canvasRef = ref<HTMLCanvasElement>();
let sim: ReturnType<typeof createGlitch> | null = null;
onMounted(() => {
if (canvasRef.value) {
sim = createGlitch();
sim.mount(canvasRef.value).start();
}
});
onUnmounted(() => {
sim?.destroy();
sim = null;
});
</script>Configuration
All options are passed via a config object:
import { createGlitch } from '@basmilius/sparkle';
const glitch = createGlitch({
intensity: 0.5,
speed: 1,
rgbSplit: 3,
scanlines: true,
noiseBlocks: true,
sliceDisplacement: true,
color: '#00ff00',
scale: 1
});
glitch.mount(canvas).start();intensity
Controls the overall strength of the glitch artifacts (0–1). Higher values produce more frequent and dramatic distortions.
createGlitch({ intensity: 0.8 });speed
Speed multiplier for the glitch animation cycle.
createGlitch({ speed: 1.5 });rgbSplit
Maximum pixel offset for the RGB channel separation effect.
createGlitch({ rgbSplit: 6 });scanlines
Enable or disable the horizontal scanline overlay.
createGlitch({ scanlines: false });noiseBlocks
Enable or disable random rectangular noise blocks appearing across the canvas.
createGlitch({ noiseBlocks: false });sliceDisplacement
Enable or disable horizontal slice displacement, where bands of the image shift sideways.
createGlitch({ sliceDisplacement: false });color
The primary color used for glitch artifacts and scanlines.
createGlitch({ color: '#ff0044' });scale
Scales all size-related values proportionally.
createGlitch({ scale: 1.5 });