Coding Ireland STEM Report 2024 Have Your Say
Mathematics Scratch
Expert
60 mins
220 points
What you need:
  • Computer/laptop

Earth and Moon Orbits

In this project we will program the earth to orbit around the sun and the moon to orbit around the earth. We will also trace their paths to visualise their orbits.

1 - Create a new Scratch project

Create a new Scratch project and delete the cat sprite.

2 - Add the Stars backdrop

Open the backdrop library and add the Stars backdrop to your project.


3 - Add the Sun

Add the Ball sprite from the sprite library to your project. This is going to represent the sun.

Rename the sprite to be called 'Sun' and then add the following code to it so that it appears in the center of the stage area.

when green flag clicked go to x (0) y (0)



4 - Add the Earth

Again we're going to add another Ball sprite to our project, but this time we will choose the 'ball-b' costume to make it blue like the earth.

Add the Ball sprite from the sprite library to your project, rename it to be called 'Earth' and then add the following code to it so that it appears smaller than the sun.

when green flag clicked switch costume to (ball-b v) set size to (30) % go to x (0) y (160)



5 - Program the earth's orbit

Next we are going to use a maths formula to continually change the x and y coordinates of the Earth sprite to make it rotate and orbit around the Sun sprite.

The equation use Sine and Cosine (often shortened to sin and cos) which are each a ratio of sides of a right angled triangle.

To calculate the x position we use the equation: sin of the current position multiplied by 160 (160 is the radius of the circle/orbit).

To calculate the y position we use the equation: cos of the current position multiplied by 160 (160 is the radius of the circle/orbit).

Create a variable called start and then add the following code to the Earth sprite, underneath the go to x: 0 y: 160 block.

when green flag clicked switch costume to (ball-b v) set size to (30) % go to x (0) y (160) // add the new code under here set [start v] to (0) forever change [start v] by (1) // how fast it will move go to x (([sin v] of (start)) * (160)) y (([cos v] of (start)) * (160)) end



Join our club 😃

To view the remaining 5 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more