📋
To draw shapes in Scratch, we first need to unlock a "hidden" set of tools called the Pen Extension. This turns your sprite into a virtual pen that leaves a trail wherever it moves.
1. Add the Pen Extension
Since the Pen blocks aren't in the default sidebar:
Click the "Add Extension" button (the blue icon at the very bottom-left corner of the screen).
Select "Pen." 3. You will now see a new green category of blocks!
2. Create the "Draw Square" Block
Now, let's use what we learned about My Blocks to create a custom command.
Go to the pink My Blocks category and click "Make a Block."
Name it
Draw Square.Click "Add an input (number or text)" and name it
size. This allows you to draw squares of any size!Click OK.
3. Define the Logic
A square has four equal sides and four $90^\circ$ turns. Here is how you define that logic under your new pink Define hat:
pen down(Put the pen on the paper)repeat (4)move (size) steps(Use thesizeinput bubble here)turn clockwise (90) degrees
pen up(Lift the pen so it stops drawing)
4. Using the Block in a Script
Now that you've "taught" Scratch how to draw a square, you can use that command anywhere.
Try this script:
When 🚩 clickederase all(Clear the screen from previous attempts)go to x: (0) y: (0)(Start in the middle)Draw Square (50)(Draw a small square)go to x: (100) y: (100)Draw Square (100)(Draw a larger square)
Pro Tip: The "Rainbow" Square
If you want to make it look cool, add a change pen color by (10) block inside the repeat loop of your definition. This will make each side of the square a different color!
Geometric Math: To draw a triangle instead, you would repeat 3 times and turn $120^\circ$. To draw a circle, you would repeat 360 times and move 1 step while turning $1^\circ$.
Would you like to know how to use the "Ask and Wait" block so the user can type in the size of the square themselves?
📋
0 件のコメント:
コメントを投稿