-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.htm
361 lines (302 loc) · 13.5 KB
/
index.htm
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<html>
<head>
<meta charset="UTF-8">
<style>
body { margin: 0; }
a { color: #fff; }
</style>
<script src="three/three.min.js"></script>
<script src="three/TrackballControls.js"></script>
</head>
<body>
<script>
// Create an empty scene
var scene = new THREE.Scene();
// Create a basic perspective camera
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
camera.position.x = 200;
// Create a renderer with Antialiasing
var renderer = new THREE.WebGLRenderer({antialias:true});
// Configure renderer clear color
renderer.setClearColor("#000000");
// Configure renderer size
renderer.setSize( window.innerWidth, window.innerHeight );
// Append Renderer to DOM
document.body.appendChild( renderer.domElement );
var colors = [];
//Add Milky Way with a special magenta color
var dotGeometry = new THREE.Geometry();
dotGeometry.vertices.push(new THREE.Vector3( 0, 0, 0 ));
colors.push(new THREE.Color('#f0f'));
var rawFile = new XMLHttpRequest();
rawFile.open("GET", "galaxydata.txt", false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var data = rawFile.responseText.split("\n");
for (var i = 0; i < 4672; i++) {
var parts = data[i].split(" ");
dotGeometry.vertices.push(new THREE.Vector3( parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]) ));
colors.push(new THREE.Color('#fff'));
}
}
}
}
rawFile.send(null);
var names;
rawFile = new XMLHttpRequest();
rawFile.open("GET", "galaxyname.txt", false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
allText = rawFile.responseText;
names = allText.split("\n");
}
}
}
rawFile.send(null);
dotGeometry.colors = colors;
var size = 0.032;
var dotMaterial = new THREE.PointsMaterial({
size: size,
vertexColors: THREE.VertexColors,
});
var dots = new THREE.Points( dotGeometry, dotMaterial );
scene.add( dots );
var controls = new THREE.TrackballControls( camera, renderer.domElement );
// Render Loop
var render = function () {
requestAnimationFrame( render );
controls.update();
// Render the scene
renderer.render(scene, camera);
};
render();
window.addEventListener( 'resize', onWindowResize, false );
window.addEventListener( 'mousemove', onDocumentMouseMove, false );
window.addEventListener( 'click', onDocumentMouseClick, false );
window.addEventListener( 'contextmenu', onDocumentMouseRightClick, false );
window.addEventListener( 'wheel', onDocumentMouseWheel, true );
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
var text = document.createElement('div');
text.style.position = 'absolute';
text.style.color = '#fff';
text.style.top = 0 + 'px';
text.style.left = 0 + 'px';
document.body.appendChild(text);
text.innerHTML = "You are looking at 4673 galaxies around Milky Way from a distance of 200 Mpc (652 million light-years)! The Milky Way plane is from top to bottom, perpendicular to the screen.<br>";
text.innerHTML += "Each galaxy is a square of side 32 Kpc (104370 light-years), the diameter of Milky Way. Each galaxy contains 100 billion to 1 trillion stars!<br><br>";
text.innerHTML += "Point at a galaxy: <b>Name, CDS, Simbad, Aladin, NED</b><br>";
text.innerHTML += "Mouse scroll or Pinch zoom: <b>Move to/from centered galaxy (default Milky Way)</b><br>Left click and drag: <b>Rotate</b><br>Right click and drag: <b>Pan</b><br>";
text.innerHTML += "Left click on a galaxy: <b>Center and color it <span style='color:#ff0;'>yellow</span></b><br>";
text.innerHTML += "Right click on a galaxy: <b>Select and color it <span style='color:#0f0;'>green</span></b><br>";
text.innerHTML += "Point at a colored galaxy (except last colored): <b>Turn it back to white</b><br>";
text.innerHTML += "Milky Way: <b>Always <span style='color:#f0f;'>magenta</span></b>";
var centertext = document.createElement('div');
centertext.style.position = 'absolute';
centertext.style.color = '#fff';
centertext.style.bottom = 0 + 'px';
centertext.style.right = 0 + 'px';
document.body.appendChild(centertext);
centertext.innerHTML = "<h1>Center: <span id='centerstring'>Milky Way</span></h1>";
centertext.innerHTML += "<h1>Distance: <span id='centerdist'>200</span> Mpc<h1>";
var centerindex = 0;
var centerstring = document.getElementById("centerstring");
var centerdist = document.getElementById("centerdist");
function onDocumentMouseWheel( event ) {
var cameraloc = camera.position;
centerdist.innerHTML = cameraloc.distanceTo(dots.geometry.vertices[centerindex]).toFixed(2);
}
var search = document.createElement('div');
search.style.position = 'absolute';
search.style.color = '#fff';
search.style.bottom = 10 + 'px';
search.style.left = 0 + 'px';
document.body.appendChild(search);
search.innerHTML = '<h1>Galaxy Search</h1>';
search.innerHTML += '<h3><a href="https://github.com/RiteshSingh/galaxies/blob/master/galaxyname.txt" target="_blank">List of all 4673 galaxies</a></h3>';
search.innerHTML += '<input type="text" placeholder="Galaxy Name" id="srchkey">';
search.innerHTML += '<button type="button" onclick="searchfunc();" id="srchbtn">Search</button>';
search.innerHTML += '<span id="srchtxt"></span>';
var srchtxt = document.getElementById("srchtxt");
document.getElementById("srchkey")
.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
document.getElementById("srchbtn").click();
}
});
var selectedObject = -1;
var clickedObject = -2;
var rightclickedObject = -3;
function searchfunc () {
var srchkey = document.getElementById("srchkey").value;
if (srchkey == "") return;
var key = srchkey.replace(/[^A-Z0-9]/ig, "").toLowerCase();
if (key == 'milkyway') {
srchtxt.innerHTML = "Milky Way galaxy centered and colored <span style='color:#f0f;'>magenta</span>. Use mouse scroll or pinch zoom to move to/from Milky Way.";
text.innerHTML = "<h1>Milky Way</h1>";
text.innerHTML += "<h1><a href='https://solarsystem.nasa.gov/resources/285/the-milky-way-galaxy/' target='_blank'>NASA</a></h1>";
text.innerHTML += "<h1><a href='https://en.wikipedia.org/wiki/Milky_Way' target='_blank'>Wikipedia</a></h1>";
controls.target = dots.geometry.vertices[0];
centerindex = 0;
var cameraloc = camera.position;
centerstring.innerHTML = "Milky Way";
centerdist.innerHTML = cameraloc.distanceTo(dots.geometry.vertices[0]).toFixed(2);
}
else {
var found = false;
for (var i = 0; i < 4673; i++) {
var name = names[i];
if (name.indexOf(',') > -1) {
var namearr = name.split(",");
for (var j = 0; j < namearr.length; j++) {
if (namearr[j].replace(/[^A-Z0-9]/ig, "").toLowerCase() == key) {
found = true;
break;
}
}
if (found) {
srchtxt.innerHTML = name + " galaxy centered and colored <span style='color:#ff0;'>yellow</span>. Use mouse scroll or pinch zoom to move to/from " + name;
controls.target = dots.geometry.vertices[i];
dots.geometry.colors[i] = new THREE.Color('#ff0');
dots.geometry.colorsNeedUpdate = true;
clickedObject = i;
text.innerHTML = "<h1>"+name+"</h1>";
var firstname = name.split(",")[0];
text.innerHTML += "<h1><a href='http://cdsportal.u-strasbg.fr/?target="+firstname+"' target='_blank'>CDS</a></h1>";
text.innerHTML += "<h1><a href='http://simbad.u-strasbg.fr/simbad/sim-id?Ident="+firstname+"' target='_blank'>Simbad</a></h1>";
text.innerHTML += "<h1><a href='https://aladin.u-strasbg.fr/AladinLite/?target="+firstname+"' target='_blank'>Aladin</a></h1>";
text.innerHTML += "<h1><a href='https://ned.ipac.caltech.edu/cgi-bin/objsearch?extend=no&hconst=73&omegam=0.27&omegav=0.73&corr_z=1&out_csys=Equatorial&out_equinox=J2000.0&obj_sort=RA+or+Longitude&of=pre_text&zv_breaker=30000.0&list_limit=5&img_stamp=YES&objname="+firstname+"' target='_blank'>NED</a></h1>";
centerindex = i;
var cameraloc = camera.position;
centerstring.innerHTML = name;
centerdist.innerHTML = cameraloc.distanceTo(dots.geometry.vertices[centerindex]).toFixed(2);
break;
}
}
else {
if (name.replace(/[^A-Z0-9]/ig, "").toLowerCase() == key) {
srchtxt.innerHTML = name + " galaxy centered and colored <span style='color:#ff0;'>yellow</span>. Use mouse scroll or pinch zoom to move to/from " + name;
controls.target = dots.geometry.vertices[i];
dots.geometry.colors[i] = new THREE.Color('#ff0');
dots.geometry.colorsNeedUpdate = true;
clickedObject = i;
text.innerHTML = "<h1>"+name+"</h1>";
var firstname = name.split(",")[0];
text.innerHTML += "<h1><a href='http://cdsportal.u-strasbg.fr/?target="+firstname+"' target='_blank'>CDS</a></h1>";
text.innerHTML += "<h1><a href='http://simbad.u-strasbg.fr/simbad/sim-id?Ident="+firstname+"' target='_blank'>Simbad</a></h1>";
text.innerHTML += "<h1><a href='https://aladin.u-strasbg.fr/AladinLite/?target="+firstname+"' target='_blank'>Aladin</a></h1>";
text.innerHTML += "<h1><a href='https://ned.ipac.caltech.edu/cgi-bin/objsearch?extend=no&hconst=73&omegam=0.27&omegav=0.73&corr_z=1&out_csys=Equatorial&out_equinox=J2000.0&obj_sort=RA+or+Longitude&of=pre_text&zv_breaker=30000.0&list_limit=5&img_stamp=YES&objname="+firstname+"' target='_blank'>NED</a></h1>";
centerindex = i;
var cameraloc = camera.position;
centerstring.innerHTML = name;
centerdist.innerHTML = cameraloc.distanceTo(dots.geometry.vertices[centerindex]).toFixed(2);
found = true;
break;
}
}
}
if (!found) {
srchtxt.innerHTML = srchkey+" not found. Yes, we know we need to improve our search 😊";
}
}
}
function onDocumentMouseMove( event ) {
event.preventDefault();
if ( selectedObject == 0 ) {
dots.geometry.colors[0] = new THREE.Color('#f0f');
dots.geometry.colorsNeedUpdate = true;
selectedObject = -1;
}
else if ( selectedObject == clickedObject ) {
dots.geometry.colors[selectedObject] = new THREE.Color('#ff0');
dots.geometry.colorsNeedUpdate = true;
selectedObject = -1;
} else if ( selectedObject == rightclickedObject ) {
dots.geometry.colors[selectedObject] = new THREE.Color('#0f0');
dots.geometry.colorsNeedUpdate = true;
selectedObject = -1;
} else if ( selectedObject > 0 ) {
dots.geometry.colors[selectedObject] = new THREE.Color('#fff');
dots.geometry.colorsNeedUpdate = true;
selectedObject = -1;
}
var intersects = getIntersects( event.layerX, event.layerY );
if ( intersects.length > 0 ) {
var idx = intersects[0].index;
dots.geometry.colors[idx] = new THREE.Color('#69f');
dots.geometry.colorsNeedUpdate = true;
selectedObject = idx;
if (idx > 0) {
var name = names[idx];
text.innerHTML = "<h1>"+name+"</h1>";
var firstname = name.split(",")[0];
text.innerHTML += "<h1><a href='http://cdsportal.u-strasbg.fr/?target="+firstname+"' target='_blank'>CDS</a></h1>";
text.innerHTML += "<h1><a href='http://simbad.u-strasbg.fr/simbad/sim-id?Ident="+firstname+"' target='_blank'>Simbad</a></h1>";
text.innerHTML += "<h1><a href='https://aladin.u-strasbg.fr/AladinLite/?target="+firstname+"' target='_blank'>Aladin</a></h1>";
text.innerHTML += "<h1><a href='https://ned.ipac.caltech.edu/cgi-bin/objsearch?extend=no&hconst=73&omegam=0.27&omegav=0.73&corr_z=1&out_csys=Equatorial&out_equinox=J2000.0&obj_sort=RA+or+Longitude&of=pre_text&zv_breaker=30000.0&list_limit=5&img_stamp=YES&objname="+firstname+"' target='_blank'>NED</a></h1>";
}
else {
text.innerHTML = "<h1>Milky Way</h1>";
text.innerHTML += "<h1><a href='https://solarsystem.nasa.gov/resources/285/the-milky-way-galaxy/' target='_blank'>NASA</a></h1>";
text.innerHTML += "<h1><a href='https://en.wikipedia.org/wiki/Milky_Way' target='_blank'>Wikipedia</a></h1>";
}
}
}
function onDocumentMouseClick( event ) {
var intersects = getIntersects( event.layerX, event.layerY );
if ( intersects.length > 0 ) {
controls.target = intersects[0].point;
var idx = intersects[0].index;
if (idx) {
dots.geometry.colors[idx] = new THREE.Color('#ff0');
var name = names[idx];
srchtxt.innerHTML = name + " galaxy centered and colored <span style='color:#ff0;'>yellow</span>. Use mouse scroll or pinch zoom to move to/from " + name;
}
else {
dots.geometry.colors[idx] = new THREE.Color('#f0f');
srchtxt.innerHTML = "Milky Way galaxy centered and colored <span style='color:#f0f;'>magenta</span>. Use mouse scroll or pinch zoom to move to/from Milky Way.";
}
dots.geometry.colorsNeedUpdate = true;
clickedObject = idx;
centerindex = idx;
var cameraloc = camera.position;
centerstring.innerHTML = names[idx];
centerdist.innerHTML = cameraloc.distanceTo(dots.geometry.vertices[centerindex]).toFixed(2);
//srchtxt.innerHTML = "";
}
}
function onDocumentMouseRightClick( event ) {
var intersects = getIntersects( event.layerX, event.layerY );
if ( intersects.length > 0 ) {
var idx = intersects[0].index;
if (idx) dots.geometry.colors[idx] = new THREE.Color('#0f0');
else dots.geometry.colors[idx] = new THREE.Color('#f0f');
dots.geometry.colorsNeedUpdate = true;
rightclickedObject = idx;
}
}
var raycaster = new THREE.Raycaster();
raycaster.params.Points.threshold = size*0.5;
var mouseVector = new THREE.Vector3();
function getIntersects( x, y ) {
x = ( x / window.innerWidth ) * 2 - 1;
y = - ( y / window.innerHeight ) * 2 + 1;
mouseVector.set( x, y, 0.5 );
raycaster.setFromCamera( mouseVector, camera );
return raycaster.intersectObject( dots, true );
}
</script>
</body>
</html>