Skip to content

Commit

Permalink
added sound to buttons yipee
Browse files Browse the repository at this point in the history
  • Loading branch information
shafiqihtsham committed Apr 15, 2024
1 parent e521de7 commit e06d503
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html lang="en" class="">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="/minecraft.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>Sorting Visualiser 3000</title>
</head>
<body>
<div id="root"></div>
Expand Down
Binary file added public/click.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions public/minecraft.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

7 changes: 7 additions & 0 deletions src/components/Slider/Slider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import sound from "/click.mp4"

interface SliderProps {
handleSpeedChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
speed: number;
}

function play(){
new Audio(sound).play();
}

const Slider = (props: SliderProps) => {
return (
<div className="flex sm:flex-row justify-center sm:min-w-[250px] min-w-[155px]">
Expand All @@ -12,6 +18,7 @@ const Slider = (props: SliderProps) => {
min={0}
max={100}
onChange={props.handleSpeedChange}
onMouseUp={play}
className="absolute h-[40px] sm:min-w-64 w-[12rem] disabled:cursor-not-allowed disabled:text-gray-400"
/>
<div className="relative bottom-[-8px] select-none">
Expand Down
11 changes: 9 additions & 2 deletions src/components/SortingVisualizer/SortingVisualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { heapSort } from "../../SortingAlgorithms/HeapSort";
import { clearMemoized } from "../../utils/displayAlgorithm";
import Slider from "../Slider";
import Controls from "../Controls";
import sound from "/click.mp4";

const ARRAY_LIMIT = {
min: 10,
Expand All @@ -24,14 +25,19 @@ const SortingVisualizer = () => {
const [sortDisabled, setSortDisabled] = useState<boolean>(false);
const [bars, setBars] = useState<number>(50);

function play() {
new Audio(sound).play();
}

const handleAlgorithmChange = (
event: React.ChangeEvent<HTMLSelectElement>
) => {
play();
setSelectedAlgorithm(event.target.value);
};

const handleSort = async () => {
// need to run this function when sort is true and i need to disable shuffle and set it to false;
play();
const copy = [...numberArray];

setShuffleDisabled(true);
Expand Down Expand Up @@ -60,6 +66,7 @@ const SortingVisualizer = () => {
};

const newArray = () => {
play();
const arrayDiv = document.getElementById("container");
if (!arrayDiv) return;

Expand All @@ -68,7 +75,6 @@ const SortingVisualizer = () => {
for (let i = 0; i < arrayBars.length; i++) {
arrayBars[i].style.backgroundColor = "";
arrayBars[i].style.backgroundImage = "";

}

const newArray = randomIntArray(ARRAY_LIMIT.min, ARRAY_LIMIT.max, bars);
Expand All @@ -82,6 +88,7 @@ const SortingVisualizer = () => {
};

const handleBarsChange = () => {
play();
let newBars;

if (bars >= 150) {
Expand Down

0 comments on commit e06d503

Please sign in to comment.