-
Notifications
You must be signed in to change notification settings - Fork 0
/
StarMap.pde
135 lines (116 loc) · 2.41 KB
/
StarMap.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
Table table;
void setup()
{
size(800,800);
background(0);
table = loadTable("stars.csv","header, csv");
loadData();
drawGrid();
printStars();
renderStars();
}
ArrayList<Star> stars = new ArrayList<Star>();
float boxX = 50;
float boxY = 50;
float startX;
float startY;
boolean lineDrawn = false;
Star star;
void draw()
{
}
void loadData()
{
for(TableRow row : table.rows())
{
int hab = row.getInt("Hab?");
String starName = row.getString("Display Name");
float distance = row.getFloat("Distance");
float xg = row.getFloat("Xg");
float yg = row.getFloat("Yg");
float zg = row.getFloat("Zg");
float absMag = row.getFloat("AbsMag");
star = new Star(hab, starName, distance, xg, yg, zg, absMag);
stars.add(star);
}
}
void printStars()
{
for(int i=0; i<stars.size(); i++)
{
println(stars.get(i).toString());
}
}
void drawGrid()
{
float boxWidth = width / 10 -10;
int parsecs = -5;
for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
float x = map(i, 0, 10, 50, width-50);
float y = map(j, 0, 10, 50, height-50);
noFill();
stroke(208, 58, 250);
rect(x, y, boxWidth, boxWidth);
if(i==0)
{
fill(208, 58, 250);
text(parsecs, y, 20);
text(parsecs, x-40, y, 20);
parsecs++;
}
}
}
}
void renderStars()
{
for(int i=0; i<stars.size(); i++)
{
stars.get(i).drawStar();
}
}
void mousePressed()
{
for(int i=0; i<stars.size(); i++)
{
float mappedxg = map(stars.get(i).xg, -5, 5, 50, width-50);
float mappedyg = map(stars.get(i).yg, -5, 5, 50, height-50);
if(mouseX > mappedxg-2 && mouseX < mappedxg+2)
{
stars.get(i).clickFlag = 1;
println(stars.get(i).starName);
}
}
}
void mouseDragged()
{
for(int i=0; i<stars.size(); i++)
{
if(stars.get(i).clickFlag == 1)
{
float mappedxg = map(stars.get(i).xg, -5, 5, 50, width-50);
line(mouseX, mouseY, mappedxg, stars.get(i).yg);
startX = mappedxg;
startY = stars.get(i).yg;
lineDrawn = true;
stars.get(i).clickFlag = 0;
}
}
}
void mouseReleased()
{
if(lineDrawn == true)
{
strokeWeight(3);
stroke(255);
line(startX, startY, mouseX, mouseY);
lineDrawn = false;
startX = 0;
startY = 0;
float distance = startX-mouseY;
String message = "Distance "+distance;
text(message, 50, height-10);
}
}