Chapter 7. Gorgeous Firework

0 3201 Easy

Fireworks are so mesmerizing! The moment fireworks explode in the night sky, the whole sky comes alive with so many vibrant hues, starbursts, and showers of light along with ribbons of smoke, making us happy and awestruck. In this chapter, we are going to display an effect of firework exploding on the stage of mind+.

Gorgeous Fireworks always comes together with a backdrop of night sky. We will use light sensing function of micro:bit to simulate the firework exploding in the night sky.

We also will get to know how to use the light sensor on micro:bit.

7.1 Clone


In some projects, you want several identical characters, they must have exactly same motion scripts and shapes. The only difference is their positions. How to do that? Well, the first idea coming to us is to duplicate. Yes, we could first design the motion scripts and shapes of one sprite and then duplicate it as much as we need. But if we want to revise some functions of these sprites, we have to do it one by one or delete all the duplicated sprites, revise the original one and duplicate it again. So complicated, right? But now with the function of clone, this will be just as easy as a pie!

What’s the difference between clone and duplicate? We can explain it in this way: duplicating is a step that happens in the period of editing and there will be more sprites appearing on the editing area of sprite and background when you start duplicating, but cloning is a feature that allows to create a clone,

or semi-duplicate, of itself while the project is running and there will be only one sprite remaining on that editing area. The “when I start as a clone” block will perform in the clone once it is created. The blocks relating to clone can be found in “Control” module. As figure 7-1 shows.


projectImage

Next, in the case of Starry Night Sky, we will learn how to use clone in the actual application.


Case 1: Starry Night Sky


We set the blue sky and star as the background and sprite respectively. Look at the scripts below, we can find that the star is cloned four times. When it starts as a clone, its size gets smaller, and it will move to the position (55, 44). Shown as figure 7-2. The four clones of the star will stay at the same place, drag and move it, the lovely stars will appear.

projectImage

How to scatter the stars over the blue sky? Yes, a random function totally works here.

projectImage

At last, we need to make these stars seem to twinkle. Where to place the scripts of this part?

Of course, it should be put under the block “when I start as a clone”. Since the parent of clone. do not have the function of shining, we have to use the “delete this clone” or “hide” block to realize that effect.

projectImage

Case 2: Draw flowers


The effect of the program will be like this: click the mouse, then the colorful flowers appears on the stage, as figure 7-5 shows. Well, now, consider if the clone function is needed here. If so, what is the parent of the clone? Take a look at the pictures below, some flowers have one layer of petal while the others have two, so obviously that is randomly chosen. To achieve an effect like that, we have to use the loop function.

projectImage
projectImage

Revise the parameters in the blocks below, and check the result.

projectImage

7.2 Algorithms Analysis


- Create a sprite “red dot” as the initial shape (shape 1) of the firework. Upload the pictures of firework exploding as the other shapes of the sprite;

- Click green flag, determine if the ambient light is less than 1, if so, the sprite clones itself for 20 times;

- When starting as a clone, the shape 1 slides to a random position from the lower part of the stage, play the sound effect of firework exploding;

- Meanwhile, set size of the sprite to 20%, switch the shape to the rest shapes, repeatedly run the program to enlarge the sprite, add color and ghost effect for the sprite. After one firework exploded, delete the clone to realize an effect of randomly exploding.

7.3 Programming


Costumes design: paint a red dot (shape 1) as the initial state of the firework, then upload several fireworks pictures as the rest shapes. As figure 7-9 shows.

projectImage

Sound Design: search for the sound of fireworks exploding on the internet, upload it into Mind+. You can trim the sound to make it shorter.

projectImage

The details of the program are shown below.

projectImage
projectImage

7.4 Programming Result


Connect the micro:bit to your computer with micro USB, and select the corresponding COM port. Click the green flag to start the program, cover the LED panel of the micro:bit to simulate the night. Check the result.

projectImage
projectImage

7.5 Light Sensor


The LED panel on the micro:bit can be used as light sensor to detect the light level around it.

projectImage

7.6 Training Camp


This program is basically to use the light sensor to control the light level within a certain range, then make the fireworks explode when the ambient light is as dark as night. How about using “light sensor” to control the lights in the corridor? If you dare to dream, you can make it. Go ahead!

License
All Rights
Reserved
licensBg
0