forked from skooter500/OOP-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarMap.java
More file actions
138 lines (113 loc) · 3.29 KB
/
StarMap.java
File metadata and controls
138 lines (113 loc) · 3.29 KB
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
136
137
138
package ie.tudublin;
import java.util.ArrayList;
import processing.core.PApplet;
import processing.data.Table;
import processing.data.TableRow;
import processing.data.*;
public class StarMap extends PApplet {
ArrayList<Star> stars = new ArrayList<Star>();
public float border;
void drawGrid()
{
stroke(255, 0, 255);
textAlign(CENTER, CENTER);
textSize(20);
for(int i = -5; i <=5; i ++)
{
float x = map(i, -5, 5, border, width - border);
line(x, border, x, height - border);
line(border, x, width - border, x);
fill(255);
text(i, x, border * 0.5f);
text(i, border * 0.5f, x);
}
}
void printStars()
{
for(Star s:stars)
{
System.out.println(s);
}
}
void loadStars()
{
Table table = loadTable("HabHYG15ly.csv", "header");
for(TableRow r:table.rows())
{
Star s = new Star(r);
stars.add(s);
}
}
public void settings() {
size(800, 800);
}
Star first = null;
Star second = null;
public void mouseClicked()
{
for(Star s:stars)
{
float x = map(s.getxG(), -5, 5, border, width - border);
float y = map(s.getyG(), -5, 5, border, height - border);
if (dist(mouseX, mouseY, x, y) < 20)
{
if (first == null)
{
first = s;
break;
}
else if (second == null)
{
second = s;
break;
}
else
{
first = s;
second = null;
break;
}
}
}
}
public void setup() {
colorMode(RGB);
loadStars();
printStars();
border = width * 0.1f;
}
public void drawStars()
{
for(Star s:stars)
{
s.render(this);
}
}
public void draw()
{
background(0);
drawGrid();
drawStars();
if (first != null)
{
float x = map(first.getxG(), -5, 5, border, width - border);
float y = map(first.getyG(), -5, 5, border, height - border);
if (second != null)
{
float x2 = map(second.getxG(), -5, 5, border, width - border);
float y2 = map(second.getyG(), -5, 5, border, height - border);
stroke(255, 255, 0);
line(x, y, x2, y2);
float dist = dist(first.getxG(), first.getyG(), first.getzG(), second.getxG(), second.getyG(), second.getzG());
fill(255);
textAlign(CENTER, CENTER);
text("Distance between: " + first.getDisplayName() + " and " + second.getDisplayName() + " is " + dist + " parsecs", width / 2, height - (border * 0.5f));
}
else
{
stroke(255, 255, 0);
line(x, y, mouseX, mouseY);
}
}
}
}