A Programming Environment


The CindyScript programming language is a powerful tool for adding all kinds of enhancements to Cinderella constructions. It is designed in a way that the interplay with the geometric part of Cinderella and the simulations of CindyLab is a smooth as possible. Its functional design allows for high-level programming that enables rapid prototyping of interactive scenarios. The CindyScript language takes advantage of the fact that it runs in an environment in which on the one hand, facilities are present for graphical output and mouse-driven input (the geometry part), and on the other hand, physical simulations can be "outsourced" to the CindyLab simulation engine. As a consequence, the user can focus on programming the core problem. Very often, only a few lines of code need to be programmed to achieve the desired behavior. This is in strong contrast to usual programming languages, where a substantial part of the programming goes into the creation of a graphical mouse-driven user interface.


Sample Applications


The possibilities of CindyScript are endless and restricted only by the imagination of the user (and perhaps disk space), as in any other programming language. Nevertheless, we want to present here a few core application areas of the language.


Enhanced Drawing Output

One of the core facilities of CindyScript is that one can programmatically produce graphical output in a geometric view. With a dynamic geometry system one very often encounters situations in which it would be desirable to extend a geometric construction by more and more elements to such an extent that it becomes unreasonable to do this constructively. The programming facilities of CindyScript can be used to create these elements automatically.

CindyScript offers access to geometric transformations, so that it is very easy to create functionally very complicated geometric drawings with only a few lines of code.


A scripted "Pythagoras tree"



Programmatic Drawing

There is a special class of applications that cannot be covered at all by a classical approach to dynamic geometry. Constructions in dynamic geometry are inherently like unbranched programs, in which all calculations are always performed. Thus it is inherently difficult to include logical decisions or algorithmic behavior in a dynamic geometry program. Usually, these problems are resolved by conditionally controlling the visibility behavior of geometric elements by intersection properties (so-called Boolean points). Cinderella.2 also offers this functionality, but at the same time, CindyScript provides a much better and more elegant way of dealing with this problem.

CindyScript is a full-featured high-level language in which it is easy to implement arbitrary algorithmic behavior. Thus even complicated algorithms can be included on a general level in a dynamic geometry environment. Graphical output can be easily included in such algorithms.

The Delaunay and Voronoi diagrams of a point set




Analysis of Mathematical Functions

In particular, CindyScript allows for advanced facilities of function plotting. Thus it is possible to draw and analyze functions dealing with derivatives, extrema, and so on. Functions can be entered directly in a drawing, and results can be shown instantly. By this and the html export features of Cinderella it is easily possible to generate interactive worksheets that allow for a wide variety of modes of analysis of functions. Functions can also be defined by geometric dependencies of the geometric constructions, so it is easy to combine graphical input and analytic parts in one example.

Newton iteration to find a root of a function



Controlling the Behavior of Constructions

A particularly interesting scenario arises when CindyScript controls the positions of free elements. The movements controlled by CindyScript usually have priority over those performed by the user. Thus it is possible to react directly to user input. The following example elucidates this in a very simple scenario. The picture below demonstrates Pick's theorem, which allows one to calculate the area of a triangle by calculating the integer points in the polygon and the integer points on the boundary.

A demonstration of Pick's theorem


Pick's theorem applies only to polygons whose vertex coordinates are pairs of integers, a restriction that is usually not supported by a dynamic geometry program. However, by adding the following three lines of code one can alter the behavior of the three free points:

A.xy=round(A);
B.xy=round(B);
C.xy=round(C);


Although the points are freely movable, this code forces each vertex to snap to the closest integral point. All the text and all the green and yellow points in this example are also generated with CindyScript.


Design and Features


CindyScript was designed to suit the needs of programming mathematical problems in an environment in which the input parameters change dynamically by user interaction. On the one hand, this was achieved by providing a language that has both powerful data types (real numbers, complex numbers, lists, vectors, matrices, etc.) and powerful operations that can work on these data. On the other hand, it was achieved by taking the real-time requirements for interactive user input directly into account when the language was designed.


High-Level Functional Programming

CindyScript is a functional language. This means that all operations are expressed as the application of functions to data. Programming functionally may take some time to get used to, but it offers a very high expressive power, so that it is possible to describe complex situations with just a few lines of code. For instance, the following three lines of code calculate and print a list of the prime numbers smaller than 100:

divisors(x):=select(1..x,mod(x,#)==0);
primes(n):=select(1..n,length(divisors(#))==2);
print(primes(100));


The first line defines a function that returns a list of all divisors of a number x. The second line provides a function that returns a list of all numbers smaller than n that have exactly two divisors. These are exactly the prime numbers. The output of the algorithm is the following line:

[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]

Using these high-level programming facilities together with graphics input and output opens possibilities that are not available in most other programming environments. The picture below shows an iteratively defined plantlike structure that was programmed in CindyScript. The code for generation of this plant is shown next to it. It essentially uses only elementary drawing, advanced geometric transformations, and functional programming to create the entire drawing.

Growing a plant in a view



Real-Time Calculations

CindyScript code can be evaluated for even the tiniest move of a geometric configuration. In this way, it is possible to achieve real-time interaction with geometric drawings. A user selects a point, moves it, and then can directly watch the changing results of the calculations. Although CindyScript is an interpreted language, it is still fast enough to create a fluent drawing impression for most standard situations. The possibility of dynamically running programs that immediately react to user input opens a wide range of applications and interactive scenarios. Here the applications range from explanations at an elementary- and high-school level through university courses up to investigations in sophisticated mathematical research. The example below shows a snapshot of an illustration of linear regression by the least squares method. The picture is dynamically updated when points are moved or added.

Linear regression by Gaussian approximation



Exact Timing

CindyScript provides various possibilities for synchronizing programs both with real time and with the time of a physics simulation. Thus one can easily create simulations that involve timing behavior. This can be very useful in programming interactive games or edutainment scenarios in which, for instance, the task of solving an exercise is bound to time restrictions. The ability to synchronize CindyScript with the timing of physics simulations can be used in two directions. Thus one can use this technique to synchronize a physics simulation with real time. Alternatively, it is possible to couple programming time and computation time, making it possible to slow down or speed up a simulation synchronously with a computation.

A real-time clock



Advanced Plotting

One line of CindyScript code is sufficient for simple function plotting. For example, plot(sin(x)) will immediately invoke the graph of the sine function to be plotted in the view. However, Cinderella also provides several possibilities and enhancements that allow for the direct display of maxima, minima, and inflection points. With these features it is easy to make a visually meaningful analysis of functions. It is also possible to generate two-dimensional function plots that use color values for different function values. It is thus possible to create images of two-dimensional data quite easily. The picture below shows the density distribution of the function sin(dist(x-A)*dist(x-B)) for two points A and B.

Cassinian ovals as waves







Page last modified on Monday 21 of November, 2005 [20:38:22 UTC].
The original document is available at http://doc.cinderella.de/tiki-index.php?page=A%20Programming%20Environment