-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMy_plottings.js
98 lines (85 loc) · 2.44 KB
/
My_plottings.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
const k = 500;
var plots =[];
var points = [[],[],[],[],[]];
const pltsQ = 5;
const labels = ["Torque","Relative angular velocity (w)","Angular Position (DEGREE)","Relative angular momentum (Iw)","Relative rotational energy (Iw2)"];
var values = [t_chart, v_chart, theta_chart,Momentum_chart, Energy_Chart ];
var v,A;
var Myplots = function(p) {
// Global variables
// Load the image before the sketch is run
p.preload = function() {
// star = p.loadImage("data/star.png");
};
// Initial setup
p.setup = function() {
// Create the canvas
h = 300*pltsQ;
w = 1200;
var canvas = p.createCanvas(w, h+30*pltsQ);
for(var i=0; i < pltsQ; i++){
points[i] = [];
// Setup for the second plot
plots[i] = new GPlot(p);
plots[i].setPos(0, i*h/pltsQ);
plots[i].setDim(w, h/pltsQ-30);
// plot2.getXAxis().getAxisLabel().setText("steps");
plots[i].getYAxis().getAxisLabel().setText(labels[i]);
plots[i].setPoints(points[i]);
// Setup the mouse actions
plots[i].activateCentering();
}
plots[0].getTitle().setText("values vs time(steps)");
plots[pltsQ-1].getXAxis().getAxisLabel().setText("steps");
// Leave empty the points for the second plot. We will fill them in draw()
};
// Execute the sketch
p.draw = function() {
values = [t_chart, v, theta_chart*180/PI,Momentum_chart, Energy_Chart ];
points = [[],[],[],[],[]];
// Clean the canvas
// Reset the points if the user pressed the space bar
// if (p.keyIsPressed && p.key === ' ') {
// plot2.setPoints([]);
// }
p.background(255);
var zaman = time_chart;
if (discs[0].vel === 0){
v = 0;
}else{
v = v_chart/discs[0].vel;
};
if (zaman < 1){
for(var i=0; i < pltsQ; i++){
plots[i].setPoints([]);
}
} else {
for(var i=0; i < pltsQ; i++){
points[i] = plots[i].getPoints();
}
};
if (plots[0].getPoints().length > k){
for(var i=0; i < pltsQ; i++){
points[i] = subset(points[i], 1);
}
};
for(var i=0; i < pltsQ; i++){
A = values[i];
print(A);
points[i].push(new GPoint(zaman, A));
plots[i].setPoints(points[i]);
// Draw the plot
plots[i].beginDraw();
plots[i].drawBackground();
plots[i].drawBox();
plots[i].drawXAxis();
plots[i].drawYAxis();
plots[i].drawTitle();
plots[i].drawGridLines(GPlot.BOTH);
plots[i].drawLines();
// plot[i].drawPoints(star);
plots[i].endDraw();
};
// Add a new point to the second plot if the mouse moves significantly
};
};