DrGeo
GNU Dr. Geo is an interactive geometry software that allows its users to design & manipulate interactive geometric sketches, including dynamic models of Physics. It is free software, created by Hilaire Fernandes, it is part of the GNU project.
It runs over a Morphic graphic system. Dr. Geo was initially developed in C++ with Scheme scripting, then in various versions of Smalltalk with Squeak, Etoys_ for One Laptop per Child Pharo then Cuis-Smalltalk.
Objects
Dr. Geo manipulates different kinds of objects such as points, lines, circles, vector, values, geometric transformations, scripts.Points
Dr. Geo has several kinds of points: a free point, which can be moved with the mouse and a point given by its coordinates.Points can also be created as the intersection of 2 curves or as the midpoint of a segment.
Lines
Dr. Geo is equipped with the classic line, ray, segment and vector.Other curvilinear objects include circles, arcs, polygons, and loci.
Transformations
Besides the parallel and perpendicular line through a point.Dr. Geo can apply to a point or a line one of these transformations:
- reflexion
- symmetry
- translation
- rotation
- homothety
Macro-construction
When some objects, called final depend on other objects, called initial, it is possible to create a complex construction deducing the final objects from the user-given initial objects. This is a macro-construction, a graph of interdependent objects.
Programming
Access to user programming is at the essence of Dr. Geo: from the software, the user can directly read, study, modify and redistribute modified version of Dr. Geo. Additionally, scripting embedded in sketch is proposed.Dr. Geo source code is Smalltalk. It is also the language used for user programming: to extend Dr. Geo with arbitrary computing operations and to define a geometric sketch entirely with programming instructions.
Dr. Geo is shipped with its source code and the developer tools. Therefore its code can be edited and recompiled from Dr. Geo while it is functioning. This design, inherited from Smalltalk, makes easy to test new ideas and new designs.
Smalltalk script
A script is a first class object defined along Dr. Geo code. It comes with zero, one or several arguments, from types selected when defining the script. When an instance of a script is plugged in a canvas, the user first selects its arguments in the canvas with mouse clicks, then the position in the canvas of the script output. The script is updated at each canvas computation. Scripts can be used in cascade, with one as the argument of another one.Script are designed to be used in two different ways:
- To output an object and to show its result in the canvas. This result can be used when building subsequent objects.
- To access objects in the canvas: model or their view for arbitrary uses and modifications. For example to modify the color of an object given the result to a computation.
The computation of the script is done in its #compute method. For example, to calculate the square of a number, la méthode
compute
"returns the square of a number"
^ self arg1 valueItem squared
creates a numeric object, whose value is the square of its first and unique argument of type number object. Whenever the first number is changed, the script returned value changes too.
Smalltalk sketch
Dr. Geo Smalltalk sketches are sketches entirely defined in the Smalltalk language. This is not about constructing a sketch with the Dr. Geo graphical interface, but about describing a sketch with the Smalltalk language. A programming interface with an easy and light syntax is provided.Smalltalk itself is a high level language, carefully crafted iteratively for about 10 years at Palo Alto Research Center. When a sketch is described with Smalltalk code, all the features of the language are used: object oriented programming, variable, collection, iterator, randomness to get a slightly different sketch at each execution.
A Smalltalk sketch is edited and tested with the Smalltalk sketch editor. Such sketch can be debugged and executed step-by-step. Its code is saved, as any source code, to an external text file encoded with UTF-8, to support native language.
Sierpinski triangle
Here is how to program a Sierpinski triangle recursively. Its red external summit is mobile.c := DrGeoSketch new.
triangle := [:s1 :s2 :s3 :n |
c segment: s1 to: s2; segment: s2 to: s3; segment: s3 to: s1.
n > 0 ifTrue: [
triangle
value: s1
value: hide
value: hide
value: n-1.
triangle
value: hide
value: s2
value: hide
value: n-1.
triangle
value: hide
value: hide
value: s3
value: n-1.
triangle value: 0@3 value: 4@ -3 value: -4@ -3 value: 3.
show
Fibonacci spiral
A Fibonacci spiral programmed with geometric transformations. The points a and b of the resulting interactive sketch are mobile.canvas := DrGeoSketch new.
alfa := hide.
shape := .
fibo := .
fibo := [ :f :o :c :k | | e f1 f2 f3 c2|
"f1: term Fn-1, f2: term Fn, o & c: origin and center of spiral arm
e: extremity of the spiral arm"
f1 := f first.
f2 := f second.
f3 := f1 + f2.
e := shape value: c value: o value: f3.
c2 := hide.
k > 0 ifTrue: Newton-Raphson algorithmSmalltalk sktech can be used to design interactive sketch illustrating a numerical analysis method. Here the Newton-Raphson algorithm in a 5 steps iteration.
sketch := DrGeoSketch new axesOn.
xn := 2.
f := .
"Derivate number"
df := .
sketch plot: f from: -20 to: 20.
ptA := large; name: 'Drag me'.
5 timesRepeat:
parent: ptA.
ptB hide.
dotted forwardArrow.
ptA := sketch point: parent: ptB.
ptA hide.
dotted forwardArrow">Newton's method">Newton-Raphson algorithmSmalltalk sktech can be used to design interactive sketch illustrating a numerical analysis method. Here the Newton-Raphson algorithm in a 5 steps iteration.
sketch := DrGeoSketch new axesOn.
xn := 2.
f := .
"Derivate number"
df := .
sketch plot: f from: -20 to: 20.
ptA := large; name: 'Drag me'.
5 timesRepeat:
parent: ptA.
ptB hide.
dotted forwardArrow.
ptA := sketch point: parent: ptB.
ptA hide.
dotted forwardArrow.