Skip to content

Commit

Permalink
Merge pull request #1 from espruino/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
dapgo committed Feb 9, 2021
2 parents 5f305e0 + 11530da commit 3017dc7
Show file tree
Hide file tree
Showing 26 changed files with 18,418 additions and 76 deletions.
17 changes: 10 additions & 7 deletions apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@
"name": "Round clock with seconds, minutes and date",
"shortName":"Round Clock",
"icon": "app.png",
"version":"0.03",
"version":"0.04",
"description": "Designed round clock with ticks for minutes and seconds and heart rate indication",
"tags": "clock",
"type": "clock",
Expand Down Expand Up @@ -2714,12 +2714,15 @@
"name": "Planetarium",
"shortName":"Planetarium",
"icon": "planetarium.png",
"version":"0.02",
"readme": "README.md",
"version":"0.03",
"description": "Planetarium showing up to 500 stars using the watch location and time",
"tags": "",
"storage": [
{"name":"planetarium.app.js","url":"planetarium.app.js"},
{"name":"planetarium.data.csv","url":"planetarium.data.csv"},
{"name":"planetarium.const.csv","url":"planetarium.const.csv"},
{"name":"planetarium.extra.csv","url":"planetarium.extra.csv"},
{"name":"planetarium.settings.js","url":"settings.js"},
{"name":"planetarium.img","url":"planetarium-icon.js","evaluate":true}
],
Expand All @@ -2730,14 +2733,14 @@
{ "id": "tapelauncher",
"name": "Tape Launcher",
"icon": "icon.png",
"version":"0.01",
"version":"0.02",
"description": "An App launcher, icons displayed in a horizontal tape, swipe or use buttons",
"readme": "README.md",
"tags": "tool,system,launcher",
"type":"launch",
"storage": [
{"name":"tapelaunch.app.js","url":"app.js"},
{"name":"tapelaunch.img","url":"icon.js","evaluate":true}
{"name":"tapelauncher.app.js","url":"app.js"},
{"name":"tapelauncher.img","url":"icon.js","evaluate":true}
]
},
{ "id": "oblique",
Expand All @@ -2759,8 +2762,8 @@
"description": "Basic app to test the bangle.js input interface. It displays the result in text or a switch on/off image.",
"tags": "input,interface,buttons,touch",
"storage": [
{"name":"test_userInput.app.js","url":"app.js"},
{"name":"test_userInput.img","url":"app-icon.js","evaluate":true}
{"name":"testuserinput.app.js","url":"app.js"},
{"name":"testuserinput.img","url":"app-icon.js","evaluate":true}
]
}

Expand Down
3 changes: 2 additions & 1 deletion apps/planetarium/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
0.01: New App!
0.02: Major speed improvement. Added more stars. Up to 500!
0.02: Major speed improvement. Added more stars. Up to 500!
0.03: Added more stars and constellations. Now it shows 20 constellations.
17 changes: 15 additions & 2 deletions apps/planetarium/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This planetarium takes your position and time and plots the sky as it is.

No planets, or moon, only stars. It can show the 500 most brilliant stars in the sky.

Plan is to show also constellations, but this is work in progress. Now it shows Taurus and Orion as examples.
It shows also constellations. Now it has 20 constellations but this is work in progress. Only northern hemisphere covered now.

I think code is quite optimized already. It runs as fast as I could make it run. If someone has some ideas to speed it up, I could plot more stars.

