-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAngleGraph.pde
More file actions
executable file
·97 lines (81 loc) · 2.15 KB
/
AngleGraph.pde
File metadata and controls
executable file
·97 lines (81 loc) · 2.15 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
class AngleGraph {
float X, Y, W, H;
AngleGraph(float X, float Y, float W, float H) {
this.X = X;
this.Y = Y;
this.W = W;
this.H = H;
}
void draw() {
pushMatrix();
translate(X, Y);
// x and y axis
fill(#6C6C6C);
stroke(#6C6C6C);
strokeWeight(2);
line(0, H/2, W, H/2);
line(0, 0, 0, H);
// x axis ticks
textSize(12);
for (int i = 1; i <= 10; i++) {
float imapped = map(i, 0, 10, 0, W);
line(imapped, H/2, imapped, H/2 + 4);
text(i, imapped - 3, H/2 + 16);
}
// y axis ticks
textSize(12);
for (float i = -PI/4; i <= PI/4; i = i + PI/12) {
float imapped = map(i, -PI/4, PI/4, H, 0);
line(0, imapped, -4, imapped);
text(nfp(degrees(i), 1, 0), -30, imapped + 5);
}
// axis labels
textSize(14);
text("time (s)", W - 40, H/2 - 10);
text("angle", 10, -10);
// data points
noFill();
strokeWeight(2);
stroke(#2AA198);
beginShape();
for (int i = 0; i < 1000; i++) {
float t = i * 0.01;
float tmapped = map(t, 0, 10, 0, W);
float ymapped = map(simulation.data[i], -PI/4, PI/4, H, 0);
vertex(tmapped, ymapped);
}
endShape();
if (mouseX > X && mouseX < X + W && mouseY > Y && mouseY < Y + H && mousePressed) {
float t = mouseX - X;
int index = round(map(t, 0, W, 0, 1000));
float y = simulation.data[index];
float ymapped = map(y, -PI/4, PI/4, H, 0);
stroke(#2AA198);
strokeWeight(1);
line(t, 0, t, H);
stroke(#CB4B16);
strokeWeight(8);
point(t, ymapped);
angleGraphHover = true;
angleGraphTheta = y;
timerRunning = false;
}
else if (timerRunning) {
float y = simulation.data[timer.index];
float ymapped = map(y, -PI/4, PI/4, H, 0);
float t = timer.t;
float tmapped = map(t, 0, 10, 0, W);
stroke(#CB4B16);
strokeWeight(8);
point(tmapped, ymapped);
}
else {
float start = map(simulation.data[0], -PI/4, PI/4, H, 0);
stroke(#CB4B16);
strokeWeight(8);
point(0, start);
angleGraphHover = false;
}
popMatrix();
}
}