GeoGebra Advanced Tutorial 12 – GeoGebraScript, Command Button, and Condition to Show

This is the 12th tutorial in the GeoGebra Advanced Tutorial Series and the first GeoGebra 4.0 Tutorial.  In this tutorial, we are going simulate the rolling of two dice using the command button and the randombetween command.

[iframe http://mathandmultimedia.com/wp-content/uploads/2011/10/rolldice.html 500 400]

If the applet above does not display correctly, click here if you want to download the GeoGebra 4.0 GGB file.

In this post, we are going to learn the following:

  1. use the command button, a new tool in GeoGebra 4.0
  2. learn basic GeoGebraScript
  3. learn to use Condition to show
  4. learn the random between command

Instructions

  1. Download the dice images.  It is composed of 12 images named b1 to b6 for blue dice with 1 through 6 dots and r1 to r6 for red dice with 1 through 6 dots.
  2. Open GeoGebra and use the View menu to hide the coordinate axes.
  3. Type r = 1 in the input bar and then press the ENTER key. Type also b = 3 in the input bar and the press the ENTER key. The variables b and r will determine which of the blue or red dice will appear. We just assigned the initial values.
  4. Type sum = b + r to determine the sum of b and r, and then press the ENTER key.
  5. Import images r1 and b1 using the Insert Image tool. The Insert Image button is “under” the Slider in the toolbar.
  6. Right click r1 and click Object Properties to display the Object Properties tab.
  7. Click the Advanced tab and type r = 1 in the Condition to show box. This means, that GeoGebra will show the red die with one dot if r = 1.
  8. Right click the blue with b1 and click the Object Properties to display the Object Properties dialog box.
  9. Select the Advanced tab and type b = 1 in the Condition to show box. Again this means that it will only show b1 if b =1. Notice that after this step, b1 will disappear because the value of b is not 1.
  10. Import the other images and fill up the necessary “conditions to show.”
  11. Use the grid line from the View menu to be sure that all red dice perfectly overlap each other and also the blue dice.

Creating the Command Button

We will use GeoGebraScript (or a series of GeoGebra keyboard commands) to randomly select values from 1 to 6 of b and r.

Instructions

1.) Click the Insert Button tool and click the drawing pad (or Graphics View) to display the Button dialog box.

2.) In the Button dialog box, type Roll Dice in the Caption text box, and type the text in the GeoGebraScript text box as shown in the figure above, and then press the Apply button when done.

3.) Now, click the Roll Dice button that you have created and observe what happens. Click a few more times.

4.) NOw, to create the Sum text as shown above,  first be sure that the Algebra Window is shown.

5.) Select the Insert Text tool and click the drawing pad to display the Insert Text dialog box.

6.) In the Insert Text dialog box, type Sum: and then click the Sum “variable” in the Algebra window. This should display the sum of b and r. After finishing, click the OK button and we are done.

Leave a Reply