A visually stunning, interactive web-based sorting algorithm visualizer with a cyberpunk neon aesthetic. Watch algorithms dance, race them head-to-head, and hear them sort.
- Cyberpunk dark theme with neon gradients, glow effects, and smooth animations
- Bars with rounded tops, shine highlights, and active-bar glow effects
- Color-coded states: comparing (pink), swapping (red), sorted (green), pivot (gold)
- Celebration cascade animation when sorting completes
| Algorithm | Time (Avg) | Time (Worst) | Space | Stable |
|---|---|---|---|---|
| Bubble Sort | O(nยฒ) | O(nยฒ) | O(1) | โ |
| Insertion Sort | O(nยฒ) | O(nยฒ) | O(1) | โ |
| Selection Sort | O(nยฒ) | O(nยฒ) | O(1) | โ |
| Merge Sort | O(n log n) | O(n log n) | O(n) | โ |
| Quick Sort | O(n log n) | O(nยฒ) | O(log n) | โ |
| Heap Sort | O(n log n) | O(n log n) | O(1) | โ |
| Radix Sort | O(nk) | O(nk) | O(n+k) | โ |
| Shell Sort | O(n logยฒn) | O(n logยฒn) | O(1) | โ |
- Play / Pause โ Start and stop the visualization
- Step โ Advance one operation at a time for detailed inspection
- Reset โ Restart with the same array
- Shuffle โ Generate a new random array
- Speed Slider โ From slow (50ms) to instant (0ms) per operation
- Size Slider โ Array size from 10 to 200 elements
- Distribution Presets โ Random, Nearly Sorted, Reversed, Few Unique
Split the canvas in half and watch two algorithms sort the same array simultaneously. Each side has its own stats โ see which algorithm finishes first!
Toggle sound to hear the sorting process:
- Clicks on comparisons with pitch mapped to bar value
- Sweeps on swaps
- Celebration chimes on completion
- Comparisons counter
- Swaps counter
- Array accesses
- Elapsed time
| Key | Action |
|---|---|
Space |
Play / Pause |
R |
Reset |
S |
Step (advance one operation) |
N |
New random array |
Works on desktop and mobile โ canvas resizes with the window.
- Open
index.htmlin any modern web browser - Select an algorithm from the dropdown
- Adjust speed and array size with the sliders
- Choose a distribution preset (Random, Nearly Sorted, etc.)
- Click โถ Play to start, or โญ Step to advance one operation at a time
- Toggle โ Race Mode to compare two algorithms side-by-side
- Toggle ๐ Sound to hear the sorting process
- p5.js (v1.9.0) โ Canvas rendering and animation
- Web Audio API โ Sound effects
- Vanilla JS โ No frameworks, no build step
- Single HTML file โ Fully self-contained, works offline
All algorithms are implemented as JavaScript generator functions that yield operations:
function* bubbleSort(arr) {
for (let i = 0; i < arr.length - 1; i++) {
for (let j = 0; j < arr.length - i - 1; j++) {
yield { type: 'compare', indices: [j, j + 1] };
if (arr[j] > arr[j + 1]) {
yield { type: 'swap', indices: [j, j + 1] };
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
}
}
yield { type: 'sorted', index: arr.length - 1 - i };
}
}This gives perfect step control โ the visualizer can advance one operation at a time, or batch multiple operations per frame for speed.
sorting-visualizer/
โโโ index.html โ Single self-contained file (HTML + CSS + JS)
โโโ README.md โ This file
| Role | Color | Hex |
|---|---|---|
| Background | Deep Navy Black | #0a0a1a |
| Bar Start | Periwinkle | #667eea |
| Bar End | Purple | #764ba2 |
| Comparing | Pink Glow | #f093fb |
| Swapping | Red Pulse | #ff6b6b |
| Sorted | Neon Green | #05ffa1 |
| Pivot | Gold | #ffd000 |
| Accent | Cyan | #00d4ff |
Built with p5.js โข Cyberpunk meets data art โข Sorting has never looked this good โก