-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControls.js
More file actions
209 lines (148 loc) · 5.63 KB
/
Copy pathControls.js
File metadata and controls
209 lines (148 loc) · 5.63 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
class Controls {
constructor(){
this.sliderX = windowWidth/50;
this.bubbleSorting = false;
this.quickSorting = false;
this.heapSorting = false;
this.radixSorting = false;
this.buttonPressed = false;
}
numOfBars(bars){
//Text for user
fill(0);
textSize(windowWidth/35);
text("Number of data", windowWidth/200, windowHeight/20);
//Draw line for the slider
fill(0);
strokeWeight(3);
line(windowWidth/50, windowHeight/10, windowWidth/5, windowHeight/10);
strokeWeight(1);
//Draw sliding ellispe
ellipse(this.sliderX, windowHeight/10, windowHeight/50, windowHeight/50);
//Move the ellispe if it is not sorting and reset values
if(bars.returnFinished()){
if(mouseY > windowHeight/10 - windowHeight/50 && mouseY < windowHeight/10 + windowHeight/50){
if(mouseX > this.sliderX - windowWidth/50 && mouseX < this.sliderX + windowWidth/50){
if(mouseIsPressed){
if(mouseX > windowWidth/50 && mouseX < windowWidth/5){
this.sliderX = mouseX;
let num = Math.round((this.sliderX - windowWidth/50 + 20)/2);
bars.setNum(num);
this.bubbleSorting = false;
this.quickSorting = false;
this.heapSorting = false;
this.radixSorting = false;
this.buttonPressed = false;
}
}
}
}
}
}
bubbleSort(){
//Tell the program if the bubble sort button is pressed
fill(0);
text("Bubble Sort", windowWidth/3, windowHeight/20);
fill(0);
ellipse(windowWidth/3.3, windowHeight/25, windowHeight/40, windowHeight/40);
fill(0);
this.bubbleSorting = false;
if(!this.buttonPressed){
if(mouseY > windowHeight/25 - windowHeight/40 && mouseY < windowHeight / 25 + windowHeight/40){
if(mouseX > windowWidth/3.3 - windowHeight/40 && mouseX < windowWidth/3.3 + windowHeight/40){
if(mouseIsPressed){
this.bubbleSorting = true;
this.buttonPressed = true;
}
}
}
}
return this.bubbleSorting;
}
radixSort(){
//Tell the program if the radix sort button is pressed
fill(0);
text("Radix Sort", windowWidth/1.5, windowHeight/20);
fill(0);
ellipse(windowWidth/1.58, windowHeight/25, windowHeight/40, windowHeight/40);
fill(0);
this.radixSorting = false;
if(!this.buttonPressed){
if(mouseY > windowHeight/25 - windowHeight/40 && mouseY < windowHeight / 25 + windowHeight/40){
if(mouseX > windowWidth/1.58 - windowHeight/40 && mouseX < windowWidth/1.58 + windowHeight/40){
if(mouseIsPressed){
this.radixSorting = true;
this.buttonPressed = true;
console.log("Radix sorting pressed");
}
}
}
}
return this.radixSorting;
}
quickSort(){
//Tell the program if the quick sort button is pressed
this.quickSorting = false;
fill(0);
text("Quick Sort", windowWidth/3, windowHeight/10);
fill(0);
ellipse(windowWidth/3.3, windowHeight/11, windowHeight/40, windowHeight/40);
fill(0);
if(!this.buttonPressed){
if(mouseY > windowHeight/11 - windowHeight/40 && mouseY < windowHeight / 11 + windowHeight/40){
if(mouseX > windowWidth/3.3 - windowHeight/40 && mouseX < windowWidth/3.3 + windowHeight/40){
if(mouseIsPressed){
this.quickSorting = true;
this.buttonPressed = true;
}
}
}
}
return this.quickSorting;
}
sleep(millisecondsDuration)
{
return new Promise(resolve => setTimeout(resolve, millisecondsDuration));
}
heapSort(){
//Tell the program if the heap sort button is pressed
this.heapSorting = false;
fill(0);
text("Heap Sort", windowWidth/1.5, windowHeight/10);
fill(0);
ellipse(windowWidth/1.58, windowHeight/11, windowHeight/40, windowHeight/40);
fill(0);
if(!this.buttonPressed){
if(mouseY > windowHeight/11 - windowHeight/40 && mouseY < windowHeight / 11 + windowHeight/40){
if(mouseX > windowWidth/1.58 - windowHeight/40 && mouseX < windowWidth/1.58 + windowHeight/40){
if(mouseIsPressed){
this.heapSorting = true;
this.buttonPressed = true;
}
}
}
}
return this.heapSorting;
}
drawControls(bars){
//Runs the controls and which sort to do, as well as setting the size of array
fill(150);
noStroke();
rect(0, 0, windowWidth, windowHeight/ 8.5);
stroke(0);
this.numOfBars(bars);
if(this.bubbleSort()){
return 1;
}
if(this.radixSort()){
return 2;
}
if(this.quickSort()){
return 3;
}
if(this.heapSort()){
return 4;
}
return 0;
}
};