A Novel Algorithm for Generating an Islamic Pattern Based on Cellular Automata

Seyed Amir Hadi Minoofam*, Azam Bastanfard** *Islamic Azad University of Qazvin, [email protected] **Islamic Azad University of Karaj, [email protected]

Abstract: Creating algorithmic approach for generating Islamic as square or rectangular kufic, because its letters are patterns extends its applications in architectures, decoration and art. Researchers face with many challenges in developing like rectangles and squares and are often used in tiling algorithms such as providing a simple and applicable architectures. Ma'qeli is an Arabic name refers to this fact algorithm to describe complex patterns. This paper used that the design and reading of these patterns require very cellular automata with extended Moor neighborhood to much thinking [12]. Ma'qeli script is based on square tiles generate Ma'qeli script patterns. The proposed approach leads to accurate and scalable algorithm for generating words like chess cells and written using geometrical shapes like pattern. The joint and disjoint pattern shapes of the letters will squares, rhombuses, rectangles, parallel and intersecting be reserved in this approach. The results of implemented lines and usually with lack of points [13]. Because algorithms demonstrate our approach with a variety of Ma'qeli Ma'qeli scripts are patterns based on square grids, patterns. therefore we can construct these patterns with cellular automata [15][16][17]. This paper describes a new Keywords: Cellular automata, Islamic patterns, Ma'qeli method for generating "Muhammad" pattern in Ma'qeli script, Non-photo realistic rendering, Pattern formation. script with cellular automata. We use extended Moore 1. Introduction neighborhood for managing letters effectively. The rest of the paper is organized as follows. Section 2 Pattern formation based on algorithm is used in refers to some related works. Section 3 describes the basic computer graphics as non-photo realistic rendering. Non- notions of two dimensional cellular automata. Section 4 photo realistic rendering is a challenging field which provides a novel algorithm for generating "Muhammad" includes modeling artificial and artistic things made by pattern using cellular automata. Techniques for creating humans. A cellular automaton is a good algorithmic visually appealing designs are proposed in section 5. approach used for pattern generation. Its grid based Experimental results appear in section 6. The paper is property makes it suitable for executing tiling algorithms. concluded in section 7. Tiling or tessellation means filling a plane with a collection of shapes that are completely filled with no 2. Related Works overlapping or blank [1]. Tessellation is found in many and are branches of non-photo new and old architectural buildings and one of the most realistic rendering techniques. Rendering of Islamic famous is Alhambra palace, Spain [6]. Ornamental geometry is one of the challenging tasks in computer geometry artisans have wonderfully decorated all surfaces graphics for example; Islamic geometry is used in many of the palace [2] [3]. Also in many artworks of designers countries in the world [2]. Recently, Kaplan offers an like Escher many beautiful patterns can be found [4] [5]. algorithm for generating Islamic star patterns based on These patterns have mathematical properties which make radially-symmetric motifs [18] [19]. Lu extracts some generating algorithm possible. Calligraphy is another symmetry in medieval Islamic tiling based on quasi- ancient art which creates many beautiful designs in crystalline [20]. Aljamali et al., as well as Valor have different countries depending on the script commonly done researches on classifying Islamic geometrical used there. For Example, calligraphy was written with patterns [21][22]. Arabic scripts in many countries in the Middle East [7] Also many researches have been done for generating [8]. Even because of the close dependency between calligraphic patterns in Chinese [23] [24] [25], Japanese and geometry, the calligraphy was [26] as well as Arabic scripts [27]. Although Ma'qeli called "geometry of script" [9]. Therefore the calligraphy script is also a kind of Islamic geometry, unfortunately is based on geometry and mathematics as well, and we limited numbers of researches have concentrated on can generate algorithms for writing letters. One of the Ma'qeli script. Ahuja and Loeb described the tessellation most important Arabian scripts is the kufic script. Kufic of the word "Ali" in a hexagon [28]. Mostapha and script generally is angular and had written in different Krishnamurti introduced a prototype for generating forms such as Ma'qeli form. Ma'qeli kufic is also known

