<< Chapter < Page
  Teaching beginners to code     Page 8 / 9
Chapter >> Page >

Programming blocks belonging to the Motion group

Image 13 shows the programming blocks that are exposed by clicking the Motion button at the top left of Image 4 .

Image 13. programming blocks belonging to the motion group.

Missing image.
Image 13. Programming blocks belonging to the Motion group.

You saw three of the blocks from Image 13 being used in Image 6 , Image 7 , and immediately below the top tan block in the bottom script in Image 8 . Now we need to use another of the blocks from Image 13 .

Turn around and face the other way

Recall that the blue point in direction block in the top script in Image 8 causes the basketball to turn to face to the right when the user clicks the green flag.

The two turn blocks in the bottom script in Image 8 cause the basketball to rotate around its center by 180 degrees. This, in turn,causes it to face in the opposite direction from the direction that it was previously facing. (It also turns it upside down, but that doesn't matter for a round basketball.)

This is the action that is required whenever either of the touching blocks is true. In other words, whenever the basketball touches either of the beach balls, it must turn to facethe opposite direction and be prepared to move 90 steps in that direction the next time the user clicks the basketball.

An online version of this program is available

A copy of this program has been posted online for your review (see Resources for the URL) . If you don't find the program using that URL, search the Scratch site for the usernamed dbal.

Run the program

I encourage you to use the information provided above to write this program. Experiment with the code, making changes, and observing the results of yourchanges. Make certain that you can explain why your changes behave as they do.

Just for fun, use blocks from the purple Sound group and add some sound effects to your program.

I also encourage you to write the program described below.

Student programming project

Write a Scratch program named IfWithVar01 that produces the output shown in Image 14 when the user clicks the green flag.

Image 14. initial output from the program named ifwithvar01.

Missing image.
Image 14. Initial output from the program named IfWithVar01.

Orthogonal axes in Cartesian coordinates

When the user clicks the green flag, a DrawingPencil sprite draws a pair of orthogonal axes that intersect at the origin in the white Stage area.Make the horizontal axis extend from -200 to 200. Make the vertical axis extend from -100 to 100.

Draw a straight line to the location of the next mouse click

Each time the user clicks the mouse in the white Stage area (after the user has clicked the green flag) , a straight line is drawn from the current location of the DrawingPencil to the location where the mouse click occurred. Image 15 shows an example output after two mouse clicks.

Image 15. program output after having clicked twice in the stage area.

Missing image
Image 15. Program output after having clicked twice in the Stage area.

A sneak peek at the solution

In case you need to sneak a peek at the solution to this programming project, a copy of this program has been posted online for your review (see Resources for the URL) . (If you don't find the program using that URL, search the Scratch website for the usernamed dbal .)

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Teaching beginners to code. OpenStax CNX. May 27, 2013 Download for free at http://cnx.org/content/col11498/1.20
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?

Ask