In lesson 3, we made individual scripts for drawing individual shapes. What if we could make just one that can draw any shape?
Using operators we can! Let’s do it:
- Import the Pen sprite and set the backdrop.
- Adjust the center of the pen to tip.
- Next, make a variable named Sides and set its input as 5.
- Then, add a repeat block and drag and drop the Sides variable block inside the space of the repeat block. Placing the Sides variable block in the space 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. We’ll write this formula using the () / () (division operator) block and the Sides variable block. Click on Operators palette and drag and drop a () / () block inside the space of the move () steps block. According to the formula, you must divide 400 by the number of sides of the shape. Therefore, in the left space of the () / () block write 400, and in the right space, drag and drop the Sides block.
- Next, drag and drop the turn clockwise () degrees block from the Motion palette and repeat step 6.
- Now, go to the Control palette and add a wait () secs block below the move () steps block; set the time as 0.1 seconds.
- Complete the script by adding a when (d) key clicked block.
Below is the complete script:
Before you move on to the next lesson, a small assignment awaits you!
You must upload the PictoBlox program you wrote in the Activity to the website. Submitting the assignment is a must in order to receive the certificate after completing the course.
Submitting the assignment is a must in order to receive the certificate after completing the course.
Follow the steps below to upload your assignment:
- Click on Choose File.
- Select the image from the pop-up window that opens up.
- Once the image is selected, click on Upload Assignment.
File types allowed is SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.