Expand All @@ -16,4 +16,17 @@ The planetarium plots the stars as if you are looking to the sky (with your watc
## Improvements
I plan to add more constellations as soon as I have time. I am adding the constellations that I know of, but the plan is to add all the main ones (at least for North Hemisphere).

Please note that the watch hardware is limited and computing the stars positions is a quite intensive task for this little processor. This is why it plots only stars and no planets or the moon. For plotting the planets, storage will be a limiting factor as well as computing the position for planets needs more initial data compared with stars.
Please note that the watch hardware is limited and computing the stars positions is a quite intensive task for this little processor. This is why it plots only stars and no planets or the moon. For plotting the planets, storage will be a limiting factor as well as computing the position for planets needs more initial data compared with stars.

## Do you want to contribute?
Maybe you want to add some more constellations to the planetarium. As you can see I didn't cover constellations in the south hemisphere. How to do it? It is a bit tedious but it can be done and you will learn the constellations pretty well at the end of it. Steps:
- Open the file `plantearium.data.csv`. There you have the 500 stars that we have in the planetarium. The number of each star is the line number. For instance for Sirius, the star number will be 1.
- Find the two stars that you want to join in your constellation (a constellation line). For identifying a star you have to have a look at the name, usually something like `AL UMA` (alpha star of constellation ursa major). Lets say that you want to join stars 155 and 8 (this is constellation canis menor, that only has a line joining two stars).
- Go to file `planetarium.const.csv` and add two lines for your new constellation. The first one will be the name of the constellation, the second one the pair of stars that you want to join, separated by coma (see the file for examples).
- Do not forget to add a break line after the last constellation.
- Upload the new `planetarium.const.csv` to your bangle (or emulator) and test it out.

What is a constellation star is not in the 500 star list in `planetarium.data.csv`? If you need another star to draw the constellation you can find that star in the full star list (`starinfo/planetarium.stars.csv`) and put it in `planetarium.extra.csv`. That stars will be loaded only when constellations are shown. In order to refer to these extra stars in the `planetarium.const.csv` you have to use the code `e_linenumber`, in order to differentiate them from the stars in the normal file. For instance, to refer to the first star in the file `planetarium.extra.csv`, you will refer it as `e_1`. Do not forget to add an extra line at the end as in the other files.

## Development version
Please check the latest development version [here](https://github.com/pglez82/BangleApps)
140 changes: 87 additions & 53 deletions apps/planetarium/planetarium.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,59 @@ function siderealTime(julianDay)
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,starInfo,starNumber,starPositions){
let starRA = parseFloat(starInfo[0]);
let starDE = parseFloat(starInfo[1]);
let starMag = parseFloat(starInfo[2]);
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 latitude = toRadians(lat);

var julianDay = toJulianDay(date.getFullYear(), date.getMonth()+1,date.getDate(),
date.getHours() + date.getTimezoneOffset() / 60,
date.getMinutes(), date.getSeconds());
var size = 240;


storage = require('Storage');
f=storage.read("planetarium.data.csv","r");
Expand All @@ -63,64 +108,50 @@ function drawStars(lat,lon,date){
while (lineend>=0) {
line = f.substring(linestart,lineend);
starNumber++;
//console.log(line);
//Process the star
starInfo = line.split(',');
//console.log(starInfo[0]);
starRA = parseFloat(starInfo[0]);
starDE = parseFloat(starInfo[1]);
starMag = parseFloat(starInfo[2]);
//var start = new Date().getTime();
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();

}
drawStar(zeta,theta,z,julianDay,latitude,longitude,starInfo,starNumber,starPositions);
linestart = lineend+1;
lineend = f.indexOf("\n",linestart);
}


if (settings.constellations){
//Each star has a number (the position on the file (line number)). These are the lines
//joining each star in the constellations.
constelations=[[[7,68],[10,53],[53,56],[28,68],"Orion"],[[13,172],[13,340],[293,340],[29,293],"Taurus"],
[[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"]];
g.setColor(0,255,0);
for (i=0;i<constelations.length;i++)
{
//First plot the extra stars for the constellations
fe=storage.read("planetarium.extra.csv","r");
linenum=linestart = 0;
lineend = fe.indexOf("\n");
let starNumber = 0;
while (lineend>=0) {
line = fe.substring(linestart,lineend);
starNumber++;
starInfo = line.split(',');
drawStar(zeta,theta,z,julianDay,latitude,longitude,starInfo,"e_"+starNumber,starPositions);
linestart = lineend+1;
lineend = fe.indexOf("\n",linestart);
}
//End of ploting extra stars

linenum=linestart = 0;
fc=storage.read("planetarium.const.csv","r");
lineend = fc.indexOf("\n");
while (lineend>=0) {
linenum++;
//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);

constelationShowing=false;
for (j=0;j<constelations[i].length-1;j++){
positionStar1=starPositions[constelations[i][j][0]];
positionStar2=starPositions[constelations[i][j][1]];

for (j=0;j<lines.length;j++){
positions = lines[j].split(' ');
positionStar1=starPositions[positions[0]];
positionStar2=starPositions[positions[1]];
//Both stars need to be visible
if (positionStar1 && positionStar2)
{
Expand All @@ -131,13 +162,16 @@ function drawStars(lat,lon,date){
constelationShowing=false;
g.flip();
}

//Write the name
if (constelationShowing && settings.consnames)
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);

var gps = { fix : 0};
Expand All @@ -157,7 +191,7 @@ Bangle.on('GPS',function(gp) {
lon = gp.lon;
Bangle.setGPSPower(0);
setTimeout(function() {
drawStars(lat,lon,new Date());},0);
plotSky(lat,lon,new Date());},0);
} else {
g.setFont("Vector",20);
g.drawString("Waiting for position",120,120);
Expand Down
40 changes: 40 additions & 0 deletions apps/planetarium/planetarium.const.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Orion
7 68,10 53,53 56,28 68
Taurus
13 172,13 340,293 340,29 293,340 276
Canis Menor
155 8
Ursa Major
36 81,87 81,235 87,33 235,33 75,75 40,36 235
Cassiopeia
67 91,74 67,91 110,110 252
Gemini
23 166,16 294,294 44,166 149,230 149,16 23
Cepheus
88 218,215 292,218 292,245 88,292 245,215 218
Perseus
150 62,150 175,175 35,403 62,487 158,384 487,384 158,35 158,487 e_3,e_3 403
Cygnus
19 65,65 90,65 147,466 65,466 189,147 401,213 90
Auriga
6 42,168 6,168 113,113 29,104 29,104 42
Can Maior
1 37,22 178,37 435,435 89,1 e_18,e_18 e_19,e_19 e_20,e_20 e_18,37 277,277 22,450 488,277 488,488 47,1 488,e_21 488,22 495
Bootes
3 118,118 279,279 286,286 180,180 316,316 3
Lupus
140 210,322 140,322 410,410 98,98 234,234 210,98 302,302 362,234 e_1,234 e_2
Leo
21 291,102 270,102 291,96 63,63 241,241 96,96 102,21 241,457 270,457 167
Lyra
5 e_4,e_4 e_5,e_5 221,221 274,274 e_4
Corona Borealis
69 353,353 e_6,69 429,429 e_7,e_7 e_8,e_8 e_9
Herculis
296 135,135 477,477 203,203 296,443 203,443 408,135 127,127 380,e_10 477,464 296,265 e_10,e_10 202
Ursa Minor
50 e_11,e_11 e_14,e_14 e_13,e_13 e_12,e_12 186,186 58,58 e_13
Draco
e_15 131,131 70,70 382,382 e_15,382 187,187 423,423 e_16,e_16 207,207 122,122 e_17,e_17 232,232 342,342 452,452 428
Pegasus
92 85,138 54,54 85,138 92,283 85,283 389,160 85,92 258,258 297,297 83
2 changes: 1 addition & 1 deletion apps/planetarium/planetarium.data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
3.874,-1.380,3.8,AL APS
4.745,0.502,3.8,OK HER
5.184,1.226,3.8,EP DRA
1.172,0.279,43.8,TH1 TAU
1.172,0.279,3.8,TH1 TAU
2.272,-0.814,3.8,_
2.335,-1.058,3.8,_
2.781,-0.842,3.8,_
Expand Down
21 changes: 21 additions & 0 deletions apps/planetarium/planetarium.extra.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1.394,-0.230,4.3,LA LEP
1.367,-0.226,4.4,KA LEP
0.825,0.866,4.0,JO PER
4.950,0.644,4.3,DE2 LYR
5.046,0.666,4.4,TH LYR
4.071,0.547,4.1,TH CRB
4.143,0.455,4.6,DE CRB
4.178,0.469,4.2,EP CRB
4.195,0.521,5.0,JO CRB
4.585,0.456,4.4,LA HER
4.591,1.511,4.4,DE UMI
4.265,1.322,5.0,ET UMI
4.119,1.358,4.3,ZE UMI
4.389,1.432,4.2,EP UMI
4.591,0.963,4.9,NY2 DRA
5.042,1.280,4.5,TA DRA
4.197,1.022,4.0,TH DRA
1.816,-0.298,4.4,JO CMA
1.849,-0.273,4.1,GA CMA
1.807,-0.210,4.1,TH CMA
1.724,-0.401,4.5,XI2 CMA
2 changes: 1 addition & 1 deletion apps/planetarium/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// make sure to enclose the function in parentheses
(function(back) {
let settings = require('Storage').readJSON('planetarium.json',1)||{};
let settings = require('Storage').readJSON('planetarium.json',1)||{"starnames":false,"constellations":true,"consnames":false};
function save(key, value) {
settings[key] = value;
require('Storage').write('planetarium.json',settings);
Expand Down
Loading

0 comments on commit 3017dc7

Please sign in to comment.