431 calligraphic patterns, but they didn‘t describe the way for Next section explains about transition rules for creating original pattern [29]. generating "Muhammad" pattern. Ma'qeli patterns are inserted in a geometrical field. In this script all letters are based on horizontal or vertical 4. Transition Rules for "Muhammad" Pattern lines with 90˘ angels. Although there are many ways to create In this paper we generate calligraphic "Muhammad" "Muhammad" pattern from artistic point of view, in this pattern using cellular automata. In comparison with section we extract some rules for generating 3 most previous algorithms, our algorithm is simpler, more famous models of "Muhammad" pattern. The word flexible and more scalable too. "Muhammad" formed by joint letters and in this word the some letters in joint form are as the same and this maybe 3. Two Dimensional Cellular Automata lead to same states for different cells which complicated Cellular Automata are concentrated on recently 50 rule extraction process. years and has become applicable in many sciences. The basic idea of cellular automata is quite simple: each cell in discrete time-steps updating its states according to a transition rule which is globally and synchronously applied to each cell. The cell value is determined by the configuration of its neighbors that is specified in transition rule by iteration. The updated values of each cell will become the inputs for the next iteration [30]. Two most applicable neighborhood definitions in cellular automata are: Moore and extended Moore [31]. In Moor neighborhood, adjacent cells considers as neighbors in vertical, horizontal and diagonal directions. The extended Moor neighborhood in its simplest form considers one cell over the Moor neighbors. The proposed approach used extended Moor neighborhood. It simply handles joint and disjoint letters and keeps performance in a good level. Fig.1 illustrates a central cell and its 24 Fig.2. (a) Model 1 of "Muhammad" pattern tiling From the Nabi Mosque of Qazvin (b)Model 2 of "Muhammad" pattern tiling From the neighborhoods. In some literatures the beginning letter of Ma'soumeh shrine of Qum. (c) Model 3 of "Muhammad" pattern tiling the name of directions used to refer neighbor cells [32] From the Ma'soumeh shrine of Qum [33]. Fig.1 shows this method of naming to refer to the cells in an easy understanding way. For instance, "NEE" Fig.2 shows architectural buildings contain three refers to the northeast east cell and "NNEE" refers to the models of "Muhammad" pattern that we called them north north east east cell. Because in calligraphy the space "model 1", "model 2" and "model 3" respectively. is either white and leaved blank or colored with the ink, There is a common part in three models. Fig. 3 shows we use two state cells for cellular automata to illustrate a process for creating this common part. basic ideas in calligraphy and simplify the implementation. Thus each cell with value 1 is colored or alive and each cell with value 0 is white or dead.

Fig.3. A process for creating the common part between 3 models of "Muhammad" pattern

Fig.1. the extended Moore neighborhood The rest process for creating model 1,2 and 3 of "Muhammad" pattern are illustrated in figures 4 to 6 respectively.

432 15) Ei.EEi.NEEi.NNEEi.NNEi.NNi

16) Ei. EEi. NNEEi. NNEi

17) Ei. EEi. NNEEi

18) Si. SEi. SEEi. NEEi. NNEEi

19) Si. SSi. SSEi. SSEEi. EEi. NEEi. NNEEi Fig.4. The rest process for generating model 1 of "Muhammad" pattern 20) Ei. SEi. SSEi. SSEEi

21) Ei. EEi. SEEi. SSEEi

22) Ni. NEi. NEEi. EEi. SEEi

23) Ni. NNi. NNEi. NNEEi. EEi. NEEi

24) Ei. Wi.EEi. NEi. NNEi. NNi. NWi. NNWi 25) SSW . SS . EE . NEE . NNEE . SEE i i i i i i Fig.5. The rest process for generating model 2 of "Muhammad" 26) SSWi. SSi. SSEi. Ei pattern 27) SSi. SSEi. SSEEi. Ei. EEi

28) Si. SSi. SEi. SEEi. SSEEi. Ni. NEi. NEEi

These rules are generating the pattern. In each time step, any true rules are acting and generating a part of pattern. Each rule describes some neighbors of a cell that are alive. For example, rule (2) is points to the south and Fig.6. The rest process for generating model 3 of "Muhammad" the southwest neighbors. If the mentioned neighbors of pattern any cell are alive, those cells come in to alive cells in the

next time step. Thus it is possible to provide a flexible algorithm for The first rule is conserving the generated pattern generating these models of "Muhammad" pattern. Also from previous steps. Clearly, this rule determines that if common part rules are reused in the models and can make C was equal to 1 in the previous step, then C should the algorithm shorter and simpler. In our extracted rules, i i+1 remain 1 in the next step. Other rules are defined based on the "i" index demonstrate current state and the "i+1" index neighborhoods. If the neighbors mentioned in a rule are demonstrate the next state of a cell. The proposed method alive and the others are dead, then that rule is true. determines flexible rules to generate other patterns as We provide an algorithm for generating all 3 models well. For example the rules for generating the common of "Muhammad" pattern. In this algorithm the sign " ⊕ " part between 3 models are as follows: means exclusive or. The algorithm is as follows:

1) Ci for i=1 to n // in this case n=35 2) Ei { 3) Ni. NWi if (Ci= =1) then Ci+1=1 4) Ei. EEi. SEEi else { //Common part 5) Ni. NNi. NNWi. NNWWi MC123=Ei ⊕ (Ni.NWi) ⊕ EE(Ei. i.SEEi) 6) Ei. NEi. NNEi. NNi. NNWi ⊕ (Ni.NNi.NNWi.NNWWi) ⊕ (Ei.NEi.NNEi.NNi.NNWi) 7) Ei. EEi. NEEi. NNEEi. NNEi. NNi ⊕ EE(Ei. i.NEEi.NNEEi.NNEi.NNi) ⊕ N(EEi. i.Si.NEi.NEEi.SEi.SEEi) 8) EEi. Ni. Si. NEi. NEEi. SEi. SEEi ⊕ (23-i)(Ni.NNi.NEi.NEEi.NNEEi) 9) Ni. NNi. NEi. NEEi. NNEEi ⊕ (Ni.NNi.NNEi.NNEEi) ⊕ (Wi.NWi.NNWi.NNi.NNEi) ⊕ (Wi.WWi.NWWi.NNWWi.NNWi.NNi) 10) Ni. NNi. NNEi. NNEEi ⊕ (Ni.NWi.NWWi.NNWWi) ⊕ (Ei.NEi.NNEi.NNi. NNWi) 11) Wi. NWi. NNWi. NNi. NNEi ⊕ EE(Ei. i.NEEi.NNEEi.NNEi.NNi) ⊕ ⊕ 12) Wi. WWi. NWWi. NNWWi. NNWi. NNi EE(Ei. i.NNEEi.NNEi) EE(Ei. i.NNEEi) ⊕ (Si.SEi.SEEi.NEEi.NNEEi) 13) Ni. NWi. NWWi. NNWWi ⊕ (Si.SSi.SSEi.SSEEi.EEi.NEEi.NNEEi) 14) Ei.NEi.NNEi.NNi.NNWi ⊕ (Ei.SEi.SSEi.SSEEi) ⊕ EE(Ei. i.SEEi.SSEEi)

433 ⊕ (Ni.NEi.NEEi.EEi.SEEi) 5. Pattern Replicators ⊕ (Ni.NNi.NNEi.NNEEi.EEi.NEEi) Representing a kind of self-replicating patterns in 2D ⊕ W(Ei. i.EEi.NEi.NNEi.NNi.NWi.NNWi) cellular automata is possible by using Edward Fredkin ⊕ (SSWi.SSi.EEi.NEEi.NNEEi.SEEi)⊕ (SSWi.SSi.SSEi.Ei) rules [30]. In 8 neighboring Moore cellular automata, the ⊕ (SSi.SSEi.SSEEi.Ei.EEi) Fredkin rule is as follows [31]:

if MC123>0 then Ci+1=1 +++++++= Ci+1 (Ni Ei Wi Si NWi NEi SWi SEi 2mod) (1) }

//Model1 Clearly, rule (1) means that if the sum of all Moore neighbors of a selected cell, without the cell itself is odd, if(pattern= model1) then then the selected cell comes to the alive cells in the next { time step. Rule (1) is a rule for outer totalistic automata. If we M1=(S .SS .SE .SEE .SSEE .N .NE .NEE ) i i i i i i i i take to account the state of the cell itself, then we‘ll have ⊕ (S .SS .SE .SEE ) i i i i outer totalistic automata. In totalistic automata the ⊕ (Si.SWi.SWWi.WWi.SSWWi.SSEEi.EEi.NEEi.SEi) Fredkin rule is such as rule (2)[32]. ⊕ (Si.SSi.SSWi.SSWWi.SWWi.SSEEi.SEEi.EEi) ⊕ (Si.SSi.SSEi.SSEEi.SEEi.EEi) ++++++++= Ci+1 (Ci Ni Ei Wi Si NWi NEi SWi SEi 2mod) (2) if M1>0 then C =1 i+1 } The rules (1) and (2) are replicated each pattern after 8 time steps. We call this 8 time step, the replication period. //Model2 In each replication period, rule (2) replicates the pattern 8 if (pattern= model2) then times and rule (1) replicates it 9 times in all directions. If we ignore the vertical and horizontal neighbors in { rule (1) and only keep the diagonal cells, we reach to a

M2=(Si.SSi.SWi.SWWi.SSWWi.SEEi.EEi.Ni.NEEi.NNEEi new replicator which called it as "diagonal replicator". .NWWi.NWWi) ⊕ (Si.SSi.SWi.SWWi.SSEEi.EEi.NEEi) ⊕ Rule (3) describe the rule of diagonal replicator. (Si.SSi.SSWi.SSWWi.EEi.SEEi.SSEEi) ⊕ ⊕ +++= (SSi.SSWi.Ei.SEi.SSEi) EE(Ei. i.SEEi.SSEEi.SSEi.SSi) C i + 1 ( NW i NE i SW i SEi 2mod) (3)

if M2>0 then Ci+1=1 The totalistic for of this rule is obtained by keep to //Model3 account the center cell and leads to rule (4). if(pattern= model3) then C (C NW NE SW ++++= SE 2mod) (4) { i+1 i i i i i

M3=(Si.SSi.SWi.SWWi.SSWWi.EEi.SEEi.NEEi.NNEEi.Ni In each replication period, rule (7) replicates the .NWi.NWWi) ⊕ (Si.SSi.SWi.SWWi.EEi.NEEi.SEEi.SSEEi) pattern 4 times in diagonal directions and also conserves ⊕ (Si.SSi.SSWi.SSWWi.EEi.SEEi.SSEEi) the pattern itself. ⊕ (Si.SEi.SEEi.EEi.NEEi.SSEEi) Using the above rules leads to nice and novel patterns. ⊕ (Si.SSi.SSEi.SSEEi.SEEi.EEi) The generated results of our proposed algorithm will be discussed in the next section. if M3>0 then Ci+1=1 } 6. Results Calligraphy is a challenging task in non-photo realistic } rendering. In this paper we described a novel algorithm } for generating 3 different models of "Muhammad" pattern with cellular automata. The results of our algorithms which are implemented in Visual C++ environment using In this Algorithm the loop counter should be n=35 to OpenGL library are illustrated as follows. We executed be able to generate each selected model of "Muhammad" all rules in 24 steps and got following results. An example pattern. Note that in step 23, a rule is automatically of executing the outer totalistic rule (1) for model 1 is ignored because of leading to the correct pattern. illustrated in Fig.7. In Fig.8 execution of the totalistic rule Otherwise, the iteration of this rule cause to additional (2) on model 2 of "Muhammad" pattern is shown. Fig. 9 incorrect pixels that make the pattern wrong. It is clear demonstrates the execution of the outer totalistic rule (3) that this algorithm is flexible and can be extend for other on model 3. Finally, Fig.10 shows the result of applying patterns too. It just needs to extract the rules and apply totalistic rule (4) on model 1. All these rules applied 24 them. steps. Fig.11 illustrates a mosque-like model.

434

Fig.7. Applying rule (1) on model 1 of "Muhammad" pattern after Fig.10. Applying rule (4) on model 1 of "Muhammad" pattern after 24 steps 24 steps

Fig.8. Applying rule (2) on model 2 of "Muhammad" pattern after Fig.11. Mosque-like model, consists of all generated results by 24 steps tiling

7. Conclusion The Ma'qeli script is a good instance in calligraphy which provides different versions of generating word patterns. As this script is based on a square grid, the proposed algorithm not only provide the simplicity and flexibility for generating these patterns but also have the power for controlling complexity and possibility of extending the functionality of the rules. Using our approach has three advantages: first, appropriate transition rules are provided some benefits such as holding the performance at a good level and being scalable too. If the region of Moore neighborhood is extended, then although more features are reachable, bat the performance decreased because it needs more conditions to be checked. Scalability means that these rules can be modified a little for generating another type of a pattern or forming new patterns. Second, mentioned Fig.9. Applying rule (3) on model 3 of "Muhammad" pattern after rules contain different ways of drawing this pattern based 24 steps

435 on similar states. Third, the extended Moor neighborhood [26] Q. Guo and T. L. Kunni, "Nijimi" rendering algorithm for creating can manage the joint and disjoint of Arabic and Persian quality black ink paintings, Computer Graphics International Proceedings 2003,pp. 152-159, 2003. letters and provides nice drawings. Examples of Ma'qeli [27] A. Belaïd and Ch. Choisy, Human Reading Based Strategies for script can be found in cultural heritage and old literatures. off-line Arabic word recognition, SACH'06, Univ. Of Maryland, Also it is so applicable in modern architectures, College Park, 2006. [28] M. Ahuja and A.L. Loeb, Tessellation in . MIT handicrafts, decorations and art. One of our future works press, 1995. is the design of more complex patterns and search about [29] H. Moustapha and R. Krishnamurti, Arabic calligraphy: A using geometrical transformations in cellular automata. computational Exploration, Mathematics and Design, Deakin, pp. 294-306, 2001. References [30] W.H. Steeb, the Nonlinear Workbook, Singapore: World Scientific Publishing, 2005. [1] B.Grunbaum and G.C.Shephard, Tiling and Patterns, New York, [31] J.L. Schiff, Cellular Automata: A Discrete View of the World, John Freeman, 1987. Wiley, 2008. [2] S.J. Abas and A. Salman, Symmetries of Islamic Geometrical [32] R.E. Griswold, Drawdown Automata, Part 2: Neighborhoods and Patterns, World Scientific, Singapore, 1998. state-transition Rules, Part1-3, 2004. [3] A. Moon, Digital illumination. TUGboat, Vol.24, Proceedings, pp. [33] K. Morita, Cellular Automata and Artificial Life: Computation and 18-22, 2003. Life in Reversible Cellular Automata, Complex Systems, pp. 151- [4] Craig S. Kaplan and David H. Salesin, Escherization. Proceedings 200, 1998. of SIGGRAPH 2000, Computer Graphics Proceedings, Annual Conference Series, pp. 499-510, 2000. [5] D.Dunham, An algorithm to generate repeating hyperbolic patterns. ISAMA, 2007. [6] M.C. Escher. Escher on Escher: Exploring the Infinite. Henry N. Abrams, Inc., 1989. [7] A. Schimmel, Calligraphy and , New York: Univ. Press, 1984. [8] J. Bonner. Three traditions of self-similarity in fourteenth and fifteenth century Islamic geometric ornament, ISAMA/ Bridges 2003 Proceedings, pp. 1-12, 2003. [9] I. El-Said, A. Parman, Geometric Concepts in Islamic Art, World of Islam Festival, 1976. [10] M. Sakkal, The art of Arabic calligraphy, (http://sakkal.com/ ArtArabicCalligraphy.html), 1993. [11] D. Hill, O. Grabar, and its decoration, Faber & Faber, 2nd, London, 1967. [12] M. Harati, M. Keshavarz, Ma'qeli Script, In Persian, Madreseh Press, 1999. [13] H. Fazaeli, Ta'lim-e Khatt: Persian Calligraphy A Manual of Instruction, In Persian, Soroush Press, Tehran, 2004. [14] M. Maher AnNaghsh, Design and Execution in Persian Ceramics, In Persian, Reza Abbasi Museum Press, Tehran, 1984. [15] S.Wolfram, a New Kind of Science, Canada: Wolfram Media, 2002. [16] A. Aljamali and E. Banissi, Normalisation and Exploration Design Method of Islamic Geometric Patterns, Proc. IEEE Inter. Conf. on Geometric Modeling and Geraphics, pp. 42-48, 2003. [17] A. Aljamali and E. Banissi, Normalised Grid/Motif Based Patterns: Islamic Geometric Patterns, Proc. IEEE Inter. Conf. on Information Visualization, IV‘97, pp. 252-257, 1997. [18] Craig S. Kaplan, Computer Graphics and Geometric Ornamental Design, Ph.D. Dissertation, University of Washington, 2002. [19] Craig.S.Kaplan, Computer generated Islamic star patterns. Bridges Proceedings, 2000. [20] P.J.Lu, and P.J. Steinhardt, Decagonal and Quasi-Crystalline Tilings in Medieval Islamic Architecture, Science, Vol. 315 no. 5815, pp. 1006-1010, 2007. [21] A.Aljamali, E. Banissi, Grid method classification of Islamic geometric Patterns. Kluwer Academic Publishers, pp.234 œ 254, 2004. [22] M.Valor, F.Albert, J.M. Gomis, M. Contero, Textile and tile pattern Design automatic cataloguing using detection of the plane symmetry group, Computer Graphics International Proceedings, pp. 112-119, 2003. [23] S.T. Wong, H. Leung and Horace H.S. Ip, Model-based analysis of images, Elsevier Science Inc ., Vol. 109, pp.69-85, 2008. [24] X.F. Zhang, Y. Zhuang, J. Q. Wu and F. Wu, Hierarchical approximate matching for retrieval of Chinese historical calligraphy character, Elsevier, Journal of Computer Science and Technology, 22(4): pp. 633-640, 2007. [25] F. Yao, G. Shao and J. Yi, Extracting the trajectory of writing brush in Chinese character calligraphy. Engineering Applications of Artificial Intelligence, Vol. 17, Issue 6, pp. 631-644, 2004.

436