Skip to content

Shiouko/sorting-visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โšก Sorting Algorithm Visualizer

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.

โœจ Features

๐ŸŽจ Visual Design

  • 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

๐Ÿงฎ 8 Sorting Algorithms

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) โŒ

๐ŸŽฎ Controls

  • 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

โš” Race Mode

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!

๐Ÿ”Š Sound Engine

Toggle sound to hear the sorting process:

  • Clicks on comparisons with pitch mapped to bar value
  • Sweeps on swaps
  • Celebration chimes on completion

๐Ÿ“Š Real-time Stats

  • Comparisons counter
  • Swaps counter
  • Array accesses
  • Elapsed time

โŒจ Keyboard Shortcuts

Key Action
Space Play / Pause
R Reset
S Step (advance one operation)
N New random array

๐Ÿ“ฑ Responsive

Works on desktop and mobile โ€” canvas resizes with the window.

๐Ÿš€ How to Use

  1. Open index.html in any modern web browser
  2. Select an algorithm from the dropdown
  3. Adjust speed and array size with the sliders
  4. Choose a distribution preset (Random, Nearly Sorted, etc.)
  5. Click โ–ถ Play to start, or โญ Step to advance one operation at a time
  6. Toggle โš” Race Mode to compare two algorithms side-by-side
  7. Toggle ๐Ÿ”Š Sound to hear the sorting process

๐Ÿ— Tech Stack

  • 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

๐Ÿงฌ Architecture

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.

๐Ÿ“‚ File Structure

sorting-visualizer/
โ”œโ”€โ”€ index.html    โ† Single self-contained file (HTML + CSS + JS)
โ””โ”€โ”€ README.md     โ† This file

๐ŸŽฏ Color Palette

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 โšก

About

๐ŸŽจ Interactive Sorting Algorithm Visualizer โ€” Cyberpunk neon aesthetics, 8 algorithms, race mode, sound effects. Built with p5.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

No contributors

Languages