-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawing.pde
85 lines (74 loc) · 2.21 KB
/
Drawing.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
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
int N = 2000;
float[] angles = new float[N];
float[] cn = new float[N];
FloatList X = new FloatList();
FloatList Y = new FloatList();
float angle = 0;
float speed = 0.005;
Fasore[] fasori = new Fasore[N];
void setup() {
size(1000, 1000);
frameRate(60);
colorMode(HSB,360);
String[] lines = loadStrings("output.txt");
for(int i=0;i<N;i+=1){
String[] parts = lines[i].split(";");
fasori[i] = new Fasore(float(parts[0]),float(parts[1]),float(parts[2]));
}
}
void draw() {
background(10);
float sumX = 0;
float sumY = 0;
colorMode(RGB,256);
stroke(255, 255, 255);
strokeWeight(1);
//Draws the arrows and calculates the new positions
for (int i=0; i<N; i++) {
if(fasori[i].speed == 0) continue;
float len = 750 * fasori[i].modulo;
float fromX = width/2 + sumX;
float fromY = height/2 + sumY;
float xDist = len*cos(fasori[i].argomento);
float yDist = len*sin(fasori[i].argomento);
float toX = fromX + xDist;
float toY = fromY + yDist;
arrow(fromX,fromY, toX, toY, fasori[i].argomento, len);
sumX += xDist;
sumY += yDist;
//Il fasore i-esimo ruota ad una velocità i*omega (omega = speed)
fasori[i].argomento += fasori[i].speed * speed;
}
X.append(width/2 + sumX);
Y.append(height/2 + sumY);
//Drawing lines between the previus ending point of the arrows
colorMode(HSB,360,360,360);
for (int i=0; i<X.size()-1; i++) {
float angle = atan2(Y.get(i)-height/2,X.get(i)-width/2);
if(angle<0){
angle += 2*PI;
}
stroke((angle*180/PI)%360,360,360);
strokeWeight(1.5);
line(X.get(i), Y.get(i), X.get(i+1), Y.get(i+1));
}
//Video Capturing
//saveFrame("frames/"+N+"/####.tif");
}
//Draws an arrow
void arrow(float x1, float y1, float x2, float y2, float angle, float size) {
line(x1, y1, x2, y2);
float delta = (180-25)*PI/180;
float l = size/15;
stroke((angle*180/PI)%360,360,360);
triangle(x2+l*cos(angle + delta), y2+l*sin(angle + delta), x2+l*cos(angle - delta), y2+l*sin(angle - delta), x2, y2);
}
//Defines the complex phasor
class Fasore{
float speed,modulo,argomento;
Fasore(float speed,float modulo,float argomento){
this.speed = speed;
this.modulo = modulo;
this.argomento = argomento;
}
}