My son had been working on a project in Scratch to make the Earth orbit the Sun with the Moon was also orbiting the Earth. He had come up with a solution for the Earth but was shrugging with the moons movement. The below is one method of achieving the goal. There are far more elegant ways of doing this but my goal was an easy to understanding method for my son. 

I am using Scratch 3, enjoy!

The End Goal

This is what we will building

Getting setup

  • Head  over to Scratch 
  • Delete the default “Sprite1” in the bottom right
  • Add a background to the stage. I used one called “Stars”

The Sun

  • Add a sprite to act as the sun.
  • Position it at x 0 y 0 (the centre) and set the size to 75
  • Make sure the Sun sprite is selected and in the centre  code section add the below code

The Earth

  • Add a sprite to act as the Earth and position near the Sun. It doesn’t need to be perfect as we are  going to position it with code
  • Set its size to 45
  • Make sure the Earth sprite is selected and in the centre  code section add the below code

The Moon

  • Add a sprite to act as the moon, I used a ball. 
  • Set its size and position it near the Earth, as before it doesn’t need to be exact as we will be positioning it via code.
  • Before we get into adding the Moons code we are going to make an addition to the Earth’s code. We are going to trigger the Moons movement from the Earth. Why because I found it is the easiest way to keep things in step. We want the Moon’s code to run after the Earth has moved so we base the Moon’s position off the Earth.
  • Back on the Earths code we are going to add a broadcast called “Move Moon” after the Earth has finished moving.
  • Finally we can add the Moon’s Code. Make sure the Moon sprite is selected and add the following code
  • Press the green flag to start the program and you should get our goal