-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (71 loc) · 1.89 KB
/
script.js
File metadata and controls
77 lines (71 loc) · 1.89 KB
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
71
72
73
74
75
76
77
let v = 0;
let frame_rate;
let canv;
function sortMethod(){
v = document.querySelector('#type').value;
document.getElementById("type").disabled = true;
document.getElementById("sort_button").disabled = true;
document.getElementById("generateRandom").disabled = true;
if(v == 1 && !isSorted(arr, arr.length)){
i=0;
}
if(v == 2 && !isSorted(arr, arr.length))
i=0;
if(v == 3 && !isSorted(arr, arr.length))
i=0;
if(v == 4 && !isSorted(arr, arr.length))
quicksort(arr, 0, arr.length-1);
if(v == 5 && !isSorted(arr, arr.length))
mergeSort(arr, 0, arr.length -1);
// console.log(v);
}
function isSorted(arr, n)
{
if (n == 1 || n == 0)
return 1;
if (arr[n - 1] < arr[n - 2])
return 0;
return isSorted(arr, n - 1);
}
function setup(){
canv = createCanvas(_w, _h);
}
function draw(){
let pos = (windowWidth - _w)/2;
if(pos<0)
pos = 0;
canv.position(pos,30);
background(color('#1c1c1c'));
for(let j=0;j<length;j++){
fill(255);
strokeWeight(0.05);
rect(gap + j*w, height - arr[j], w, arr[j]);
}
if(isSorted(arr, arr.length)){
for(let j=0;j<length;j++){
fill(150,255,150);
strokeWeight(0.05);
rect(gap + j*w, height - arr[j], w, arr[j]);
}
document.getElementById("type").disabled = false;
document.getElementById("sort_button").disabled = false;
document.getElementById("generateRandom").disabled = false;
v = 0;
}
if(v == 1){
frameRate(20);
bubble_draw();
}
if(v == 2){
frameRate(20);
sellection_draw();
}
if(v == 3){
frameRate(10);
insertion_draw();
}
if(v == 4)
quick_draw();
if(v == 5)
merge_draw();
}