-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.pde
48 lines (45 loc) · 1.07 KB
/
graph.pde
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
class graph {
float[] coordinates;
int lineWidth;
color lineColor;
int graphWidth;
int graphHeight;
int xStart;
int yStart;
float yCoordinate;
graph(int _graphWidth, int _graphHeight, int _lineWidth, color _lineColor, int _xStart, int _yStart) {
graphWidth = _graphWidth;
graphHeight = _graphHeight;
lineWidth = _lineWidth;
lineColor = _lineColor;
xStart = _xStart;
yStart = _yStart;
coordinates = new float[graphWidth];
for (int i=0; i < graphWidth; i++) {
coordinates[i]=0;
}
}
void display() {
stroke(lineColor);
strokeWeight(lineWidth);
pushMatrix();
translate(xStart, yStart);
for (int j=0; j < graphWidth; j++) {
if (j>0) {
line(j-1, -coordinates[j-1], j, -coordinates[j]);
}
}
popMatrix();
}
void push(float _yCoordinate) {
yCoordinate = _yCoordinate;
for (int j=0; j < graphWidth; j++) {
if ((j+1)==graphWidth) {
coordinates[j]=constrain(yCoordinate, 0, graphHeight);
}
else {
coordinates[j]=coordinates[j+1];
}
}
}
}