Introduction: Make Earth Revolve Around the Sun in Scratch
Watch the full tutorial here – How to Make Earth Revolve Around the Sun in Scratch | Make Animation in Scratch | Kodex Academy
Animating Earth revolving around the Sun is a classic beginner/intermediate Scratch animation project. It combines trigonometry (sine & cosine), variables, loops, and visual scripting. Kids can learn how to use sin
and cos
blocks to compute X/Y positions based on an angle and radius, how to use pen tools to trace orbits, and how to add rotation, sound, and other effects.
This blog covers:
- Step‑by‑step coding guide from the video
- All possible scenarios and variants
- Enhancement features with code
- Best practices (SEO, usability)
- External resources for further learning
- Full example code (Scratch blocks style)
Core Concepts – Learn Before You Code!
Understanding the core concepts is key to successfully animating Earth’s revolution around the Sun in Scratch. This section explains what’s happening behind the scenes — so you’re not just copying code, but actually understanding how it works.
1. Sprites & Backdrop
Sprites are characters or objects in Scratch. For this project, you need:
- Sun Sprite: Fixed in the center
- Earth Sprite: Revolves around the Sun
Backdrop: Choose a space-themed background (like “Stars”) to simulate the solar system.
Tip: Resize Earth to ~50% for better visuals.
2. Trigonometric Functions: Sin and Cos
This is the magic behind the animation!
What Are sin()
and cos()
in Scratch?
Scratch includes math functions like sin
, cos
, tan
, etc. These come from trigonometry, and help in calculating circular motion.
How Do They Work?
To simulate circular movement, you update an object’s X and Y positions like this:
- X = Center X + radius × sin(angle)
- Y = Center Y + radius × cos(angle)
Why Use Them?
Because they allow you to rotate a sprite smoothly around a center point — just like the Earth orbits the Sun!
Did you know? In Scratch, angles are in degrees, not radians. So sin(90)
= 1, cos(0)
= 1, etc.
3. Variables – Earth’s Motion Parameters
You’ll use variables to control the motion:
Variable | Type | Purpose |
---|---|---|
angle | Sprite-only | Tracks Earth’s current position in orbit |
radius | Sprite-only | How far Earth is from the Sun |
speed | Sprite-only | How fast Earth moves (degrees per frame) |
sun x | Global | X position of the Sun |
sun y | Global | Y position of the Sun |
Read more about variables in Scratch: https://en.scratch-wiki.info/wiki/Variable
4. Loops & Animation Timing
To keep Earth moving smoothly, you’ll use the forever
loop:
forever
// update Earth's position using sin/cos
end
You can also add wait (0.05)
seconds to control the animation speed.
5. Pen Tool – Drawing the Orbit
The Pen extension in Scratch allows sprites to draw lines as they move.
- Use
pen down
to start drawing. - Use
erase all
at the beginning to clean old drawings. - Draw the orbit path to visualize Earth’s trajectory!
Learn more: Scratch Wiki – Pen Extension
6. Sound & Rotation
Add sound to make your project more fun and immersive!
- Use looping sounds like “Xylo 3”
- Use
turn clockwise
block to make the Earth rotate on its own axis
This helps simulate both rotation (Earth spinning) and revolution (orbiting the Sun).
7. Rotation Styles
Each sprite has a rotation style:
- Don’t Rotate → Use for Sun (static)
- All Around → Use for Earth (to spin it)
Set it in code:
set rotation style [all around v]
Make sure Earth rotates properly as it orbits!
8. Operators & Math Blocks
You’ll use operator blocks like:
+
(Addition)*
(Multiplication)sin
,cos
(Trigonometry functions)
These go inside the Motion > Go to x/y block to calculate real-time position changes.
go to x: (sun x + radius × sin(angle))
y: (sun y + radius × cos(angle))
Learn more: Scratch Wiki – Operators
Summary of Core Concepts
Concept | Description |
---|---|
Sprites & Backdrop | Sun (fixed), Earth (rotating), starry space background |
sin() & cos() | For circular motion calculations |
Variables | Control orbit parameters like angle, radius, speed |
Loops | To animate movement over time |
Pen Tool | To draw the orbit path |
Rotation Style | Controls how sprites rotate visually |
Operators | Needed for position calculations |
How to Make Earth Revolve Around the Sun in Scratch: Step‑By‑Step Coding
Here’s how to recreate the project from the transcript with code sketches in Scratch blocks.
Setup
- Delete the default cat sprite.
- Choose a backdrop (e.g. Stars).
- Add two sprites: Sun and Earth.
- Resize Earth to about 50% or whatever size you like.
Sun Sprite Code
when green flag clicked
go to x: (0) y: (0)
set rotation style [don't rotate v]
This ensures the Sun stays fixed in the centre.
Earth Sprite: Variables
Create for Earth sprite only:
angle
radius
speed
Create for all sprites (or could be global variables):
sun x
sun y
Earth Sprite: Initialization
when green flag clicked
hide variable [angle v]
hide variable [radius v]
hide variable [speed v]
set [sun x v] to (0)
set [sun y v] to (0)
set [radius v] to (150)
set [speed v] to (1) // degrees per tick
set [angle v] to (0)
set rotation style [all around v]
Also set Earth’s initial position if desired:
go to x: (something) y: (something) // e.g. 88, 124 — optional starting offset
Earth Sprite: Orbit Movement
forever
// compute new position
set x to ((sun x) + (radius * (sin (angle))))
set y to ((sun y) + (radius * (cos (angle))))
change [angle v] by (speed)
// option: rotate Earth sprite on its own axis
turn cw (10) degrees // or some value
wait (0.05) secs // to control speed visually
end
Drawing the Orbit with Pen
when green flag clicked
erase all
pen down
set pen color to [white v] // or any color
forever
// the same position update code as above
go to x: ((sun x) + (radius * (sin (angle))))
y: ((sun y) + (radius * (cos (angle))))
change [angle v] by (speed)
wait (0.05) secs
end
Adding Sound
when green flag clicked
forever
play sound [Xylo 3 v] until done
end
Scenarios & Variants
These are additional scenarios you might want to try:
Scenario | What Changes | Learning Outcome |
---|---|---|
Earth rotates around Sun (circle) | Standard use of sin and cos with fixed radius | Understand circular motion |
Elliptical orbit | Use different radii for x vs y component (e.g. radius_x and radius_y ) | Understand ellipse shapes |
Multiple planets | Add more sprites (Mercury, Venus, Mars…) with different radius, speed, size | Understanding relative motion, scale, concurrency |
Moons around planets | A moon sprite orbiting Earth which itself orbits Sun | Hierarchical motion, nested orbits |
Show graphs of sin and cos | Use pen blocks to draw functions over angle vs output | Connect animation with math graphs |
Phase shift / oscillations | Start angle at different initial values, or use cos/sin swapped | Learn about phase shift in waves |
Interactive control | Let user adjust speed and radius via slider or input | Interactivity, debugging, user input |
Enhancement Features & Code Snippets
To make the project more engaging, you can add enhancements. Here are some with sample Scratch block‑style code.
- Variable UI Controls
Let the user changespeed
orradius
during runtime.
when [up arrow v] key pressed
change [radius v] by (10)
when [down arrow v] key pressed
change [radius v] by (-10)
when [right arrow v] key pressed
change [speed v] by (1)
when [left arrow v] key pressed
change [speed v] by (-1)
2. Multiple Planets with Different Speeds & Colors
For each planet sprite:
when green flag clicked
set [radius v] to (planet‑specific value)
set [speed v] to (planet‑specific speed)
set pen color to [color v] // different color
// then orbit code as above
3. Elliptical Orbit
Use two radii: radius_x
and radius_y
:
set [radius_x v] to (150)
set [radius_y v] to (80)
forever
set x to (sun x + (radius_x * sin(angle)))
set y to (sun y + (radius_y * cos(angle)))
change [angle v] by (speed)
wait (0.05)
end
4. Background Stars Moving / Parallax Effect
To simulate depth: have multiple star sprites or backgrounds move slowly (or tween) as Earth orbits:
when green flag clicked
forever
change y by (small amount) // or change x
wait (0.1)
end
Or switch costumes periodically for twinkling stars.
5. Day/Night Effect on Earth
Use two Earth costumes: one lit half, one dark half. Rotate or change brightness.
forever
next costume
wait (0.5)
end
6. Sound Variation
Instead of looping one sound, vary pitch or choose different sounds per planet orbit:
when green flag clicked
forever
play sound [Xylo 3 v] until done
wait (1 second)
play sound [Bell v] until done
wait (1 second)
end
7. Reset / Pause Controls
when [space v] key pressed
stop [all v] // pause or stop motion
Or custom pause logic by using a variable like paused?
and checking inside forever
loops.
Putting It All Together
- Watch the video to see the final effect & follow along. (YouTube Link)
- Set up your Scratch project: backdrop, sprites.
- Create variables.
- Write initialization code (Sun at center, Earth radius etc.).
- Write orbit & rotation code (using
sin
,cos
, loops). - Add pen drawing, sound, and interactive controls for enhancements.
- Test, adjust speed/radius to your taste.
- Share it with friends or on Scratch.
Possible Troubleshooting
- Earth moves too fast / too slow → adjust
speed
or add await
block. - Orbit looks like line or ellipse unintentionally → ensure you use both
sin(angle)
andcos(angle)
properly; if only one is varied, motion will collapse into a line. - Pen tool draws weird shapes → ensure
erase all
is used at start, pen down before loop, and pen color/size set. - Rotation style: If Earth’s sprite rotates weirdly (spins), you need to set rotation style “all around” for Earth; for Sun, set “don’t rotate” if you want it fixed.
- Variable visibility: Hide variables once you’re comfortable with the project, unless they are needed to be shown.
Conclusion: Learn, Code, and Orbit!
Congratulations! 🎉 You’ve just learned how to make Earth revolve around the Sun in Scratch using sine and cosine — core trigonometric concepts simplified for a fun and visual learning experience.
This Scratch animation project not only helps you create realistic space animations, but also introduces you to powerful programming fundamentals such as:
- Using variables to control motion
- Applying trigonometry for circular movement
- Implementing loops, pen extensions, and rotation styles
- Creating interactive animations and games using Scratch
Whether you’re a Scratch beginner, a teacher looking for coding projects for kids, or just curious about how to make games in Scratch, this tutorial is a perfect starting point for combining STEM education with creativity.
Call to Action
- Don’t forget to check out the full video tutorial: How to Make Earth Revolve Around the Sun in Scratch | Make Animation in Scratch | Kodex Academy
- Like, comment & share the video
- Visit kodexacademy.com
- subscribe to the Kodex Academy YouTube channel for deeper Scratch content.
Happy coding with Kodex Academy! 🚀
Learn More with Kodex Academy
At Kodex Academy, we’re passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.
Explore more:
Stay updated with new content, free tutorials, and coding challenges!
- 🌐 Website: https://kodexacademy.com
- 🌐 Website: https://games.kodexacademy.com
- 💬 WhatsApp Channel: Join Now
- 💼 LinkedIn: Kodex Academy
- 📸 Instagram: @kodex_academy
- 𝕏 Twitter: @Kodex_Academy
- 📢 Telegram: Join Our Channel
- 🔗 Patreon: patreon.com/KodexAcademy
Further Reading & Links
- Scratch Wiki Motion Blocks: https://en.scratch-wiki.info/wiki/Motion_Blocks
- Scratch Programming for Beginners: https://scratch.mit.edu/projects/editor
- Scratch Animation Guide: https://en.scratch-wiki.info/wiki/Animating