How does it work?

DrGeo handles user scripts just like any other geometric item, or more exactly as any value item inserted into the geometric figure. A script depends on:

  • a set of items in the geometric figure (its parents item). This parent collection is used as arguments for the script. To specify its parent items, the user selects them in the drawing area.
  • a script definition (or code source). The returned value of the script is printed in the drawing area, the script value.
  • a position in the drawing area is where to print the script value.

DrGeoII script revisited

Regarding DrGeoII script implementation (as of 04/08/2008), as follows:

  • the script language is Smalltalk, a script is defined as an instance method of the DrGeoUserScripts class.
  • a script owns an arbitrary number of arguments, starting with zero. Script name uses the Smalltalk convention: unary message or keyword message.
  • To create and to edit a script, the user operates with a Browser narrowed to the DrGeoUserScripts class

Step by step process to work on a script

We will give two examples, in this article one script without any arguments, and in a next article a script with two arguments. From the background menu of DrGeoII, go to numerics>edit script. A class browser window opens on the DrGeoUserScripts class. We can create and edit the script from there. You are encouraged to experiment the class browser to get your own feeling with the tool.

The browser is opened by default on the examples message category. The pane on the bottom is the place to write code. Edited code must be confirmed with the Alt+s key stroke. When confirming the code change, the method is compiled and DrGeoII is informed about the change, so the drawing area is updated.

A script without arguments

Let's say we want a random integer in ]-10 ; 10]. The method could looks like:

editScript1.png

Now you want to use this script in your drawing area. From the DrGeoII background menu, go to numerics>use script. In the newly opened wizard dialog, you can select the script:

Select a script to use in the drawing area

You may have noted the script description is the comment at the beginning of the message source code, between the double quotes.

Next, as this script owns no argument, click anywhere in the drawing area, the script value will be plugged in at this place. Now when you move this value with the mouse, you will note the script value is changing. Obviously it is a random number!

Of course the script value can be used as any other item value: to define a point by coordinates, or as an argument to another script.

Conclusion

In this article, we have exposed the overall structure of the DrGeoII Smalltalk script system and how to use it. We have shown a simple script example without argument to generate random integer.

The DrGeoII Smalltalk script system completely fit in the OLPC philosophy regarding introducing programming to kid. Not only with DrGeoII kids can write code snippet but they can also do mathematical calculus. Moreover the Smalltalk environment provide an extremely friendly environment to write code: the class browser, the debugger and many more friendly tools.