Create a virtual sparkler in this quick Scratch project! Just like a real sparkler – students should be able to wave the sparkler around with their mouse to draw out their name or make patterns.
Task
Read through this page and in Scratch, create the program that is asked for. Pay close attention to what is being asked and the success criteria.
We recommend planning the program before you start it.
Create a Scratch Project that does the following:
- Create a sparkler effect in Scratch
- The sparkle effect should follow your mouse as you move it
- A trail should follow the sparkle effect but only for a small amount of time.
Instructions
1. Open Scratch or go to the Scratch website www.scratch.mit.edu
2. Download and save the Sparkler video file below (make sure you save it to a place you know!):
3. We now need to put the video we have downloaded into Scratch
5. Select the file and click on the Open button
This will put the video into Scratch for you.
If you go to the Sprite window you should be able to see the video.
6. If the cat sprite is still here you can get rid of it as we don’t need it for this project.
Click on the cat then click on the rubbish bin.
Sorry cat!
7. We will now code our program. Click on the sprite that we imported and select the starting block from the ‘Events’ menu on the left.
Double click or drag this block into the coding window to the right.
This block tells the sprite what to do when you click on the green flag.
8. Under the ‘Looks’ menu on the left, find the block that says ‘switch costume to’ and place it under the starting block.
Your code should look like the image on the left.
This block of code will help our video to run / animate.
9. Under the ‘Variables’ menu on the left, find the block that says ‘set my variable to 0’.
Drag it into the code area and change the 0 to 24.
This is the number of frames per second the video has.
Can you change the variable name to ‘frames’ instead of ‘my variable’?
10. Under the ‘Control’ menu on the left, find the block that says ‘forever’.
Drag it into the code area and attach it under the variable block.
This block will make the code in it run forever until we stop the program.
11. We now need to add something extra to Scratch to make the sparkler draw lines as we move our mouse.
Click on the blue button in the bottom right hand corner of the screen underneath all of the other menu options.
12. A window will pop up with lots of different extensions. You need to select the ‘Pen’ extension.
Without this, our sparkler won’t be able to draw lines.
Did you know – Python uses similar extensions called libraries that allows it to do extra tasks as well!
Click on the image and an extra menu option will be added to the left hand menu bar called ‘Pen’
You will be given lots of different Pen menu options.
13. From the ‘Pen’ menu option on the left we need to select 3 different blocks:
- set pen size to
- pen down
- set pen color to
All 3 of these need to go into our forever loop.
Make sure you change the set pen size value to 10.
Change the ‘set pen color to’ value to a nice orange colour.
These 3 blocks setup our sprite so that it can draw onto the screen.
14. Under the ‘Motion’ menu option on the left select the block labelled ‘go to random position’.
Drag the block into the forever loop.
Click on the ‘random position’ value and select the ‘mouse-pointer’ value.
This will make our sprite go to where the mouse pointer is so that we can use the mouse to draw.
15. Under the ‘Looks’ menu option on the left select the block labelled ‘next costume’.
Drag the block into the forever loop.
This block will make sure that the animation on our sparkler runs.
16. The next block we add is actually comprised of 3 blocks – pay attention to get this correct.
Under the ‘Control’ menu option select the ‘wait 1 seconds’ block.
Drag it into the forever loop.
Next under the ‘Operators’ menu option select the block with the ‘/’ symbol in the middle of it and two blank spaces either side.
Drag this block and put it into the ‘wait 1 seconds’ block where the ‘1’ is.
Next under the ‘Variables’ menu option select the ‘my variable’ (or ‘frames’ variable if you renamed it).
Drag this into the empty space on the right side of the ‘/’ block like the picture.
Finally put a ‘1’ into the left hand blank space of the ‘/’ block.
This block makes sure that our animation runs at the correct speed.
17. The last part of code we need!
Under the ‘Pen’ menu option select the block that says ‘erase all’.
Drag this into the forever loop.
This block will erase our drawing as, like a real sparkler the drawing should not last for long.
Press the Green flag to try out your virtual sparkler!
Is everything working correctly? Great! If not have another read through and make sure you have followed the instructions.
Challenge
- Make the sparkler draw colour changing patterns.