diff --git a/apps.json b/apps.json index 44b79768b..09462a8ba 100644 --- a/apps.json +++ b/apps.json @@ -2693,4 +2693,22 @@ {"name":"intervals.img","url":"intervals-icon.js","evaluate":true} ] } +, +{ "id": "planetarium", + "name": "Planetarium", + "shortName":"Planetarium", + "icon": "planetarium.png", + "version":"0.01", + "description": "Planetarium showing up to 350 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.settings.js","url":"settings.js"}, + {"name":"planetarium.img","url":"planetarium-icon.js","evaluate":true} + ], + "data":[ + {"name":"planetarium.json"} + ] +} ] diff --git a/apps/planetarium/README.md b/apps/planetarium/README.md new file mode 100644 index 000000000..ff2178888 --- /dev/null +++ b/apps/planetarium/README.md @@ -0,0 +1,11 @@ +# Planetarium + +This planetarium takes your position and time and plots the sky as it is. + +No planets, or moon, only stars. It can show the 350 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. + +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. + +Basic equations to compute declination and right ascension for stars where taken from this [github repo](https://github.com/Michi83/planetarium). \ No newline at end of file diff --git a/apps/planetarium/planetarium-icon.js b/apps/planetarium/planetarium-icon.js new file mode 100644 index 000000000..b1644b98b --- /dev/null +++ b/apps/planetarium/planetarium-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwgkhiIAECp8BCwoABiAWVDBoWKDBgWLMZQuMGBQWNGBAuHjtBGBomHjvRGBhdI7vUMJgLGilE7vdohJHC5MUCoIADDAxGKpoWDJI5ICC44wESJS1IGAR4IJAQXgI4YXJXpAXBoJiBBhEQC5JzCigXTABgXeIBJODC5MdaA4hB6IXLpoNFEIbDFC4zRJboIXJojRC6lEBwdEegXdBIYXDZwIAEeY4ABNgQvEEgfdMIkdBIZTDC4gwELwouGC4MABoyQGHQSCEgAXHSAxSDC7pgDKQJiBL4xcBBIZeBC4cUNIUUC4oJGC4RIEAB4WCC7BgDABxGDGCYWEGCIuFGCIWGGB4uHGB4WIGBouJDBgWLDBQWNMZAVPACAA==")) \ No newline at end of file diff --git a/apps/planetarium/planetarium.app.js b/apps/planetarium/planetarium.app.js new file mode 100644 index 000000000..bd36bf4b7 --- /dev/null +++ b/apps/planetarium/planetarium.app.js @@ -0,0 +1,161 @@ +/* + * Degrees to radians + */ +function toRadians(degrees) +{ + return Math.PI * degrees / 180; +} + +/* + * Julian day number + * Assumes a proleptic gregorian calendar where the year 1 is preceded by the + * year 0. + */ +function toJulianDay(year, month, day, hours, minutes, seconds) +{ + day += hours / 24 + minutes / 1440 + seconds / 86400; + + if(month <= 2) + { + year -= 1; + month += 12; + } + + var A = Math.floor(year / 100); + var B = 2 - A + Math.floor(A / 4); + return Math.floor(365.25 * (year + 4716)) + Math.floor(30.6001 * (month + 1)) + day + B - 1524.5; +} + +/* + * Sidereal time in Greenwich + */ +function siderealTime(julianDay) +{ + var T = (julianDay - 2451545.0) / 36525; + return toRadians(280.46061837 + 360.98564736629 * (julianDay - 2451545.0) + 0.000387933 * T * T - T * T * T / 38710000); +} + +function drawStars(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"); + linestart=0; + g.clear(); + + //Common calculations based only on time + var t = (julianDay - 2451545.0) / 36525; + var zeta = toRadians((2306.2181 * t + 0.30188 * t * t + 0.017998 * t * t * t) / 3600); + var theta = toRadians((2004.3109 * t - 0.42665 * t * t - 0.041833 * t * t * t) / 3600); + var z = toRadians((2306.2181 * t + 1.09468 * t * t + 0.018203 * t * t * t) / 3600); + + + let starNumber = 0; + var starPositions = {}; + + for (i=0;i= 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.5?2:1; + g.fillCircle(x, y, magnitude); + if (starMag<1 && settings.starnames) + g.drawString(starInfo[3],x,y+2); + g.flip(); + + } + } + } + + 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],"Ursa Major"],[[67,91],[74,67],[91,110],[110,252],"Cassiopeia"],[[23,166],[16,294],[294,44],[166,149],[230,149],[16,23],"Gemini"]]; + g.setColor(0,255,0); + for (i=0;iprevSats || prevSats===0){ + prevSats = gp.satellites; + g.clearRect(0,150,240,180); + g.drawString("Got "+gp.satellites+" satellites",120,160); + } + g.clearRect(0,180,240,220); + g.drawString("GMT:"+(date.getHours()+date.getTimezoneOffset() / 60)+":"+date.getMinutes()+":"+date.getSeconds(),120,200); + g.drawString(date.getDate()+'/'+date.getMonth()+1+"/"+date.getFullYear(),120,215); + g.flip(); + } +}); \ No newline at end of file diff --git a/apps/planetarium/planetarium.data.csv b/apps/planetarium/planetarium.data.csv new file mode 100644 index 000000000..7b178c767 --- /dev/null +++ b/apps/planetarium/planetarium.data.csv @@ -0,0 +1,343 @@ +1.768,-0.292,-1.5,Sirius +1.675,-0.920,-0.7,AL CAR +3.734,0.335,-0.0,Arcturus +3.838,-1.062,-0.0,AL1 CEN +4.874,0.677,0.0,Vega +1.382,0.803,0.1,Capella +1.372,-0.143,0.1,Rigel +2.004,0.091,0.4,Procyion +0.426,-0.999,0.5,AL ERI +1.550,0.129,0.5,Betelgeuse +3.682,-1.054,0.6,BE CEN +5.196,0.155,0.8,AL AQL +1.204,0.288,0.8,Aldebaran +4.317,-0.461,1.0,AL SCO +3.513,-0.195,1.0,AL VIR +2.030,0.489,1.1,Pollux +6.011,-0.517,1.2,AL PSA +3.350,-1.042,1.2,BE CRU +5.417,0.790,1.2,Deneb +3.838,-1.062,1.3,AL2 CEN +2.655,0.209,1.4,AL LEO +1.827,-0.506,1.5,EP CMA +1.984,0.557,1.6,Castor +3.258,-1.101,1.6,AL1 CRU +1.984,0.557,1.6,AL GEM +3.278,-0.997,1.6,GA CRU +4.597,-0.648,1.6,LA SCO +1.419,0.111,1.6,Bellatrix +1.424,0.499,1.6,BE TAU +2.414,-1.217,1.7,BE CAR +1.467,-0.021,1.7,EP ORI +5.796,-0.820,1.7,AL GRU +3.377,0.977,1.8,EP UMA +2.136,-0.826,1.8,GA2 VEL +0.892,0.870,1.8,AL PER +2.896,1.078,1.8,AL UMA +1.869,-0.461,1.8,DE CMA +4.818,-0.600,1.9,EP SGR +2.193,-1.039,1.9,EP CAR +3.611,0.861,1.9,ET UMA +4.613,-0.750,1.9,TH SCO +1.569,0.784,1.9,BE AUR +4.401,-1.205,1.9,AL TRA +1.735,0.286,1.9,GA GEM +5.348,-0.990,1.9,AL PAV +2.289,-0.955,2.0,DE VEL +1.670,-0.313,2.0,BE CMA +2.477,-0.151,2.0,AL HYA +0.555,0.409,2.0,AL ARI +0.663,1.558,2.0,AL UMI +4.954,-0.459,2.0,SI SGR +0.190,-0.314,2.0,BE CET +1.487,-0.034,2.0,ZE ORI +0.037,0.508,2.1,AL AND +0.304,0.622,2.1,BE AND +1.517,-0.169,2.1,KA ORI +3.694,-0.635,2.1,TH CEN +3.886,1.294,2.1,BE UMI +4.603,0.219,2.1,AL OPH +3.258,-1.101,2.1,AL2 CRU +5.946,-0.818,2.1,BE GRU +0.821,0.715,2.1,BE PER +3.094,0.254,2.1,BE LEO +3.323,-0.855,2.2,GA CEN +5.333,0.703,2.2,GA CYG +2.391,-0.758,2.2,LA VEL +0.177,0.987,2.2,AL CAS +1.449,-0.005,2.2,DE ORI +4.078,0.466,2.2,AL CRB +4.698,0.899,2.2,GA DRA +2.110,-0.698,2.2,ZE PUP +2.431,-1.035,2.2,JO CAR +0.541,0.739,2.3,GA1 AND +0.040,1.032,2.3,BE CAS +3.508,0.959,2.3,ZE UMA +4.408,-0.599,2.3,EP SCO +3.577,-0.933,2.3,EP CEN +3.848,-0.827,2.3,AL LUP +3.820,-0.736,2.3,ET CEN +4.190,-0.395,2.3,DE SCO +2.888,0.984,2.4,BE UMA +0.115,-0.738,2.4,AL PHE +5.691,0.172,2.4,EP PEG +4.636,-0.681,2.4,KA SCO +6.038,0.490,2.4,BE PEG +4.496,-0.274,2.4,ET OPH +3.115,0.937,2.4,GA UMA +5.579,1.092,2.4,AL CEP +1.938,-0.511,2.5,ET CMA +5.438,0.593,2.5,EP CYG +0.247,1.060,2.5,GA CAS +6.042,0.265,2.5,AL PEG +2.453,-0.960,2.5,KA VEL +0.795,0.071,2.5,AL CET +3.646,-0.825,2.5,ZE CEN +2.941,0.358,2.6,DE LEO +4.351,-0.184,2.6,ZE OPH +1.452,-0.311,2.6,AL LEP +3.211,-0.306,2.6,GA CRV +3.178,-0.885,2.6,DE CEN +4.986,-0.522,2.6,ZE SGR +2.705,0.346,2.6,GA1 LEO +4.001,-0.164,2.6,BE LIB +1.570,0.649,2.6,TH AUR +4.213,-0.346,2.6,BE1 SCO +0.500,0.363,2.6,BE ARI +1.482,-0.595,2.6,AL COL +3.292,-0.408,2.6,BE CRV +4.120,0.112,2.6,AL SER +0.374,1.051,2.7,DE CAS +3.642,0.321,2.7,ET BOO +3.921,-0.753,2.7,BE LUP +1.296,0.579,2.7,JO AUR +2.822,-0.863,2.7,MY VEL +3.304,-1.207,2.7,AL MUS +4.585,-0.651,2.7,YP SCO +1.907,-0.647,2.7,PI PUP +3.861,0.473,2.7,EP BOO +4.804,-0.521,2.7,DE SGR +5.176,0.185,2.7,GA AQL +4.251,-0.064,2.7,DE OPH +4.293,1.074,2.7,ET DRA +3.493,-0.641,2.8,JO CEN +3.887,-0.280,2.8,AL2 LIB +2.805,-1.124,2.8,TH CAR +1.464,-0.103,2.8,JO ORI +4.321,0.375,2.8,BE HER +4.640,0.080,2.8,BE OPH +4.080,-0.718,2.8,GA LUP +1.343,-0.089,2.8,BE ERI +4.583,0.913,2.8,BE DRA +0.112,-1.348,2.8,BE HYI +3.208,-1.025,2.8,DE CRU +2.127,-0.424,2.8,RH PUP +4.369,0.552,2.8,ZE HER +4.834,-0.444,2.8,LA SGR +4.345,-0.492,2.8,TA SCO +0.058,0.265,2.8,GA PEG +3.413,0.191,2.8,EP VIR +1.432,-0.362,2.8,BE LEP +1.022,0.556,2.9,ZE PER +4.168,-1.107,2.9,BE TRA +4.561,-0.969,2.9,BE ARA +0.518,-1.075,2.9,AL HYI +5.840,-1.052,2.9,AL TUC +0.993,0.421,2.9,ET TAU +5.170,0.788,2.9,DE CYG +5.703,-0.281,2.9,DE CAP +1.671,0.393,2.9,MY GEM +1.038,0.698,2.9,EP PER +4.010,-1.199,2.9,GA TRA +4.184,-0.456,2.9,PI SCO +4.281,-0.447,2.9,SI SCO +5.017,-0.367,2.9,PI SGR +1.951,0.145,2.9,BE CMI +3.386,0.669,2.9,AL2 CVN +5.635,-0.097,2.9,BE AQR +0.806,0.934,2.9,GA PER +1.789,-0.883,2.9,TA PUP +5.947,0.527,2.9,ET PEG +1.039,-0.236,3.0,GA ERI +3.272,-0.288,3.0,DE CRV +4.590,-0.871,3.0,AL ARA +2.562,-1.136,3.0,YP CAR +5.785,-0.006,3.0,AL AQR +1.762,0.439,3.0,EP GEM +2.556,0.415,3.0,EP LEO +1.318,0.765,3.0,EP AUR +4.738,-0.531,3.0,GA2 SGR +4.998,0.242,3.0,ZE AQL +0.565,0.611,3.0,BE TRI +1.473,0.369,3.0,ZE TAU +3.186,-0.395,3.0,EP CRV +3.486,-0.404,3.0,GA HYA +0.973,0.834,3.0,DE PER +2.922,0.777,3.0,PS UMA +5.733,-0.652,3.0,GA GRU +1.659,-0.525,3.0,ZE CMA +1.846,-0.416,3.0,OK2 CMA +3.805,0.669,3.0,GA BOO +4.658,-0.700,3.0,JO1 SCO +0.608,-0.052,3.0,OK CET +3.620,-0.741,3.0,MY CEN +2.715,0.724,3.0,MY UMA +3.344,-1.189,3.0,BE MUS +4.017,1.254,3.0,GA UMI +5.029,1.181,3.1,DE DRA +4.415,-0.664,3.1,MY1 SCO +5.108,0.488,3.1,BE1 CYG +5.328,-0.258,3.1,BE CAP +2.336,0.104,3.1,ZE HYA +2.835,-0.283,3.1,NY HYA +4.789,-0.642,3.1,ET SGR +5.400,-0.825,3.1,AL IND +1.531,-0.624,3.1,BE COL +2.448,0.600,3.1,AL LYN +2.492,-0.995,3.1,_ +3.036,-1.100,3.1,LA CEN +3.923,-0.735,3.1,KA CEN +4.445,-0.977,3.1,ZE ARA +2.353,0.838,3.1,JO UMA +4.516,0.434,3.1,DE HER +4.516,0.642,3.2,PI HER +1.337,0.720,3.2,ET AUR +1.736,-0.754,3.2,NY PUP +2.500,0.902,3.2,TH UMA +4.489,1.147,3.2,ZE DRA +4.912,-0.471,3.2,PH SGR +1.265,0.121,3.2,PI3 ORI +1.333,-0.390,3.2,EP LEP +3.851,-1.134,3.2,AL CIR +4.440,0.164,3.2,KA OPH +5.554,0.528,3.2,ZE CYG +4.668,-0.647,3.2,_ +6.193,1.355,3.2,GA CEP +4.020,-0.709,3.2,DE LUP +5.285,-0.014,3.2,TH AQL +5.623,1.232,3.2,BE CEP +0.992,-1.296,3.2,GA HYI +4.269,-0.082,3.2,EP OPH +4.970,0.571,3.2,GA LYR +1.960,-0.756,3.2,SI PUP +4.805,-0.051,3.3,ET SER +0.172,0.539,3.3,DE AND +1.196,-0.961,3.3,AL DOR +1.781,-1.081,3.3,AL PIC +3.693,-0.466,3.3,PI HYA +4.547,-0.436,3.3,TH OPH +5.998,-0.276,3.3,DE AQR +1.636,0.393,3.3,ET GEM +3.945,-0.441,3.3,SI LIB +4.036,1.029,3.3,JO DRA +0.288,-0.815,3.3,BE PHE +1.365,-0.283,3.3,MY LEP +3.209,0.995,3.3,DE UMA +2.678,-1.222,3.3,OM CAR +2.758,-1.077,3.3,_ +5.004,-0.483,3.3,TA SGR +4.504,-0.755,3.3,ET SCO +2.048,-0.434,3.3,XI PUP +2.942,0.269,3.3,TH LEO +4.561,-0.984,3.3,GA ARA +4.708,-0.171,3.3,NY OPH +1.110,-1.090,3.4,AL RET +5.807,1.016,3.4,ZE CEP +1.416,-0.042,3.4,ET ORI +1.768,0.225,3.4,XI GEM +2.226,1.060,3.4,OK UMA +5.085,0.054,3.4,DE AQL +3.555,-0.010,3.4,ZE VIR +4.026,-0.780,3.4,EP LUP +0.499,1.111,3.4,EP CAS +2.298,0.112,3.4,EP HYA +3.384,0.059,3.4,DE VIR +0.808,0.678,3.4,RH PER +1.172,0.277,3.4,TH2 TAU +2.693,-1.070,3.4,_ +5.940,0.189,3.4,ZE PEG +0.386,-0.756,3.4,GA PHE +0.493,0.516,3.4,AL TRI +3.619,-0.728,3.4,NY CEN +3.981,-0.909,3.4,ZE LUP +4.189,-0.670,3.4,ET LUP +0.778,-0.703,3.4,TH1 ERI +4.653,0.484,3.4,MY HER +5.432,-1.155,3.4,BE PAV +5.434,1.079,3.4,ET CEP +0.214,1.009,3.4,ET CAS +2.404,-1.029,3.4,_ +2.691,0.409,3.4,ZE LEO +5.001,-0.085,3.4,LA AQL +0.299,-0.178,3.5,ET CET +2.693,0.749,3.5,LA UMA +4.931,0.582,3.5,BE LYR +0.713,0.056,3.5,GA CET +1.050,0.218,3.5,LA TAU +1.840,-0.488,3.5,SI CMA +2.080,-0.925,3.5,CH CAR +3.995,0.581,3.5,DE BOO +5.231,0.340,3.5,GA SGE +2.960,0.578,3.5,NY UMA +4.514,0.251,3.5,AL1 HER +5.978,0.429,3.5,MY PEG +5.971,-0.896,3.5,EP GRU +0.454,-0.278,3.5,TA CET +3.935,0.705,3.5,BE BOO +4.830,-0.802,3.5,AL TEL +4.964,-0.368,3.5,XI2 SGR +2.166,0.160,3.5,BE CNC +2.536,0.173,3.5,OK LEO +2.650,0.293,3.5,ET LEO +5.976,1.155,3.5,JO CEP +1.172,0.335,3.5,EP TAU +1.920,0.384,3.5,DE GEM +4.143,-0.060,3.5,MY SER +4.376,0.679,3.5,ET HER +5.804,0.108,3.5,TH PEG +0.974,-0.170,3.5,DE ERI +2.604,-0.952,3.5,PH VEL +3.024,-0.556,3.5,XI HYA +4.615,-0.269,3.5,XI SER +1.514,-0.259,3.5,ZE LEP +3.750,-0.804,3.5,JO LUP +0.085,-0.154,3.6,JO CET +0.596,-0.899,3.6,PH ERI +1.125,-0.590,3.6,YP4 ERI +2.964,-0.258,3.6,DE CRT +4.022,-0.633,3.6,PH1 LUP +5.274,-1.155,3.6,DE PAV +0.428,0.849,3.6,51 AND +2.027,0.426,3.6,KA GEM +4.417,-0.664,3.6,MY2 SCO +4.804,1.269,3.6,CH DRA +5.315,-0.219,3.6,AL2 CAP +1.912,0.289,3.6,LA GEM +3.804,0.530,3.6,RH BOO +4.089,-0.491,3.6,YP LIB +3.235,-1.054,3.6,EP CRU +0.367,-0.143,3.6,TH CET +0.894,0.158,3.6,OK TAU +1.386,-0.119,3.6,TA ORI +1.503,-0.392,3.6,GA LEP +1.801,0.593,3.6,TH GEM +2.372,0.823,3.6,KA UMA +2.490,-0.706,3.6,PS VEL +2.030,-0.663,3.6,_ +2.664,-0.216,3.6,LA HYA +3.101,0.031,3.6,BE VIR +0.399,0.268,3.6,ET PSC +2.270,-0.924,3.6,OK VEL +3.413,-1.249,3.6,DE MUS +4.427,-0.739,3.6,ZE2 SCO +4.586,-1.059,3.6,DE ARA +4.650,-1.130,3.6,ET PAV +6.030,0.739,3.6,OK AND +0.742,0.476,3.6,41 ARI +1.000,0.420,3.6,27 TAU +5.400,0.255,3.6,BE DEL +3.079,-1.165,3.6,LA MUS +1.134,0.273,3.6,GA TAU +3.323,-0.025,3.6,GA VIR +3.684,1.124,3.6,AL DRA +5.475,-1.020,3.6,BE IND \ No newline at end of file diff --git a/apps/planetarium/planetarium.png b/apps/planetarium/planetarium.png new file mode 100644 index 000000000..c40606009 Binary files /dev/null and b/apps/planetarium/planetarium.png differ diff --git a/apps/planetarium/settings.js b/apps/planetarium/settings.js new file mode 100644 index 000000000..21dd36f6b --- /dev/null +++ b/apps/planetarium/settings.js @@ -0,0 +1,25 @@ +// make sure to enclose the function in parentheses +(function(back) { + let settings = require('Storage').readJSON('planetarium.json',1)||{}; + function save(key, value) { + settings[key] = value; + require('Storage').write('planetarium.json',settings); + } + const appMenu = { + '': {'title': 'Planetarium Settings'}, + '< Back': back, + 'Star names': { + value: !!settings.starnames, + format: v =>v?'On':'Off', + onchange: v => { + save('starnames',v); + }}, + 'Constellations': { + value: !!settings.constellations, + format: v =>v?'On':'Off', + onchange: v => { + save('constellations',v); + } + }}; + E.showMenu(appMenu) + }) \ No newline at end of file