-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
171 lines (136 loc) · 2.19 KB
/
sketch.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
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
arr=[0,0,0,0]
var s=0
var k=0
let states=[]
var a=[]
var n=250
var y
var wid
var rad
var speede=6.5
var repea
var current=n+2
var isItOn=0
function setup() {
slider=createSlider(5,500,n)
p1=createP("Array Size")
p1.position(25,15)
p2=createP("Speed")
p2.position(320,15)
speedSlider=createSlider(5,500,30)
slider.position(0,50)
speedSlider.position(300,50)
button=createButton("New Array")
button.position(150,50)
button.mousePressed(refresh)
speedSlider.input(changespeed)
canva=createCanvas(windowWidth, windowHeight-100);
canva.position(0,80)
y=height
wid=width/n
rad=wid/10
for(var i=0;i<n;i++)
{
a.push(random(3,height))
states.push(-1)
}
// quickSort(a,0,n-1)
}
changespeed=()=>
{
speede=map(speedSlider.value(),3,60,3,60)
}
var sorte=""
function draw() {
var ele=document.getElementsByName('Sorts')
for(var e=0;e<ele.length;e++)
{
if(ele[e].checked)
{
sorte=ele[e].value
}
}
s=0
background(180,70,25)
fill(0, 102, 153);
slider.input(sliderChange)
stroke(150)
strokeWeight(1)
fill(20,255,255)
if(n==1)
rad=0
else
rad=3
for(var i=0;i<n;i++)
{var color=map(a[i],3,height,55,255)
fill(0,color,color)
rect(0+s,y,wid,-(a[i]),rad)
s+=wid
}
if(sorte=="selection")
{
if(arr[1])
{
selectionSort(a,n,k)
}
else
{k=-1
arr[0]=0
arr[1]=1
arr[2]=0
arr[3]=0
}
}
else if(sorte=="bubble")
{if(arr[0])
{
bubbleSort(a,n,k)
}
else{k=0
arr[0]=1
arr[1]=0
arr[2]=0
arr[3]=0
}}
else if(sorte=="insertion"){
if(arr[2])
{
insertionSort(a,n,k)
}
else {
k=0
arr[0]=0
arr[1]=0
arr[2]=1
arr[3]=0
}
}
else if(sorte=="quick"){
if(arr[3])
{
if(isItOn==0)
{
window.alert("some features are not optimized with quicksort like combining diff sorting algo also press new array after slider change for quicksort")
callquickSort()
}
isItOn=1
}
else {
k=0
isItOn=0
arr[0]=0
arr[1]=0
arr[2]=0
arr[3]=1
}}
frameRate(speede)
k++
if(k>n)
{
k=0
}
}
callquickSort=()=>
{
quickSort(a,0,n-1)
}