Coding Stories: Sensational Science with Scratch

Greg Benedis-Grab
Feb 24, 2020 · 5 min read

While preparing for Sensational Science with Scratch, a workshop at STEM Teachers NYC, I got into a conversation with @JulietteScience (co-presenter) about other ways to include coding in the science classroom. I found out she is running a Trout in the classroom project at her school with 4th graders. Trout in the classroom involves setting up a large tank where you raise trout eggs to be released into the wild. It is a trout repopulation strategy. I was immediately interested because setting up a tank of fish is essentially creating a model of a natural river system. You need to have the correct temperature, food supply, pH level, etc. so that the system is balanced and the conditions are conducive to fish survival. You are essentially building a simulation with live fish; and I love simulations. In fact if you think about it, the natural river system is a simulation as well where a set of scientific laws determine how the state of the system updates over time. You might even argue that all of biology can be thought of as a simulation. As I described in a previous post evolution certainly works this way. In his book, The Blind Watchmaker, Richard Dawkins writes, “It is raining instructions out there; it’s raining programs; it’s raining tree-growing, fluff-spreading, algorithms. That is not a metaphor, it is the plain truth. It couldn’t be any more plain if it were raining floppy discs. (Dawkins, p111)” Antiquated media storage terminology aside, that is what I believe makes computational modeling such a powerful way to think deeply about scientific ideas. By creating a computer model of a natural system and seeing how it develops you gain insights about how the system works, what factors are important and what trends emerge. The model does not have to be precisely accurate to expand your thinking. In fact it’s limitations are just as thought provoking as its accuracies. So I was determined to create a computing system that modeled the trout tank being described.

Since the class is 4th grade I thought Scratch would be the most accessible coding tool to use. To begin my simulation I would need a population of fish. The clone feature in Scratch allows me to make an arbitrary number of fish in my simulation. I decided to start with 50 fish

It looked like this

Next I decided it would be nice if they moved around the screen. This is how I coded it.

I could also have them change direction but since I would love to show the code to the 3rd graders eventually I prioritized keeping the program as simple as possible. To be honest they don’t actually need to move around to simulate population size but it makes it so much more fun so I left that part in.

Next I wanted the fish to get bigger over time and then at some point start reproducing. This is how I wrote that.

The reproduction age corresponds with a size of 20 and the chance of reproducing is 14% per turn. Those were arbitrary choices that can be modified. I could also add complexity to this model giving fish a sex and other traits. But again I am trying to keep this as simple as possible. If I run the model now the population explodes out of control so I need a limiting factor. Instead of including food or other realistic limits I just wrote a death script.

Every second I pick a random number for each fish in the population from 1 to 500. If that number is smaller than the total population then that fish is killed. This function has the nice property that as the population increases the chance of death increases as well which is somewhat analogous to how a food limiting condition would work. Importantly this stabilizes the population to somewhere in the neighborhood of 100 fish on the screen. You might have also noticed that I change the color of the fish right before it dies or reproduces to make that more obvious. Here is the final simulation.

What I love about this simulation is that through a very simple set of rules I have created a fairly stable fish population. You can see fish both dying and reproducing resulting in an equilibrium population. But there are also fluctuations in the population. While the exact parameters that determine survival might not be true to the trout experience, the fluctuation is probably accurate and is not something that would be obvious without running the model.

Run the model yourself on the scratch website https://scratch.mit.edu/projects/369827489/editor/

To simulate a pH change I just made the chance of death higher outside of a perscribed range, in this case between 6 and 8. I am sure this is not how nature works. But I like how the fish population drops slowly when the pH is out of range and it takes time to notice the change in the equilibrium state. Creating a computational model provides opportunities to evaluate the model, its affordances and its limitations. By engaging in this work with computers we can deepen our thinking about the world around us. Also we can make visually engaging simulations that are fun and motivating to children. Go ahead and remix my model or model something completely different.

The Startup

Get smarter at building your thing. Join The Startup’s +792K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Greg Benedis-Grab

Written by

exploring the intersection of coding, education and disciplinary knowledge

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +792K followers.

Greg Benedis-Grab

Written by

exploring the intersection of coding, education and disciplinary knowledge

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +792K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store