-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubbleSort.js
59 lines (46 loc) · 1.19 KB
/
bubbleSort.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
var lines = [];
var n = 0;
var j = 0;
var bSortCanvas;
var bubbleButton;
var bubbleLoop;
function setup(){
bSortCanvas = createCanvas(1000, 800);
bSortCanvas.parent("bCanvas");
for (var i = 0; i <width; i++){
lines[i] = random(0, height);
}
bubbleLoop = false;
bubbleButton = document.getElementById("bubble");
bubbleButton.onclick = function proceedLoop(){
bubbleLoop = true
}
}
function draw(){
background(0);
if (bubbleLoop){
for (var i = 0; i<lines.length; i++){
if(i%2==0){
stroke(155);
strokeWeight(5);
line(i, height, i, height-lines[i]);
}else{
stroke(0);
strokeWeight(5);
line(i, height, i, height-lines[i]);
}
}
if (n<lines.length){
for (j = 0; j< lines.length; j++){
if (lines[j]>lines[j+1]){
var temp = lines[j];
lines[j] = lines[j+1];
lines[j+1] = temp;
}
}
n+=1;
}else{
noLoop();
}
}
}