-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructionDrawable.pde
More file actions
119 lines (108 loc) · 2.64 KB
/
InstructionDrawable.pde
File metadata and controls
119 lines (108 loc) · 2.64 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
class InstructionDrawable implements Drawable {
private float x, y;
private final float noteHeight;
private final float noteWidth;
private boolean executing;
private final Instruction instruction;
private final int[] a;
public InstructionDrawable(Instruction instruction, float noteHeight, float noteWidth, int[] a) {
this.instruction = instruction;
this.noteHeight = noteHeight;
this.noteWidth = noteWidth;
this.a = a;
}
public void place(Point p) {
this.x = p.x;
this.y = p.y;
}
public float getWidth() {
return noteWidth;
}
public float getHeight() {
return noteHeight * (float)a.length;
}
public void setup() { }
public void tick() { }
public void draw() {
pushMatrix();
translate(x, y);
if(executing) {
pushStyle();
fill(255,255,0,50);
noStroke();
rect(0,0,noteWidth,noteHeight * a.length);
popStyle();
}
for(int i = 0; i < a.length; i++) {
float noteY = i * noteHeight;
if(instruction.swap()) {
/*if(i > instruction.lo() && i < instruction.hi()) {*/
/*continue;*/
/*}*/
/*if(i > instruction.hi() && i < instruction.lo()) {*/
/*continue;*/
/*}*/
}
pushStyle();
strokeCap(PROJECT);
if(instruction.isControlPoint(i) && !instruction.isBeingSwapped(i)) {
stroke(15,59,160,100);
line(0, noteY, noteWidth-1f, noteY);
}
else {
// set up stroke style based on whether there was a
// 1 - swap
// 2 - compare
// 3 - nothing
if(i == instruction.hi() || i == instruction.lo()) {
// either a swap or a compare
if(instruction.swap()) {
// draw swaps in bold
stroke(0,0,0,200);
}
else {
// draw compares in red
stroke(255,0,0,200);
}
}
else {
// lightly draw idle positions
stroke(0,0,0,30);
}
if(instruction.swap()) {
if(i == instruction.hi()) {
float endY = instruction.lo() * noteHeight;
// curve to instruction.lo()
noFill();
beginShape();
vertex(0, noteY);
bezierVertex(noteWidth/2f, noteY, noteWidth/2f, endY, noteWidth-1f, endY);
endShape();
}
else if(i == instruction.lo()) {
/*float endY = instruction.hi() * noteHeight;*/
/*// curve to instruction.hi()*/
/*noFill();*/
/*beginShape();*/
/*vertex(0, noteY);*/
/*bezierVertex(noteWidth/2f, noteY, noteWidth/2f, endY, noteWidth-1f, endY);*/
/*endShape();*/
// don't draw
}
else {
line(0, noteY, noteWidth-1f, noteY);
}
}
else {
// not a swap
line(0, noteY, noteWidth-1f, noteY);
}
}
popStyle();
}
popMatrix();
}
public void setExecuting(boolean b) {
this.executing = b;
}
}