CONNECTING OF TURTLES IN A PROGRAMMING LANGUAGE BASED ON L-SYSTEMS

The connecting of turtles which is introduces in this article, extends the possibility of use L-system based method in computer graphics. It can be used for terrain modelling and for creating of leaves. Introduction There is many fractal methods [1,6] for generating of models of complex natural object, e.g. IFS, midpoint displacement, or L-systems. L-systems are often used for modelling of plants. The L-systems [2,3] are based on rewriting systems. They contain symbols for developing of the plant skeleton and special symbols '[' and ']' for branching. Tracing the object boundary by a turtle and filling it can create enclosed objects, like leaves. There is no published method for connecting curves drawn by turtles between '[' and ']' and the curve drawn after ']'. A functional programming language based on L-systems was proposed in [4]. New data types and techniques for turtle connection extended this language. This article is organised as follows: the new data types are introduces in section "New data types and structures" and following sections explain principles of turtle connection. New data types and structures Real numbers were the only one data type in previous language version. It was insufficient for future development of language features. Data types string, list and special value null were added. Strings are bounded by quotation marks and are used for debugging purposes and for specifying of some behaviour of functions. List is a structure data type. It is a indexed sequence of items which can be of any data type (number, string, list or value null). Null is a special value. It represents empty list or invalid value. There are three ways to construct a list: • Enumeration of its elements. The enumeration is enclosed en braces and its items are separated by commas: Example: {"Hello",2,5.6} • Linear sequence denoted first and last element or denoted by first and last element and number of elements. Double colon separates these parts. Example: {1::8} stands for {1,2,3,4,5,6,7,8}, {1::1::8} stands for {1,1,1,1,1,1,1,1}. • Connecting of two lists or scalar values by operator $. Multiturtle system There is only a one turtle in classical L-systems. The branching of structure is denoted by symbols '[' and ']' which mean pushing and popping state of turtle into or from a stack respectively. Let have another look to branching. Lets consider, that the sequence between '[' and ']' is interpreted by a new turtle. This turtle is called daughter turtle and its initial state is inherited from its mother. The symbol ']' now means: "Kill daughter turtle and return to its mother. " Connected turtles Connected turtles are the simpler variant of connecting turtles. We can create pair of banded turtles instead of creating an independent daughter turtle (it is denoted by square parenthesis). Mother turtle and its daughter form this pair. These turtles draw their curves and then are connected by connecting function. Programming construction for connected turtles can be everywhere instead of calling a turtle function. It has following form: {Body for the daughter turtle, body for the mother turtle, connecting function} Connecting functions are special type of turtle functions. They control two turtles: the daughter turtle and the mother one. A point of connection and new orientation is computed from co-ordinates of these turtles and their orientation in a drawing space. Both turtles are brought to the point of connection along their traces. The area between traces of these turtles can be filled by a colour of the mother turtle. When the daughter turtle is connected to the mother one, it dies. The language contains several standard connecting functions which are derived from normal turtle functions. Following code shows using of connected turtles. An ornament created by this program is shown in Fig. 1. Atraktor(h)=Barva.Nastav (12,{0.2,0.2,0.3}) Pero (1) Presun (-100) Vpravo (/4) Presun (300) Vlevo (/4) A(200,pi/4,h); A(d=800,alfa,h) = % Central shape [Presun (d/3) A(d/3,alfa,h-1)] {% Left shape drawn by daughter turtle Barva.Dalsi Vlevo (alfa) A (d/(2*cos(alfa)),alfa/2.5,h-1) Vpravo (2*alfa) Barva.Dalsi A (d/(2*cos(alfa)),alfa/2.5,h-1), % Right shape drawn by mother turtle Vpravo (alfa) A (d/(2*cos(alfa)),alfa/2.5,h-1) Vlevo (2*alfa) Barva.Predchozi A (d/(2*cos(alfa)),alfa/2.5,h-1) Vpravo (alfa), % Connect these shapes and fill the area if it is the bottom % fractal level. SpPripoj (h=1)}; final A(d=10)=Kresli (d); Addressing of turtles Connected turtles are suitable only for special cases. They cannot create complex shapes, like a grid. System for joining any turtle is needed. If we want connect any turtle, we must designate which turtle we want to attach. Each turtle has its unique address for this purpose. This address is based on genealogy; the address of daughter turtle is derived from the address of its mother according following rules: 1. The address of basic turtle is null. 2. Daughters of every turtle are indexed, the index of the first daughter of every turtle is zero, the next has index one etc. 3. Let M be an address of some turtle and d is an index of its daughter. Then the address of the daughter (D) is formed by the index d concatenated with its mother address M: D=d$M Example: null is the basic turtle, {0} is the first daughter of the basic turtle, Fig. 1 Ornament created by connected turtles {1,0} is the second daughter of the first turtle of the basic turtle and {0,1,0} is its first daughter. Branched structure with turtle addresses is shown in Fig. 2. Connection of arbitrary turtle The daughter turtle usually dies when it completes it action. This place is detonated by a right square bracket. But if we make the turtle fall asleep, we should awake it again and connect with another turtle. To denote the turtle asleep, we use the keyword sleep before the right square bracket. This sleeping turtle should be referenced by it address. We can connect the sleeping turtle using connecting command with awake. The form of this command is: {awake address, connecting function} As the connected turtle must not be daughter of the one it connects to, we will call the couple of the turtles the attached one and the running one. Using connecting command with awake we can create a simple net for modelling of mountain as it is shown at Fig. 3.