Astronomy. Sun azimuth. Constellations. Moon phase. JavaScript

  • September 23, 2023 is Astronomy Day (Autumn).
    We are going to see some applications on this topic, they are simply adaptations of JavaScript to App Inventor. You can create other applications about the passionate world of astronomy.

1.- Sun azimuth. Altitude.

p111_posicion_sol.aia (114.7 KB)

On this website we find a code to obtain the position of the Sun, Moon, Mars, Venus,...
Let's adapt it to App Inventor.

The observer is in the center of the circle.
Azimuth is the angle measured from the north (top of circle) in a clockwise direction.
Altitude is the altitude angle.

Look at the modified part of the code:

let azims_altis = "";

for (let body of BodyList) {
    let equ_2000 = Astronomy.Equator(body, date, observer, false, true);
    let equ_ofdate = Astronomy.Equator(body, date, observer, true, true);
    let hor = Astronomy.Horizon(date, observer, equ_ofdate.ra, equ_ofdate.dec, 'normal');
    document.getElementById(`${body}_ra`).innerText = FormatCoord(equ_2000.ra);
    document.getElementById(`${body}_dec`).innerText = FormatCoord(equ_2000.dec);
    document.getElementById(`${body}_az`).innerText = FormatCoord(hor.azimuth);
    document.getElementById(`${body}_alt`).innerText = FormatCoord(hor.altitude);
    azims_altis = azims_altis + FormatCoord(hor.azimuth) + "," + FormatCoord(hor.altitude) + ",";
//alert (azims_altis);
window.AppInventor.setWebViewString("" + azims_altis);

- Proposal:
create another Ball that shows the position of the moon.


2.- Constellations.

p111_constelaciones.aia (70.7 KB)

There are 88 constellations (Orion, Andromeda, Ursa minor, Aquarius, Sagittarius,...).

On this website we can see a JavaScript code that draws constellations:

Let's adapt it to App Inventor.

- Proposal: create an app where when you press the button a random constellation is drawn and its name is not shown. The user must guess the name of that constellation.


3.- Orion. The hunter.

  • One of the best-known constellations is Orion, the hunter. Observe its belt formed by the stars Alnitak, Alnilam and Mintaka.

  • In the northern hemisphere we can see this constellation throughout the winter.

- Proposal: calculate the kilometer distance away from each of the marked stars.


4.- Moon phases.

p111_fase_luna.aia (111.1 KB)

In this topic we can see a code to calculate the phases of the moon.

We can also use this code in JavaScript.

Let's adapt it to App Inventor.


5.- Kepler's Laws. Elliptical orbits.

Johannes Kepler formulated three fundamental laws of planetary motion in the early 17th century, known as Kepler's Laws of Planetary Motion.

Kepler's Laws
  1. Kepler's First Law (Law of Ellipses): This law states that the orbit of a planet around the Sun is an ellipse, with the Sun at one of the two foci of the ellipse. In simpler terms, the planets do not move in perfect circles but in slightly elongated, oval-shaped orbits.
  2. Kepler's Second Law (Law of Equal Areas): This law states that a line segment joining a planet and the Sun sweeps out equal areas in equal intervals of time. This means that a planet moves faster in its orbit when it is closer to the Sun (perihelion) and slower when it is farther away (aphelion).
  3. Kepler's Third Law (Law of Harmonies): This law relates the orbital periods and semi-major axes of planets. It states that the square of the orbital period of a planet is directly proportional to the cube of the semi-major axis of its orbit. In mathematical terms, it can be expressed as: T^2 ∝ r^3, where T is the orbital period and r is the semi-major axis.
  • The earth moves around the sun describing an ellipse, but an ellipse of little eccentricity that looks like a circle.
  • Observe the orbits of the planets, they look like circles.


  • This is because ellipses have little eccentricity.
    Mercury e = 0.2056
    Venus e = 0.00678
    Earth e = 0.017
    Mars e = 0.0934
    Jupiter e = 0.049
    Saturn e = 0.056
    Uranus e = 0.046
    Neptuno e = 0.0107
    Pluto e = 0.244
    Halley e = 0.967

  • Observe the elliptical orbit and eccentricity of the Earth and Comet Halley

Let's adapt it to App Inventor.
We will use the Slider component.

  • We must modify the orbita.htm and mathcells.js files

Note, for a better visualization it is convenient that the blue axis be seen from above.

p111_orbita.aia (78.3 KB)


6.- Doppler effect. Redshift. Blueshift.

How do scientists know the displacement of a star?

  • Remember the Doppler effect, when the ambulance approaches the observer perceives an increase in the frequency of the sound, this is a "high-pitched sound".
    As the ambulance moves away he perceives a decrease in frequency, this a "low-pitched sound".

- Proposal,
create a simple application where the user "flung" the ball.
When the ball moves up, the "visible frequencies" image will shift to the left (redshift).
When the ball moves down, the "visible frequencies" image will shift to the right (blueshift).
It uses the Canvas and Ball components, and the Flung event.

1 Like

7.- Calculation of age and weight on other planets.

  • Create an app, using blocks, that calculates your age and weight on other planets.