-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
78 lines (49 loc) · 1.49 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let n = 40;
let arr = []
let isSorting = false;
reset();
function reset(){
for(let i = 0; i < n; i++) {
arr[i] = Math.random();
}
displayBars();
}
function playSort(sortAlgorithm) {
if(isSorting) return;
isSorting = true;
const copy = [...arr];
const moves = sortAlgorithm(copy);
animate(moves);
disableAndHideDropdown();
disableSliders();
disableButtons();
}
// DISTINCT INSERTION SORT AND SHELL SORT
function playShellPlayInsert(sortAlgorithm) {
if(isSorting) return;
isSorting = true;
const copy = [...arr];
const moves = sortAlgorithm(copy);
animateShellInsert(moves);
disableAndHideDropdown();
disableSliders();
disableButtons();
}
function displayBars(move){
const container = document.getElementById("container");
container.innerHTML ="";
const barSizeInput = document.getElementById("change-size-bars");
const newSize = parseInt(barSizeInput.value);
const barWidth = 500 / newSize; // Calculate the new width of the bars
for(let i = 0; i < arr.length; i++) {
const bar = document.createElement('div');
bar.style.height = arr[i] * 100 + "%";
bar.style.width = barWidth + "px"; // Set the new width of the bars
bar.classList.add("bar");
if (move && move.indices.includes(i)){
bar.style.backgroundColor =
move.moveType == "change" ? "green" : "red";
}
container.appendChild(bar);
}
}