needs to be long enough to
touch the cubes going by on
the conveyor belt
(Figure
H
)
.
If you want, add a gripper to
the end of the robot’s arm.
You can custom design the
shape using the same kind
of controls as in Tinkercad
(Figure
I
)
.
Make sure to group all the
pieces of the arm together,
so they act like one shape
(Figure
J
)
.
H I
J
Chapter 3: Robots That Think 91
Make_Simple_Robots_interior_FIN.indd 91Make_Simple_Robots_interior_FIN.indd 91 4/26/22 1:55 PM4/26/22 1:55 PM
As you create your arm sprite, keep an eye on the stage (upper right
of the screen) to see how it fits in with the rest of the scene
(Figure
K
)
. Don’t worry about animating this sprite just yet — you can do
that when you are coding.
6. Now it’s time to create the cubes. Since you only see one cube at a time,
you can create one cube sprite and tell it to change to a different
costume every time it goes by
(Figure
L
)
. If you make the costume
K
L
92
Making Simple Robots, 2nd Edition
Make_Simple_Robots_interior_FIN.indd 92Make_Simple_Robots_interior_FIN.indd 92 4/26/22 1:55 PM4/26/22 1:55 PM
changes random, it will make the animation more fun to watch. Here’s
what to do:
Create a new sprite and give it a name, like Cube.
Use the rectangle tool to make the first cube. Check the
Stage to be sure it’s the right size for your backdrop. Then
use the Fill tool to make it whatever color you like.
IMPORTANT: Don’t put an outline on this sprite! The color of the cube
needs to touch the robot arm. If the Outline is on, click the red slash
to turn it off.
Name the costume with the color of the cube. Then right click
on the first cube costume to duplicate it. Change the color of the
second costume and give it a name that matches.
Continue making as many costumes as you like. Remember to
make at least one of them green! If you have a lot of different
costumes, add a few more green costumes so they pop up more
often.
With all your artwork done, you’re ready to code! Start with the Cube sprite.
The algorithm for it looks like this:
Move one cube at a time from left to right along the conveyor
belt.
At the end of the conveyor belt, make these things happen
instantly:
change the cube’s color randomly,
send the cube back to the beginning of the conveyor belt,
start the cube moving along the conveyor belt again from left
to right.
If the robot broadcasts a message that the cube is green, make the
cube change direction and fly off toward the Green Cubes sign.
7. To use blocks from the Motion (dark blue) menu to make the Cube
sprite move to the right:
Chapter 3: Robots That Think 93
Make_Simple_Robots_interior_FIN.indd 93Make_Simple_Robots_interior_FIN.indd 93 4/26/22 1:55 PM4/26/22 1:55 PM
Drag a “move [10] steps” block
into the workspace. Click on it
to see the sprite move a short
distance to the right
(Figure
M
)
.
Put the “move [10] steps” block
inside a “forever” block from
Control (orange). Click on this
stack to make the cube move
across the whole stage. Notice
that the cube stops moving
when it hits the right edge of
the Stage.
8. To make the Cube sprite go back to
the beginning when it reaches the
end of the conveyor belt:
Drag an “if-then-else” block
from Control inside the
“forever” block
(Figure
N
)
.
Drag the “move” block inside the mouth below “else.” Change
the number of steps to 2. This will make it move slower.
Go to the Sensing menu (light blue) and drag the pointy-
ended “touching [mouse-pointer]?” block inside the space
on the “if-then-else” block. Click on the little arrow next to
“mouse-pointer” and change it to “edge”
(Figure
O
)
.
To make the Cube sprite jump back to the right spot:
In the Motion menu, find the “go to x: [] y: []”
block — but don’t grab it yet
(Figure
P
)
.
Go to the Stage, drag the Cube sprite to the beginning of
the conveyor belt, and drop it. Watch how the numbers on
the “go to” block change! (The numbers refer to the cube’s
location on an invisible grid. You can find any location by
looking at the x and y numbers of the square its on. To
see the grid, search for it in the Backdrops library.)
N
M
94
Making Simple Robots, 2nd Edition
Make_Simple_Robots_interior_FIN.indd 94Make_Simple_Robots_interior_FIN.indd 94 4/26/22 1:55 PM4/26/22 1:55 PM
Now drag the “go to” block into the remaining mouth of the
“if-then-else” block. Try dragging the Cube sprite to a different
part of the Stage. Click on the stack of code to make sure the
cube goes back where you want it to, and then moves along the
conveyor belt over and over.
O
P
Chapter 3: Robots That Think 95
Make_Simple_Robots_interior_FIN.indd 95Make_Simple_Robots_interior_FIN.indd 95 4/26/22 1:55 PM4/26/22 1:55 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.154.208