|
|
|
@ -35,14 +35,56 @@ function siderealTime(julianDay)
|
|
|
|
return toRadians(280.46061837 + 360.98564736629 * (julianDay - 2451545.0) + 0.000387933 * T * T - T * T * T / 38710000);
|
|
|
|
return toRadians(280.46061837 + 360.98564736629 * (julianDay - 2451545.0) + 0.000387933 * T * T - T * T * T / 38710000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function drawStars(lat,lon,date){
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Draws a single star in the sky.
|
|
|
|
|
|
|
|
* starPositions is a dictionary that gets modified and it is used later for ploting the constelations
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function drawStar(zeta,theta,z,julianDay,latitude,longitude,starDE,starRA,starMag,starNumber,starPositions){
|
|
|
|
|
|
|
|
var dec = Math.asin(Math.sin(theta) * Math.cos(starDE) * Math.cos(starRA + zeta) + Math.cos(theta) * Math.sin(starDE));
|
|
|
|
|
|
|
|
var ascen = Math.atan2(Math.cos(starDE) * Math.sin(starRA + zeta), Math.cos(theta) * Math.cos(starDE) * Math.cos(starRA + zeta) - Math.sin(theta) * Math.sin(starDE)) + z;
|
|
|
|
|
|
|
|
var H = siderealTime(julianDay) - longitude - ascen;
|
|
|
|
|
|
|
|
//Compute altitude
|
|
|
|
|
|
|
|
var alt = Math.asin(Math.sin(latitude) * Math.sin(dec) + Math.cos(latitude) * Math.cos(dec) * Math.cos(H));
|
|
|
|
|
|
|
|
if(alt >= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//Compute azimuth
|
|
|
|
|
|
|
|
var azi = Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(latitude) - Math.tan(dec) * Math.cos(latitude));
|
|
|
|
|
|
|
|
var x = size / 2 + size / 2 * Math.cos(alt) * Math.sin(azi);
|
|
|
|
|
|
|
|
var y = size / 2 + size / 2 * Math.cos(alt) * Math.cos(azi);
|
|
|
|
|
|
|
|
starPositions[starNumber] = [x,y];
|
|
|
|
|
|
|
|
var magnitude = starMag<1?2:1;
|
|
|
|
|
|
|
|
//Stars between 1.5 and 4 magnitude should get a different colour
|
|
|
|
|
|
|
|
var col=1;
|
|
|
|
|
|
|
|
if (starMag<=1.5)
|
|
|
|
|
|
|
|
col=1;
|
|
|
|
|
|
|
|
else if (starMag>1.5 && starMag<2)
|
|
|
|
|
|
|
|
col=0.9;
|
|
|
|
|
|
|
|
else if (starMag>=2 && starMag<3)
|
|
|
|
|
|
|
|
col=0.7;
|
|
|
|
|
|
|
|
else if (starMag>=3 && starMag<3.5)
|
|
|
|
|
|
|
|
col=0.5;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
col=0.3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g.setColor(col,col,col);
|
|
|
|
|
|
|
|
g.fillCircle(x, y, magnitude);
|
|
|
|
|
|
|
|
if (starMag<1 && settings.starnames)
|
|
|
|
|
|
|
|
g.drawString(starInfo[3],x,y+2);
|
|
|
|
|
|
|
|
g.flip();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function plotSky(lat,lon,date){
|
|
|
|
var longitude = toRadians(-lon);
|
|
|
|
var longitude = toRadians(-lon);
|
|
|
|
var latitude = toRadians(lat);
|
|
|
|
var latitude = toRadians(lat);
|
|
|
|
|
|
|
|
|
|
|
|
var julianDay = toJulianDay(date.getFullYear(), date.getMonth()+1,date.getDate(),
|
|
|
|
var julianDay = toJulianDay(date.getFullYear(), date.getMonth()+1,date.getDate(),
|
|
|
|
date.getHours() + date.getTimezoneOffset() / 60,
|
|
|
|
date.getHours() + date.getTimezoneOffset() / 60,
|
|
|
|
date.getMinutes(), date.getSeconds());
|
|
|
|
date.getMinutes(), date.getSeconds());
|
|
|
|
var size = 240;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
storage = require('Storage');
|
|
|
|
storage = require('Storage');
|
|
|
|
f=storage.read("planetarium.data.csv","r");
|
|
|
|
f=storage.read("planetarium.data.csv","r");
|
|
|
|
@ -63,64 +105,40 @@ function drawStars(lat,lon,date){
|
|
|
|
while (lineend>=0) {
|
|
|
|
while (lineend>=0) {
|
|
|
|
line = f.substring(linestart,lineend);
|
|
|
|
line = f.substring(linestart,lineend);
|
|
|
|
starNumber++;
|
|
|
|
starNumber++;
|
|
|
|
//console.log(line);
|
|
|
|
|
|
|
|
//Process the star
|
|
|
|
//Process the star
|
|
|
|
starInfo = line.split(',');
|
|
|
|
starInfo = line.split(',');
|
|
|
|
//console.log(starInfo[0]);
|
|
|
|
//console.log(starInfo[0]);
|
|
|
|
starRA = parseFloat(starInfo[0]);
|
|
|
|
starRA = parseFloat(starInfo[0]);
|
|
|
|
starDE = parseFloat(starInfo[1]);
|
|
|
|
starDE = parseFloat(starInfo[1]);
|
|
|
|
starMag = parseFloat(starInfo[2]);
|
|
|
|
starMag = parseFloat(starInfo[2]);
|
|
|
|
//var start = new Date().getTime();
|
|
|
|
drawStar(zeta,theta,z,julianDay,latitude,longitude,starDE,starRA,starMag,starNumber,starPositions);
|
|
|
|
var dec = Math.asin(Math.sin(theta) * Math.cos(starDE) * Math.cos(starRA + zeta) + Math.cos(theta) * Math.sin(starDE));
|
|
|
|
|
|
|
|
var ascen = Math.atan2(Math.cos(starDE) * Math.sin(starRA + zeta), Math.cos(theta) * Math.cos(starDE) * Math.cos(starRA + zeta) - Math.sin(theta) * Math.sin(starDE)) + z;
|
|
|
|
|
|
|
|
var H = siderealTime(julianDay) - longitude - ascen;
|
|
|
|
|
|
|
|
//Compute altitude
|
|
|
|
|
|
|
|
var alt = Math.asin(Math.sin(latitude) * Math.sin(dec) + Math.cos(latitude) * Math.cos(dec) * Math.cos(H));
|
|
|
|
|
|
|
|
if(alt >= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//Compute azimuth
|
|
|
|
|
|
|
|
var azi = Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(latitude) - Math.tan(dec) * Math.cos(latitude));
|
|
|
|
|
|
|
|
var x = size / 2 + size / 2 * Math.cos(alt) * Math.sin(azi);
|
|
|
|
|
|
|
|
var y = size / 2 + size / 2 * Math.cos(alt) * Math.cos(azi);
|
|
|
|
|
|
|
|
starPositions[starNumber] = [x,y];
|
|
|
|
|
|
|
|
var magnitude = starMag<1?2:1;
|
|
|
|
|
|
|
|
//Stars between 1.5 and 4 magnitude should get a different colour
|
|
|
|
|
|
|
|
var col=1;
|
|
|
|
|
|
|
|
if (starMag<=1.5)
|
|
|
|
|
|
|
|
col=1;
|
|
|
|
|
|
|
|
else if (starMag>1.5 && starMag<2)
|
|
|
|
|
|
|
|
col=0.9;
|
|
|
|
|
|
|
|
else if (starMag>=2 && starMag<3)
|
|
|
|
|
|
|
|
col=0.7;
|
|
|
|
|
|
|
|
else if (starMag>=3 && starMag<3.5)
|
|
|
|
|
|
|
|
col=0.5;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
col=0.3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g.setColor(col,col,col);
|
|
|
|
|
|
|
|
g.fillCircle(x, y, magnitude);
|
|
|
|
|
|
|
|
if (starMag<1 && settings.starnames)
|
|
|
|
|
|
|
|
g.drawString(starInfo[3],x,y+2);
|
|
|
|
|
|
|
|
g.flip();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
linestart = lineend+1;
|
|
|
|
linestart = lineend+1;
|
|
|
|
lineend = f.indexOf("\n",linestart);
|
|
|
|
lineend = f.indexOf("\n",linestart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.constellations){
|
|
|
|
if (settings.constellations){
|
|
|
|
//Each star has a number (the position on the file (line number)). These are the lines
|
|
|
|
linenum=linestart = 0;
|
|
|
|
//joining each star in the constellations.
|
|
|
|
fc=storage.read("planetarium.const.csv","r");
|
|
|
|
constelations=[[[7,68],[10,53],[53,56],[28,68],"Orion"],[[13,172],[13,340],[293,340],[29,293],"Taurus"],
|
|
|
|
lineend = fc.indexOf("\n");
|
|
|
|
[[155,8],"Canis Menor"],[[36,81],[87,81],[235,87],[33,235],[33,75],[75,40],[36,235],"Ursa Major"],[[67,91],[74,67],[91,110],[110,252],"Cassiopeia"],[[23,166],[16,294],[294,44],[166,149],[230,149],[16,23],"Gemini"],[[88,218],[215,292],[218,292],[245,88],[292,245],[215,218],"Cepheus"],[[150,62],[150,175],[175,35],[403,62],[487,158],[384,487],[384,158],[35,158],[487,403],"Perseus"],[[19,65],[65,90],[65,147],[466,65],[466,189],[147,401],[213,90],"Cygnus"],[[6,42],[168,6],[168,113],[113,29],[104,29],[104,42],"Auriga"],[[1,47],[1,37],[37,22],[22,178],[37,89],"Can Maior"],[[3,118],[118,279],[279,286],[286,180],[180,316],[316,3],"Bootes"]];
|
|
|
|
while (lineend>=0) {
|
|
|
|
g.setColor(0,255,0);
|
|
|
|
linenum++;
|
|
|
|
for (i=0;i<constelations.length;i++)
|
|
|
|
//In this file, each constelation are two lines. The first one the name, the second the lines joining stars
|
|
|
|
{
|
|
|
|
var name = fc.substring(linestart,lineend);
|
|
|
|
|
|
|
|
linestart = lineend+1;
|
|
|
|
|
|
|
|
lineend = fc.indexOf("\n",linestart);
|
|
|
|
|
|
|
|
var lines = fc.substring(linestart,lineend).split(',');
|
|
|
|
|
|
|
|
linestart = lineend+1;
|
|
|
|
|
|
|
|
lineend = fc.indexOf("\n",linestart);
|
|
|
|
|
|
|
|
g.setColor(0,255,0);
|
|
|
|
|
|
|
|
if (linenum>11)
|
|
|
|
|
|
|
|
break;
|
|
|
|
constelationShowing=false;
|
|
|
|
constelationShowing=false;
|
|
|
|
for (j=0;j<constelations[i].length-1;j++){
|
|
|
|
|
|
|
|
positionStar1=starPositions[constelations[i][j][0]];
|
|
|
|
for (j=0;j<lines.length;j++){
|
|
|
|
positionStar2=starPositions[constelations[i][j][1]];
|
|
|
|
positions = lines[j].split(' ');
|
|
|
|
|
|
|
|
positionStar1=starPositions[parseInt(positions[0])];
|
|
|
|
|
|
|
|
positionStar2=starPositions[parseInt(positions[1])];
|
|
|
|
//Both stars need to be visible
|
|
|
|
//Both stars need to be visible
|
|
|
|
if (positionStar1 && positionStar2)
|
|
|
|
if (positionStar1 && positionStar2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -132,12 +150,14 @@ function drawStars(lat,lon,date){
|
|
|
|
g.flip();
|
|
|
|
g.flip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Write the name
|
|
|
|
//Write the name
|
|
|
|
if (constelationShowing && settings.consnames)
|
|
|
|
if (constelationShowing && true)
|
|
|
|
g.drawString(constelations[i][constelations[i].length-1],positionStar2[0]+10,positionStar2[1]);
|
|
|
|
g.drawString(name,positionStar2[0]+10,positionStar2[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const size = 240; //Bangle size screen
|
|
|
|
|
|
|
|
|
|
|
|
Bangle.setGPSPower(1);
|
|
|
|
Bangle.setGPSPower(1);
|
|
|
|
|
|
|
|
|
|
|
|
var gps = { fix : 0};
|
|
|
|
var gps = { fix : 0};
|
|
|
|
@ -157,7 +177,7 @@ Bangle.on('GPS',function(gp) {
|
|
|
|
lon = gp.lon;
|
|
|
|
lon = gp.lon;
|
|
|
|
Bangle.setGPSPower(0);
|
|
|
|
Bangle.setGPSPower(0);
|
|
|
|
setTimeout(function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
drawStars(lat,lon,new Date());},0);
|
|
|
|
plotSky(lat,lon,new Date());},0);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
g.setFont("Vector",20);
|
|
|
|
g.setFont("Vector",20);
|
|
|
|
g.drawString("Waiting for position",120,120);
|
|
|
|
g.drawString("Waiting for position",120,120);
|
|
|
|
|