CHAPTER 7
Writing Functions and Scattering Stuff
Pufferfish Puff is an action-packed toy where silly pufferfish bounce around an ocean scene. You’ll make it interactive by adding a user input that triggers each pufferfish to puff up — as if just startled! Using randomness, you’ll scatter the puffers in all directions and make them zoom and ricochet off the edges. It’s an underwater explosion of motion!
You’ll start with a sea-themed backdrop and one pufferfish sprite. Then, using a new concept called cloning, you’ll create a whole school of puffers that inherit all the code and attributes of the original pufferfish. Now that your code is getting longer and more complex, you’ll also build custom code packages called functions to organize your program like real coders do.
This project brings together lots of skills: randomness, motion, loops, cloning, and functions. It’s your biggest coding challenge yet (and maybe your puffiest). Let’s go!

Brainstorm
You can swap the pufferfish for any character or sea creature. Scratch has several sea critters, including a crab, jellyfish, an octopus, and even a shark! Or you can create something altogether different to clone and move around your toy — bouncy balls, fireflies, cats — it’s your choice. Get creative and start coding!
Start a New Project
Begin creating your Pufferfish Puff program by starting a new project. Name your project ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access