-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compass.pde
40 lines (38 loc) · 1.03 KB
/
Compass.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
class Compass
{
private float preLat;
private float preLong;
private String text = "";
private int X;
private int Y;
Compass(float preLat, float preLong, int X, int Y)
{
this.preLat=preLat;
this.preLong=preLong;
this.X=X;
this.Y=Y;
}
public void update(float curLat, float curLong)
{
float dLat=curLat-preLat;
float dLong=curLong-preLong;
float angle=degrees(atan2(dLat,dLong));
//println(angle);
if(angle<0) angle+=360;
//println(angle);
if(angle>22.5 && angle<157.5) text+='N';
else if(angle>202.5 && angle<337.5) text+='S';
if((angle>=0&&angle<67.5)||(angle<=360&&angle>292.5)) text+='E';
else if(angle>112.5 && angle<247.5) text+='W';
stroke(0,0,255);
strokeWeight(2);
fill(0);
ellipse(X,Y, 50, 50);
textAlign(CENTER, CENTER);
fill(255);
text(text, X,Y);
preLat=curLat;
preLong=curLong;
text="";
}
}