Grow A Dragonfly
Grow A Dragonfly
Projects
Grow a dragonfly
Make a dragonfly that grows bigger as it eats
annoying mosquitos and other insects.
Step 1 Introduction
Make a nature app with a dragonfly that grows bigger as it eats insects.
You will:
Use if blocks to make decisions based on conditions made with operators and sensing blocks
Use random numbers to control the movement of a sprite
Use the Sounds editor to edit a sound
We use conditions all the time to make decisions. We could say “if the pencil is blunt, then sharpen it”. If
blocks and conditions let us write code that does something different depending on whether a condition is
true or false.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 1/31
27/05/2022, 12:01 Grow a dragonfly
You will set the scene. Choose your backdrop and add a
dragonfly that follows the mouse-pointer around the Stage.
Working offline
For information about how to set up Scratch for offline use, visit our ‘Getting started with Scratch’
guide (https://projects.raspberrypi.org/en/projects/getting-started-scratch/1).
Dragonflies can be found all over the world and have been around for over 300 million years!
Choose: Click Choose a Backdrop and add a backdrop of your choice. We used the Jurassic backdrop.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 2/31
27/05/2022, 12:01 Grow a dragonfly
Click Choose a Sprite and search for dragonfly, then add the Dragonfly sprite.
Add a script to make the Dragonfly sprite follow the mouse-pointer (or your finger):
when clicked
forever
move 5 steps
Test: Click the green flag and make the Dragonfly sprite move around the Stage. Is the dragonfly
moving as you would expect?
The Dragonfly costume is not facing to the right, so the head of the Dragonfly sprite is not pointing towards the
mouse-pointer.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 3/31
27/05/2022, 12:01 Grow a dragonfly
Click on the Costumes tab and use the Select (arrow) tool to select the costume. Use the Rotate tool at
bottom of the selected costume to turn the Dragonfly costume to face the right.
Test: Click the green flag and look at how the dragonfly moves now.
Dragonfly wings make a fluttering sound as they vibrate. You can edit a sound in Scratch to create your own sound.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 4/31
27/05/2022, 12:01 Grow a dragonfly
Sounds are organised by category, and you can hover over the icon to hear a sound. Choose a
suitable sound.
You should then see that your sprite has your chosen sound.
The Crank sound is too long and too slow for dragonfly wings.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 5/31
27/05/2022, 12:01 Grow a dragonfly
Play the new sound. Click the Faster button a few times until you like the result:
If you like, you can select the very end of the Wings sound, and then click Delete to remove it:
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 6/31
27/05/2022, 12:01 Grow a dragonfly
Now add a block to play the Wings sound when the dragonfly moves:
when clicked
set size to 25 %
forever
move 5 steps
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 7/31
27/05/2022, 12:01 Grow a dragonfly
Characters that move around on their own in games are sometimes called mobs, short for mobiles. Can you
think of a game that has mobs?
Add the Frog 2 sprite to your project. Rename the sprite to Insect:
Click on the Costumes tab. Click on the fly to select it and click on the Copy icon.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 8/31
27/05/2022, 12:01 Grow a dragonfly
Click on the Paste icon to paste the sprite into the new costume. Drag the fly to the centre so it lines up
with the crosshair.
You can rename your costume Insect and delete the other costumes, as you won’t need those:
Increase the size of the fly so that it’s easier to see and catch:
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 9/31
27/05/2022, 12:01 Grow a dragonfly
Click on the Code tab and add a script to make the Insect sprite bounce around:
when clicked
forever
move 3 steps
if on edge, bounce
The if on edge, bounce block checks to see if the sprite has reached the edge of the Stage and
points the sprite in a different direction if it has.
You want the Insect sprite to hide if it gets eaten by the Dragonfly sprite.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 10/31
27/05/2022, 12:01 Grow a dragonfly
when clicked
forever
move 3 steps
if on edge, bounce
if then
The if has a hexagon-shaped input. This means you can put a condition here.
When the if block runs, Scratch will check the condition. If the condition is ‘true’ then the code inside the if
block will run.
You want the insect to hide if it is touching the Dragonfly sprite.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 11/31
27/05/2022, 12:01 Grow a dragonfly
Drag a touching [Dragonfly v] into the if block. Add a hide block inside the if block.
when clicked
forever
move 3 steps
if on edge, bounce
hide eaten
Test: Test your code and control the dragonfly to eat the fly. The fly should disappear.
The dragonfly won’t get very big if it can only eat one fly!
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 12/31
27/05/2022, 12:01 Grow a dragonfly
Add blocks to go to a random position on the Stage, and make your sprite wait for one second
then show:
when clicked
forever
move 3 steps
if on edge, bounce
hide
go to random position
wait 1 seconds
Test: Test that your dragonfly can now eat lots of flies.
Make sure you have added the show block to show at the start.
Tip: You can click the red Stop button above the Stage if you want the dragonfly to be quiet while you add more
code.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 13/31
27/05/2022, 12:01 Grow a dragonfly
You will make the dragonfly grow when it eats a fly, and stop
if it reaches full-size.
The biggest living dragonflies can be found in Central America and have a wingspan of 19cm (a bit bigger
than your hand). The largest insect ever known was Meganeuropsis permiana, a dragonfly with a wingspan
of about 75cm (the size of a big footstep).
The fly knows that it has been eaten, and now the Dragonfly needs to know so that it grows.
When you need to let another sprite know that something has happened, you can use a broadcast block as you
did in Broadcasting spells (https://projects.raspberrypi.org/en/projects/broadcasting-spells).
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 14/31
27/05/2022, 12:01 Grow a dragonfly
Add a broadcast block to the Insect sprite with new message food:
when clicked
forever
move 3 steps
if on edge, bounce
broadcast food
hide
go to random position
wait 1 seconds
show
The Dragonfly sprite needs to grow when it receives the food message.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 15/31
27/05/2022, 12:01 Grow a dragonfly
change size by 5
Add the Chomp sound to the dragonfly and start it when an insect gets eaten:
change size by 5
Test: Run your project to test the dragonfly grows and makes a chomp sound when it eats a fly.
When the dragonfly reaches its full size, the game will congratulate you and stop.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 16/31
27/05/2022, 12:01 Grow a dragonfly
Add an if block.
The dragonfly is full-size when the size = 100%. First, add an = operator into the hexagon-shaped
input:
change size by 5
if = then
Finish building the condition by adding a built-in size variable and type the value 100:
change size by 5
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 17/31
27/05/2022, 12:01 Grow a dragonfly
Add blocks so that if the condition is true then the dragonfly will broadcast an ‘end’ message and
say I got to full size!
Finally, add a stop all block to stop the other dragonfly scripts:
change size by 5
broadcast end
At the moment, the fly still moves after the project has ended. Add this script to the Insect sprite.
Test: Click the green flag and keep eating flies until your dragonfly reaches full-size.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 18/31
27/05/2022, 12:01 Grow a dragonfly
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 19/31
27/05/2022, 12:01 Grow a dragonfly
Select the Dragonfly and find the script that starts with when flag clicked.
Drag an if inside the forever block and the blocks inside the forever will move inside the if.
when clicked
set size to 25 %
forever
if then
move 5 steps
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 20/31
27/05/2022, 12:01 Grow a dragonfly
Then drag a not block into the if and a touching (mouse-pointer) inside that.
when clicked
set size to 25 %
forever
move 5 steps
The not block turns a condition into its opposite, just like it would in a sentence.
Test: Check that the glitch is fixed, and the Dragonfly only moves when it is not touching (mouse-
pointer).
This makes the dragonfly move when it’s far enough from the mouse-pointer.
Tip: You can drag blocks anywhere in the Code area and leave them there while you try different things.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 21/31
27/05/2022, 12:01 Grow a dragonfly
Right-click on the Insect sprite in the Sprite list under the Stage and duplicate it.
The insect gets eaten even if it touches the dragonfly’s wing or tail.
To make your app more realistic, fix this so that the insect gets eaten by the dragonfly’s mouth. You can use the
touching color block so the insect only gets eaten if it is touches a particular colour on the Dragonfly.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 22/31
27/05/2022, 12:01 Grow a dragonfly
You need to check that the Insect2 sprite is touching the Dragonfly sprite and touching the colour of the
dragonfly’s mouth.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 23/31
27/05/2022, 12:01 Grow a dragonfly
The <touching [Dragonfly v] ?> block will pop out, drag it into the left of the and block:
when clicked
show
forever
move 3 steps
if on edge, bounce
broadcast food
hide
go to random position
show
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 24/31
27/05/2022, 12:01 Grow a dragonfly
Drag a touching color block into the right of the and block:
when clicked
show
forever
move 3 steps
if on edge, bounce
broadcast food
hide
go to random position
show
If it doesn’t have the colour of the dragonfly’s mouth selected, click on the colour circle and then click on
the Eyedropper tool to select a colour.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 25/31
27/05/2022, 12:01 Grow a dragonfly
Click on the dragonfly’s mouth on the Stage to set the colour to match:
Tip: If this is tricky to do, change the size of the Dragonfly sprite so it’s really big.
Test: Now test that the dragonfly can only eat the second insect with its mouth.
If you like, you can change the first Insect so that it can only be eaten with the dragonfly’s mouth.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 26/31
27/05/2022, 12:01 Grow a dragonfly
Add a script to Insect 2 to make it point in a random direction every 1–3 seconds.
when clicked
Test: Run your project and watch how the fly moves. Try changing the numbers to get the effect you
want.
You can also drag this script to the Insect sprite so that it also moves randomly.
Change the insects until they behave the way you want them to.
You could change the number of steps they move to make them faster or slower.
You could also change the size that the dragonfly needs to grow to reach full size.
Make changes until you are happy with your project.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 27/31
27/05/2022, 12:01 Grow a dragonfly
Select the Mosquito emoji to insert it into the Paint editor. Use the Select (arrow) tool to centre, resize,
and rotate your mosquito until you are happy with it.
Tip: Emojis can look different on different computers, so they might not look the same on a tablet and a
desktop computer. Some emojis aren’t available on some computers, but most modern computers will
support them.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 28/31
27/05/2022, 12:01 Grow a dragonfly
Use your Backpack to trade insects with your friends from their ‘Grow a Dragonfly’ projects.
To add a sprite to your Backpack, drag the sprite from the Sprite list to the Backpack. This will
store the full sprite in your Backpack, including all of its costumes, sounds, and scripts.
To add a backdrop to your Backpack, select the Stage pane and click on the Backdrops tab, then
choose the backdrop that you want and drag it to your Backpack.
To use an item in your Backpack in another project, open the project and drag the item from the
Backpack to the correct pane or tab.
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 29/31
27/05/2022, 12:01 Grow a dragonfly
To delete an item in your Backpack, find the item in the Backpack tab, then right-click (or on a
tablet, tap and hold) on the item and select delete.
You can hide your Backpack when you are not using it. To do this, click on the Backpack tab at
the bottom of the screen.
Tip: Check that all your sprites and costumes have sensible names. It makes your project easier to
understand if you come back to it later.
Tip: Make sure your code is laid out neatly in the Code area. Right-click on the Code area and choose
Clean up Blocks to get Scratch to tidy up your code.
Completed project
You can view the completed project here (https://scratch.mit.edu/projects/521688740/).
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 30/31
27/05/2022, 12:01 Grow a dragonfly
What next?
If you are following the More scratch (https://projects.raspberrypi.org/en/raspberrypi/more-scratch)
pathway, you can move on to the Drum star (https://projects.raspberrypi.org/en/projects/drum-star) project.
In this project, you will make a clicker game where you earn beats to play new drums at bigger venues.
If you want to have more fun exploring Scratch, then you could try out any of these projects (https://projects.ra
spberrypi.org/en/projects?software%5B%5D=scratch&curriculum%5B%5D=%201).
https://projects.raspberrypi.org/en/projects/grow-a-dragonfly/print 31/31