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.
Create a new Scratch project and delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
Open the backdrop library and add the Stars backdrop to your project.
To add a backdrop from the backdrop library follow these steps:
You can use search box or the filter links (Fantasy, Music, Sports etc) to locate your backdrop.
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)
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)
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