Algorithms with myBlocks
You have actually been creating algorithms since you first started coding. Only, you may have not been naming these algorithms, which means that you cannot re-use them. You can encapsulate an algorithm by using abstraction to create your own custom-built "block" in Scratch.
For this example, let's create algorithms for drawing different shapes. Once we name these algorithms with their own block, we can re-use them as often as we'd like.
Decomposition
- Create a sprite that will "draw" a shape at a random point on the screen
- Create an algorithm for the following shapes:
- square
- triangle
- circle
- When you click the flag, "call" (i.e., use) your new blocks several times.