-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.js
More file actions
133 lines (94 loc) · 2.86 KB
/
interface.js
File metadata and controls
133 lines (94 loc) · 2.86 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
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
wW = windowWidth;
wH = windowHeight;
barWidth = wW/jrs.data.length;
}
function mousePressed() {
noLoop();
redraw();
}
function shuffleJRS() {
var curr = jrs.data.length - 1;
while (0 !== curr) {
jrs.swap(curr, Math.floor(Math.random() * curr));
curr--;
}
}
function setup() {
//Graphical stuff
frameRate(60);
createCanvas(windowWidth, windowHeight);
wW = windowWidth;
wH = windowHeight;
barWidth = 0;
//Sorty stuff
jrs = new Controller();
data = [];
leftPivots = [];
rightPivots = [];
bestBubbleIndexes = [];
deltaIndexes = [];
bestDeltaIndexes = [];
starts = [];
ends = [];
let n = 400;
for (let i = 0; i < n; i++) {
value = ceil(100 * (1/(1+Math.pow(Math.E, ((-i)+(n/2))/(n/6)))));
data.push(value);
jrs.addData(value);
}
shuffleJRS();
jrs.setZoneLimit(10);
jrs.setMachines(10);
jrs.go();
barWidth = wW/jrs.data.length;
noStroke();
}
function draw() {
//noLoop();
background(0);
//clear and gather data from the jrs
leftPivots = [];
rightPivots = [];
bestBubbleIndexes = [];
deltaIndexes = [];
bestDeltaIndexes = [];
starts = [];
ends = [];
for (machine of jrs.machines) {
if (machine.leftPivot != -1) {leftPivots.push(machine.leftPivot);}
if (machine.rightPivot != -1) {rightPivots.push(machine.rightPivot);}
if (machine.bestBubbleIndex != -1) {bestBubbleIndexes.push(machine.bestBubbleIndex);}
if (machine.deltaIndex != -1) {deltaIndexes.push(machine.deltaIndex);}
if (machine.bestDeltaIndex != -1) {bestDeltaIndexes.push(machine.bestDeltaIndex);}
if (machine.start != -1) {starts.push(machine.start);}
if (machine.end != -1) {ends.push(machine.end);}
}
//Draw the initial data SORTED
fill(255);
for (let i = 0; i < data.length; i++) {
let y = map(data[i], 100, 0, wH/2, 0);
let x = i * barWidth;
rect(x, wH/2, barWidth, -y);
}
//Draw the JRS data
let rampCheck = jrs.data[0];
for (let i = 0; i < jrs.data.length; i++) {
//for (let query of jrs.queryQueue) {if (i >= query[1] && i <= query[2]) {fill(155,155,255);}}
if (jrs.data[i] >= rampCheck) {fill(255); rampCheck = jrs.data[i];}
for (let check of leftPivots) {if (i == check) {fill(0, 255, 255);}}
for (let check of rightPivots) {if (i == check) {fill(255, 0, 255);}}
for (let check of bestBubbleIndexes) {if (i == check) {fill(155,155,255);}}
for (let check of deltaIndexes) {if (i == check) {fill(0, 255, 255);}}
for (let check of bestDeltaIndexes) {if (i == check) {fill(155,255,155);}}
for (let check of starts) {if (i == check) {fill(0,0,255);}}
for (let check of ends) {if (i == check) {fill(255,0,0);}}
let y = map(jrs.data[i], 100, 0, wH/2, 0);
let x = i * barWidth;
rect(x, wH, barWidth, -y);
fill(155);
}
//Stop redraws when JRS is DONE
if (jrs.step() == "Controller is DONE") {noLoop();}
}