Initiation au code – Les bloques opérateurs
THE SITE OPERATOR
On a construction site near your home, a tall, beautiful building is being constructed. You go by the site every morning, looking at the huge crane that stands there for moving objects. How does it operate? A skilled human, just like you, sits inside a cabin attached to the giant machine and operates the crane. The power of the crane, combined with the skill of the operator creates magic at the construction site.
Just like the crane operator operates the crane and performs the function of lifting objects using the crane (makes them interact), in computer programming, operators are characters that perform functions on data; it is either one variable or constant, or more that one. In PictoBlox, there are different types of operators in the Operators palette such as:
- arithmetic operators (+, -, *, /)
- logical operators (and, or, not)
- relational operators (<, >, =)
ACTIVITY: WRITING THE SCRIPT FOR THE SHAPE OF YOU(R) CHOICE
Now, that we know what gives a program some flavor, let’s spice up the program, or, in Scratch lingo, the script for drawing shapes. Ready. Set. Code!
Like in the previous script, here as well, you must use the following blocks:
- Create a variable using the Variables palette; name it Sides.
- After you create the variable, you’ll see five blocks in the block palette; one of them will be Set () to (). Drag and drop this block below the when () key pressed and repeat block. Select Sides from the drop-down menu and in the second space write the number of sides of the shape you want to draw.
- Drag and drop the Sides variable block inside the space of the repeat block. Placing the Sides variable block in the bubble indicates that the repeat block will make the script inside it repeat as many times as the value of Sides.
- Now, we need to decide the value of the angle. In chapter one, you learned the formula for calculating the value of the angle (exterior angle to be precise). We’ll write this formula using the () / () (division operator) block and the Sides variable block. Click on Operators palette and drag and drop the () / () block inside the space of the move () steps block. According to the formula, you must divide 360° by the number of side of the shape. Therefore, in the left bubble of the () / () block write, and in the right bubble, drag and drop the Sides block.
- Now, go to the Control palette and drag and drop the wait () secs block below the move () steps block; write 0.1 in the space.
- Drag and drop the turn ‘clockwise’ () degrees block from the Motion palette and repeat step 5.
- To make the erase all block independent, and to not click on it every time, you can use another when () key pressed block. For that, you can select a different keyboard key, say c. this will make its use both independent and hassle-free.
Et voila! Your script is ready! Go ahead and fill the stage with all possible shapes! Don’t forget to it.
Below is the complete script with its result: