# Fractal Art Pattern Generation Based on Genetic Algorithm

Authors: Huabai Liu
Journal: Advances in Multimedia
 (2022)

---

## Abstract

In order to solve the problem in the application and optimization method of fractal art pattern generation, on the basis of the integration of the fractal theory and genetic algorithm, a generation method based on genetic algorithm and composition generation was proposed. The method provided a more stable and convenient supporting environment for the innovative design of artistic patterns, which met the needs of different users for the design of artistic patterns. The experimental results showed that the simplified genetic programming algorithm was optimized in both individual coding complexity and algorithm complexity. The search space was 1023-1026 times larger than the traditional algorithm, and the evaluation times were 2-3 times larger than the traditional algorithm. The results showed that the method could solve the problem that fitness function could not express well and ensure the optimal genetic population.


---

## Body

## 1. Introduction

With the improving of the people’s living standard, huge changes have taken place in modern people’s consumption idea. More and more attention is paid to the commodity external beauty and modelling embodies artistry when buying a commodity. Some companies are beginning to realize the change of people consumption idea and pay more attention to art and design innovation in the process of production [1]. The artistic design innovation of products is more embodied in the design field of art patterns. The combination of fractal theory and computer graphics design technology can generate more beautiful and complex fractal art patterns with the help of relatively simple iterative formula, which is also more suitable for the aided design of art patterns. For enterprises, they should consider how to use a simple communication interface platform that allows designers who otherwise have little knowledge of fractal theory to modify it with a small number of parameters [2]. Art pattern can satisfy the consumers’ demand, which is generated by using fractal theory of art design. The designers need to consider the problem at the present stage, which is also the focus of the research.


## 2. Literature Review

As a new subject, fractal is still developing. The concept of fractal was first put forward by an American scholar in 1975. Its original meaning was “irregular, fractional, and fragmented”. Fractal is a powerful tool used to describe irregular geometry. The current research on fractal theory is mainly divided into the following three types [3]. The first one is the basic theory of fractal, including the study of fractal dimension (property, dimension, etc.), fractal local structure, and so on. The second one is the practical application of fractal theory. For example, fractal theory is applied in physics, chemistry, biology, seismology, architecture, computer graphics, art design, mathematical modelling, etc [4]. The third one is the fractal graph generation method. Compared with these three types of research studies, there are more researchers in the former two types of problems, and the results are also faster. In particular, remarkable achievements have been made in the application of fractal theory in mathematics, physics, chemistry, computer graphics, and other disciplines. In particular, fractal technology has been successfully applied in some computer games, advertisements, computer animation, covers of books, newspapers, and art works. There are few research studies on the latter kind of problems [5]. And the results are slow, especially in the estimation and essential understanding of fractal set dimension, the in-depth understanding of fractal set structure, and the “derivative” of fractal function, etc. The progress is slow. However, there are constantly new results in the fractal compression, which is put into practical application [6].Fractal graphics have been used in the design of pattern in China’s garment and textile industry, and certain economic benefits have been produced. But, the designers have not yet understood the essence of fractal art graphics [7]. In the stage background design of some large parties, dynamic fractal graphics show the strange, changeable, and unprecedented visual impact. For some industries with high requirements on fractal technology, such as films and 3D games, the application of fractal art graphics has not been applied in a real sense in China. Generally speaking, at present, its development in domestic practical application is still very slow, which still needs a period of time to be applied.On the one hand, the theory and practice is not good mastery. For some aspects involving the application of fractal art, the disadvantage is that the creation way is too single. They are just the fractal graphics directly attached to the 2 d or 3 d objects [8]. And due to a lack of understanding of the fractal, the basic generated fractal graphics law as well as the application of law is rarely considered [9]. At the same time, science education and art education in China are disjointed. Science and art circles have not reached a certain degree of integration. Moreover, the publicity of the fractal theory is not enough, making people see only the fractal abstract side and cannot see the essence. A scale effect is not formed. And the funds and policy support are not enough, so the current fractal art is still not fully popularized, which has not been recognized as a mainstream art. The acceptance of fractal art also is relatively slow. Therefore, as a new theory, fractal art graphics still needs to be further promoted. Wider application fields should be expanded and fractal art should truly infiltrate into our daily life [10].


## 3. Method

### 3.1. Interactive Genetic Programming Algorithm

#### 3.1.1. Coding

Gray code: in order to overcome the deficiency of binary code in discretization of continuous functions, gray code, an improved form of binary code, is proposed. Suppose there is an individual whose binary code is as follows:(1)X=xmxm−1…x2x1.The corresponding gray code is(2)Y=ymym−1…y2y1.The relationship between the two is as follows:(3)ym=xm,yi=xi+1⊕xi,i=m−1,m−2,…,2,1.Gray code not only inherits most advantages of binary coding but also improves the local searching ability of genetic algorithm.Real number coding: when genetic algorithm is used to solve practical problems, the search space is usually relatively large [11]. And the code generated by binary class encoding is very long, which also occupies a lot of memory space, which is not conducive to the implementation of the algorithm.Nonnumerical coding: non-numerical coding refers to a set of symbols in which one or more gene values have only the meaning of pointers indicating other contents but with no specific character meaning. These pointers can be numbers or other characters [12].In Cartesian genetic programming, the encoding of individual chromosomes in a population is a hybrid encoding pattern. The code consists of a series of positive integers. Each gene-meaning unit occupies four bits of code, including two input indexes, one function index, and one parameter, and several output bits at the end of each individual chromosome [13]. This coding pattern identifies the data obtained by nodes, the operations performed by nodes on the data, and the data output by nodes, forming a directional acyclic graph composed of two-dimensional mesh computing nodes.The input and output of chromosomes are as follows:(4)X=x0x1T,Y=y2y7y5T.Output from the first node is(5)x2=input1+input2=x0+x1.The output mode of the last five nodes is the same as that of the first node, as follows:(6)x3=x02,x4=x0x1+x12,x5=x02|p3,x6=x0x1+x12+x02|p3,x7=x0x1+x12+x02.There are 27 digits in the code. Excluding the 24 digits that make up the six complete gene-meaning units, three digits are at the end of the code. These three numbers cannot constitute a complete gene-meaning unit (minus one bit), which represents the output of the code. The 25th number “2” indicates the output, which is as follows [14]:(7)y2=x2=x0+x1.The 26th digit “7” indicates the output, which is as follows:(8)y7=x02+x12+x0x1.The 27th digit “5” indicates the output, which is as follows:(9)y5=x5=x02|p3.Another important part of coding is the selection of a set of functions that can traverse the entire search space quickly without causing too much negative impact on the search [15].


#### 3.1.2. Improvement of Selection Algorithm

In interactive Cartesian genetic programming, the selection algorithm is based on manual fitness evaluation, and excellent individuals have the same fitness. For this special individual fitness assignment, interactive Cartesian genetic programming uses the optimal individual preservation method and simulated anneal-like method.The optimal individual preservation method saves the individuals with the highest fitness in one generation population. That is, the excellent individuals selected in each generation are directly entered into the next generation population without genetic operations such as crossover and mutation. The optimal individual preservation method ensures that the code of each generation of optimal individuals in the population is not damaged by crossover and mutation, and the convergence of the algorithm is guaranteed under the condition of rational users.The simulated annealing method records each generation of optimal individuals selected by users and establishes a dynamic database. With the increase of evolutionary algebra, the selection probability of the optimal individuals of each generation changes dynamically [16]. The specific method is to make the late generation population has a greater selection probability. Considering the noise of artificial selection, we make the selection probability of every generation k equal, so that the probability changes in echelon form and the probability function is used as follows:(10)Fx=x4+1−cosπ/2x2.Suppose the current generationt (counting from generation 0), then the use probability of the optimal individual of generation i is as follows:(11)Ps=Fa+Fb.Among them,(12)a=⌊t−1/k⌋−⌊t−i/k⌋+1⌊t−1/k⌋+1,(13)b=⌊⌊t−1/k⌋⌋−⌊⌊t−i/k⌋⌋⌊t−1/k⌋+1.For example, when the current algebra is generation 7 and generation 14, the usage probability variation trend of each generation is shown in Figures1 and 2.Figure 1
Change trend of probability in generation7.Figure 2
Change trend of probability in generation14.As can be seen from the figures, with the increase of algebra, the selection probability increases in echelon form. And the probability of the last order is much higher than that of the previous ones, which greatly increases the possibility of the algorithm selecting individuals of recent generations [17]. Even if the selection probability of previous generations decreases gradually, the algorithm also provides the possibility for the optimal individuals to enter the crossover and mutation of the latest generation.


#### 3.1.3. Improvement of Crossover Algorithm

Crossover is that the codes of two individuals are swapped with each other in a way that creates two new individuals. It is the main driving force of individual evolution in the process of evolution, which has a great influence on the global search ability of genetic algorithm. The interactive Cartesian genetic programming improves the POX algorithm which is widely used at present [18]. The core idea is to summarize and organize the codes of the parent, screen out the excellent gene sequences, and add these gene sequences to the offspring. The specific method is to scan the coding sequence of the parent individual, compare the functional index bits in each gene-meaning unit in turn, screen out the most used functional index bits, retain the gene-meaning unit where these functional index bits reside, and randomly cross the remaining gene meaning units., as shown in Figure 3.Figure 3
Example of crossover algorithm.The figure shows the crossover process of two individual codes, where the code of individual A is211¯0322¯0231¯1 and the code of individual B is 012¯1001¯0213¯0. And, the crossover result is that the code of offspring A is 211¯0001¯0231¯1 and the code of offspring B is 013¯1322¯0213¯0. After the improvement, the parent individual codes have been fully crossed while retaining the good genes. The offspring can reach a larger search range, which is more conducive to the evolution of individuals. And, the image phenotype is more complex and diverse.


## 3.1. Interactive Genetic Programming Algorithm

### 3.1.1. Coding

Gray code: in order to overcome the deficiency of binary code in discretization of continuous functions, gray code, an improved form of binary code, is proposed. Suppose there is an individual whose binary code is as follows:(1)X=xmxm−1…x2x1.The corresponding gray code is(2)Y=ymym−1…y2y1.The relationship between the two is as follows:(3)ym=xm,yi=xi+1⊕xi,i=m−1,m−2,…,2,1.Gray code not only inherits most advantages of binary coding but also improves the local searching ability of genetic algorithm.Real number coding: when genetic algorithm is used to solve practical problems, the search space is usually relatively large [11]. And the code generated by binary class encoding is very long, which also occupies a lot of memory space, which is not conducive to the implementation of the algorithm.Nonnumerical coding: non-numerical coding refers to a set of symbols in which one or more gene values have only the meaning of pointers indicating other contents but with no specific character meaning. These pointers can be numbers or other characters [12].In Cartesian genetic programming, the encoding of individual chromosomes in a population is a hybrid encoding pattern. The code consists of a series of positive integers. Each gene-meaning unit occupies four bits of code, including two input indexes, one function index, and one parameter, and several output bits at the end of each individual chromosome [13]. This coding pattern identifies the data obtained by nodes, the operations performed by nodes on the data, and the data output by nodes, forming a directional acyclic graph composed of two-dimensional mesh computing nodes.The input and output of chromosomes are as follows:(4)X=x0x1T,Y=y2y7y5T.Output from the first node is(5)x2=input1+input2=x0+x1.The output mode of the last five nodes is the same as that of the first node, as follows:(6)x3=x02,x4=x0x1+x12,x5=x02|p3,x6=x0x1+x12+x02|p3,x7=x0x1+x12+x02.There are 27 digits in the code. Excluding the 24 digits that make up the six complete gene-meaning units, three digits are at the end of the code. These three numbers cannot constitute a complete gene-meaning unit (minus one bit), which represents the output of the code. The 25th number “2” indicates the output, which is as follows [14]:(7)y2=x2=x0+x1.The 26th digit “7” indicates the output, which is as follows:(8)y7=x02+x12+x0x1.The 27th digit “5” indicates the output, which is as follows:(9)y5=x5=x02|p3.Another important part of coding is the selection of a set of functions that can traverse the entire search space quickly without causing too much negative impact on the search [15].


### 3.1.2. Improvement of Selection Algorithm

In interactive Cartesian genetic programming, the selection algorithm is based on manual fitness evaluation, and excellent individuals have the same fitness. For this special individual fitness assignment, interactive Cartesian genetic programming uses the optimal individual preservation method and simulated anneal-like method.The optimal individual preservation method saves the individuals with the highest fitness in one generation population. That is, the excellent individuals selected in each generation are directly entered into the next generation population without genetic operations such as crossover and mutation. The optimal individual preservation method ensures that the code of each generation of optimal individuals in the population is not damaged by crossover and mutation, and the convergence of the algorithm is guaranteed under the condition of rational users.The simulated annealing method records each generation of optimal individuals selected by users and establishes a dynamic database. With the increase of evolutionary algebra, the selection probability of the optimal individuals of each generation changes dynamically [16]. The specific method is to make the late generation population has a greater selection probability. Considering the noise of artificial selection, we make the selection probability of every generation k equal, so that the probability changes in echelon form and the probability function is used as follows:(10)Fx=x4+1−cosπ/2x2.Suppose the current generationt (counting from generation 0), then the use probability of the optimal individual of generation i is as follows:(11)Ps=Fa+Fb.Among them,(12)a=⌊t−1/k⌋−⌊t−i/k⌋+1⌊t−1/k⌋+1,(13)b=⌊⌊t−1/k⌋⌋−⌊⌊t−i/k⌋⌋⌊t−1/k⌋+1.For example, when the current algebra is generation 7 and generation 14, the usage probability variation trend of each generation is shown in Figures1 and 2.Figure 1
Change trend of probability in generation7.Figure 2
Change trend of probability in generation14.As can be seen from the figures, with the increase of algebra, the selection probability increases in echelon form. And the probability of the last order is much higher than that of the previous ones, which greatly increases the possibility of the algorithm selecting individuals of recent generations [17]. Even if the selection probability of previous generations decreases gradually, the algorithm also provides the possibility for the optimal individuals to enter the crossover and mutation of the latest generation.


### 3.1.3. Improvement of Crossover Algorithm

Crossover is that the codes of two individuals are swapped with each other in a way that creates two new individuals. It is the main driving force of individual evolution in the process of evolution, which has a great influence on the global search ability of genetic algorithm. The interactive Cartesian genetic programming improves the POX algorithm which is widely used at present [18]. The core idea is to summarize and organize the codes of the parent, screen out the excellent gene sequences, and add these gene sequences to the offspring. The specific method is to scan the coding sequence of the parent individual, compare the functional index bits in each gene-meaning unit in turn, screen out the most used functional index bits, retain the gene-meaning unit where these functional index bits reside, and randomly cross the remaining gene meaning units., as shown in Figure 3.Figure 3
Example of crossover algorithm.The figure shows the crossover process of two individual codes, where the code of individual A is211¯0322¯0231¯1 and the code of individual B is 012¯1001¯0213¯0. And, the crossover result is that the code of offspring A is 211¯0001¯0231¯1 and the code of offspring B is 013¯1322¯0213¯0. After the improvement, the parent individual codes have been fully crossed while retaining the good genes. The offspring can reach a larger search range, which is more conducive to the evolution of individuals. And, the image phenotype is more complex and diverse.


## 3.1.1. Coding

Gray code: in order to overcome the deficiency of binary code in discretization of continuous functions, gray code, an improved form of binary code, is proposed. Suppose there is an individual whose binary code is as follows:(1)X=xmxm−1…x2x1.The corresponding gray code is(2)Y=ymym−1…y2y1.The relationship between the two is as follows:(3)ym=xm,yi=xi+1⊕xi,i=m−1,m−2,…,2,1.Gray code not only inherits most advantages of binary coding but also improves the local searching ability of genetic algorithm.Real number coding: when genetic algorithm is used to solve practical problems, the search space is usually relatively large [11]. And the code generated by binary class encoding is very long, which also occupies a lot of memory space, which is not conducive to the implementation of the algorithm.Nonnumerical coding: non-numerical coding refers to a set of symbols in which one or more gene values have only the meaning of pointers indicating other contents but with no specific character meaning. These pointers can be numbers or other characters [12].In Cartesian genetic programming, the encoding of individual chromosomes in a population is a hybrid encoding pattern. The code consists of a series of positive integers. Each gene-meaning unit occupies four bits of code, including two input indexes, one function index, and one parameter, and several output bits at the end of each individual chromosome [13]. This coding pattern identifies the data obtained by nodes, the operations performed by nodes on the data, and the data output by nodes, forming a directional acyclic graph composed of two-dimensional mesh computing nodes.The input and output of chromosomes are as follows:(4)X=x0x1T,Y=y2y7y5T.Output from the first node is(5)x2=input1+input2=x0+x1.The output mode of the last five nodes is the same as that of the first node, as follows:(6)x3=x02,x4=x0x1+x12,x5=x02|p3,x6=x0x1+x12+x02|p3,x7=x0x1+x12+x02.There are 27 digits in the code. Excluding the 24 digits that make up the six complete gene-meaning units, three digits are at the end of the code. These three numbers cannot constitute a complete gene-meaning unit (minus one bit), which represents the output of the code. The 25th number “2” indicates the output, which is as follows [14]:(7)y2=x2=x0+x1.The 26th digit “7” indicates the output, which is as follows:(8)y7=x02+x12+x0x1.The 27th digit “5” indicates the output, which is as follows:(9)y5=x5=x02|p3.Another important part of coding is the selection of a set of functions that can traverse the entire search space quickly without causing too much negative impact on the search [15].


## 3.1.2. Improvement of Selection Algorithm

In interactive Cartesian genetic programming, the selection algorithm is based on manual fitness evaluation, and excellent individuals have the same fitness. For this special individual fitness assignment, interactive Cartesian genetic programming uses the optimal individual preservation method and simulated anneal-like method.The optimal individual preservation method saves the individuals with the highest fitness in one generation population. That is, the excellent individuals selected in each generation are directly entered into the next generation population without genetic operations such as crossover and mutation. The optimal individual preservation method ensures that the code of each generation of optimal individuals in the population is not damaged by crossover and mutation, and the convergence of the algorithm is guaranteed under the condition of rational users.The simulated annealing method records each generation of optimal individuals selected by users and establishes a dynamic database. With the increase of evolutionary algebra, the selection probability of the optimal individuals of each generation changes dynamically [16]. The specific method is to make the late generation population has a greater selection probability. Considering the noise of artificial selection, we make the selection probability of every generation k equal, so that the probability changes in echelon form and the probability function is used as follows:(10)Fx=x4+1−cosπ/2x2.Suppose the current generationt (counting from generation 0), then the use probability of the optimal individual of generation i is as follows:(11)Ps=Fa+Fb.Among them,(12)a=⌊t−1/k⌋−⌊t−i/k⌋+1⌊t−1/k⌋+1,(13)b=⌊⌊t−1/k⌋⌋−⌊⌊t−i/k⌋⌋⌊t−1/k⌋+1.For example, when the current algebra is generation 7 and generation 14, the usage probability variation trend of each generation is shown in Figures1 and 2.Figure 1
Change trend of probability in generation7.Figure 2
Change trend of probability in generation14.As can be seen from the figures, with the increase of algebra, the selection probability increases in echelon form. And the probability of the last order is much higher than that of the previous ones, which greatly increases the possibility of the algorithm selecting individuals of recent generations [17]. Even if the selection probability of previous generations decreases gradually, the algorithm also provides the possibility for the optimal individuals to enter the crossover and mutation of the latest generation.


## 3.1.3. Improvement of Crossover Algorithm

Crossover is that the codes of two individuals are swapped with each other in a way that creates two new individuals. It is the main driving force of individual evolution in the process of evolution, which has a great influence on the global search ability of genetic algorithm. The interactive Cartesian genetic programming improves the POX algorithm which is widely used at present [18]. The core idea is to summarize and organize the codes of the parent, screen out the excellent gene sequences, and add these gene sequences to the offspring. The specific method is to scan the coding sequence of the parent individual, compare the functional index bits in each gene-meaning unit in turn, screen out the most used functional index bits, retain the gene-meaning unit where these functional index bits reside, and randomly cross the remaining gene meaning units., as shown in Figure 3.Figure 3
Example of crossover algorithm.The figure shows the crossover process of two individual codes, where the code of individual A is211¯0322¯0231¯1 and the code of individual B is 012¯1001¯0213¯0. And, the crossover result is that the code of offspring A is 211¯0001¯0231¯1 and the code of offspring B is 013¯1322¯0213¯0. After the improvement, the parent individual codes have been fully crossed while retaining the good genes. The offspring can reach a larger search range, which is more conducive to the evolution of individuals. And, the image phenotype is more complex and diverse.


## 4. Experiment Results and Analysis

In order to verify the effectiveness of the algorithm, an interactive Descartes genetic programming image generation system was designed in genetic Java language. The system parameters were set as follows:k = 3 in the selection algorithm, that was, the selection probability of every three generations was equal. The initial variation number of individual code was N0=15 in the mutation algorithm, and the individual variation threshold was σ=5 in the mutation process [19]. The number of individuals in each generation was 15. The maximum evolution algebra was set as 500 generations (generally speaking, the evolution algebra of ICGP is 10 ∼ 100, and the maximum generation terminated by the system design is 500 generations). The improved algorithm ERGA, which strengthened the proposed interactive genetic algorithm, was compared with the interactive Cartesian genetic programming in order to illustrate its evolutionary efficiency. This was because the search space of the ERGA algorithm 224≈1.6×107 was much smaller than 2.2×1033 of normal interactive Cartesian genetic programming. In order to make an effective comparison, the interactive Cartesian genetic programming algorithm was simplified. The initial number of variation of parameter coding variation was adjusted to N0=3. The upper limit of variation was set to 7 and chromosome length to 15. The search space was narrowed to 1×1010.Table1 reflects the evolution algebra used when users achieved satisfactory results under different algorithms. The results showed that the search space of the simplified interactive Cartesian genetic algorithm was much larger than that of the ERGA algorithm, while the average search algebra increased slightly. The search space of normal interactive Cartesian genetic programming was 1023 ∼ 1026 times larger than that of the first two algorithms, and the evaluation times used were only 2 ∼ 3 times larger than those of the two algorithms. The experimental results showed that interactive Cartesian genetic programming was feasible and efficient, which could help people find satisfactory images [20].Table 1
Comparison of algorithm evaluation times.
AlgorithmGroup 1Group2Group3Group4MeanICGP (simplified)2329282626.5ERGA2115282422ICGP (normal)6272678170.5


### 4.1. Process

Genetic Algorithm (GA) in computer science was applied to fractal art design in the research. The application of GA in fractal pattern generation of generalized M-J sets was discussed. On the basis of Genetic Algorithm, human-computer interaction process was added and user preference was integrated into the genetic process. In this way, fractal art works that were easier to satisfy users or more “personalized” were evolved, so that fractal patterns could match the needs of users better and faster [21]. The iterative functions that generated fractal patterns of generalized M-j sets were considered as individuals in the genetic algorithm population and their iterative functions were encoded. The application of binary tree structure to represent mathematical expression had great flexibility. Therefore, the structural formula coding method was used here to express the solution of the problem in the form of binary trees, and each tree was a chromosome.The fitness function in genetic operation was the basis to evaluate the merits and demerits of genetically evolved chromosome individuals. Here, the “satisfaction degree” and “consensus degree” of users to design works were used as the index to measure the quality of genetic chromosomes [22]. Taking Table 2 as an example, although both design work A and design work B had a common score of 14, work B did not show the attitude of “dissatisfaction” and had a high degree of consistency in evaluation. Therefore, it was more in line with the actual needs of users.Table 2
Users’ scoring of works.
Design art patternUsers scoringGroup common scoringA1 3 3 2 3 214B2 2 3 2 3 214C1 1 3 2 1 210D1 1 1 2 1 28E3 3 3 2 3 115F1 3 1 2 2 211Set the sequence of user evaluation scores as follows:(14)Vii=1,2,…,n.Then,(15)Vmax=Vj;Vj≥Vi,i=1,2,…,n,Vmin=Vk;Vk≤Vi,i=1,2,…,n.Thus, the normalized value was obtained through [0,1].(16)SVi=Vi−VminVmax−Vmin.Set the consensus degree asT and calculate the consensus degree by standard deviation.(17)T=1−∑i−1nVi−V¯2n.The satisfaction degree is as follows:(18)S¯Vi=∑i=1nSVin.In formula (19), V¯ is the average value of all user evaluation results. i and n are positive integers, and 1 ≤ i ≤ n.Assuming that the proportion of consensus degreeT and satisfaction S¯Vi to the adaptive value were u and v(u + v = 1). Consensus satisfaction, as a fitness function, was as follows:(19)fitness=uS¯Vi+vT.In traditional genetic algorithms, fitness was determined by fitness function. But, each user’s subjective evaluation was different. Therefore, it was impossible to have objective fitness function, so the fitness value adopted in the research should be reflected by user scoring. This way of extracting “satisfaction degree” and “consensus degree” from users to get the adaptive value through user scoring was a full embodiment of the interactive thought [23]:(1)
Initialize the population, which randomly generates valid mathematical expressions in the set of operators and operands as iterative functions to generate fractal patterns. The expression string is represented as a binary tree by structural encoding.(2)
Get the fitness value of the middle chromosome of the initial population through interaction with the user. Users can evaluate the chromosomes in the population to modify their fitness value, so as to carry out genetic selection of the next generation.(3)
Generate new populations according to the fitness of chromosomes.(4)
Cross and mutate the population.(5)
After several rounds of evaluation and elimination, if there is a satisfactory result of the user, it will end; otherwise, it will go to 2.


### 4.2. Case Analysis

The escape radius algorithm of generalized M-J set and the escape time algorithm of Newton iterative method were taken as examples to illustrate the application of genetic algorithm in fractal pattern generation of complex dynamical systems.First assuming that the set of operands given was as follows:(20)Az,z2,z3,z4,z−1,z−2,z−3,z−4,ez,sinz,cosz,tanz,atgz,a.In the formula,(21)z=x+yi.The initial population consisted of multiple binary trees constructed from randomly selected elements in the set of operands and the set of operators. The steps to build a binary tree were as follows. Multiple elements randomly from the set of operators were selected as the intermediate nodes, and multiple elements randomly from the set of operands were selected as the final nodes of the binary tree. Each binary tree represented an iterative function. For example, we selected three spanning trees from the initial population generated according to sets A and B: Tree A, Tree B, and Tree C, as shown in Figures4–6.Figure 4
Tree A3z2−2z−2+sinz∗cos−2.Figure 5
Tree Bz−4/z4−ctgz−1.Figure 6
Tree C2z−4/z4−2sinz∗tanz−cosz.100 users were asked to score and evaluate the patterns generated by the iterative function. The consensus degree of users was calculated by the formula. The satisfaction degree of users was calculated by the formula, and finally, the adaptive value of each fractal design pattern was calculated by formula. Good chromosomes were selected according to fitness values to produce the next generation[24]. The selected chromosomes were crossed and mutated to form individuals in a new population. So here, we crossed Tree A with Tree B. The “-” node of the left subtree of Tree A and the “/” node of the left subtree of Tree B were randomly selected as the intersection points. The swapped portion was a subtree rooted at the intersection. The new individuals generated after crossing were Tree D and Tree E, as shown in Figures 7 and 8.Figure 7
Tree D3z2−2z−2−ctgz−1.Figure 8
Tree Ez−4/z4+sinz∗cosz.After the above steps, if the user is satisfied with the art design work, stop the operation; otherwise, return to continue the genetic operation. Through the above examples, it can be seen that the idea of genetic algorithm is applied to generate fractal art patterns, which automatically generates new patterns and retains the pattern elements that users are interested in for inheritance, so as to help designers quickly design fractal art patterns that users can appreciate.


### 4.3. Generation Method of Fractal Pattern Based on the LS Grammar Composition Method of Genetic Algorithm

In LS grammar composition method, the generation rule P is the core of the generative component pattern, also known as fractal element. Therefore, how to find the rules for generating fractal patterns with high artistic value and timely and accurately capture user preferences is the primary problem for every designer to solve. In this part, the idea of genetic algorithm into the generation process of fractal patterns was introduced, selecting those fractal patterns with good elements and applying genetic algorithm to conduct genetic manipulation on the generation rules of these patterns, which produced the next generation with good rules. So, the purpose of making the generated fractal art pattern closer to the user’s demand faster and better was achieved.When using LS grammar composition method for encoding, for LS grammar with single rule, chromosomes in the population are composed of axioms (initial symbols) by rewriting mechanism. That is to say, chromosomes are the successor of production rule because the precursor is always axioms (such as F). We do not need to store it. For example, the rule P: F⟶F [+F]F[--F]F, whose encoding is F[+F]F[--F]F. However, for the generation formula of multirule LS grammar, its precursor may be different characters, such asG, K, and F. So, its precursor is also stored in the encoding, and the encoding of rule P is FF[+F]F[--F]F. And, we take the first character as the precursor character in the decoding [25]. In order to enrich the rules of production, we can adopt the encoding method of variable length chromosome genetic algorithm. The selection of crossover probability and mutation probability directly affects the convergence of genetic algorithm, which is also the key to affect the performance of genetic algorithm. According to the pattern theorem, patterns with low order, short definition distance, and higher average fitness than population increase exponentially in offspring. In the early stage of the algorithm, the pattern was focused on the individuals with low fitness. If the crossover rate and mutation rate were too small, it was difficult for the population to produce excellent new individuals. In the later stage of the algorithm, the pattern began to concentrate on individuals with high fitness. If the crossover rate and mutation rate were large, the good pattern was easily destroyed and the algorithm fell into local convergence.Here, we can learn from the adaptive genetic algorithm. It can determine the individual crossover probability and mutation probability by the dynamic fitness function. Among them, crossover probability and mutation probability are adaptively changed based on individual fitness value. For individuals whose fitness is lower than the average population fitness, this solution can be eliminated by increasing crossover probability and mutation probability. For individuals with high adaptive values, the solution can be protected automatically into the next generation by making them correspond to small crossover probability and mutation probability, so as to ensure the excellence of individuals. When the fitness of each individual tends to be the same or local optimal, the crossover probability and mutation probability should be increased. The crossover probability and mutation probability should be reduced when the individual adaptive function of the population is dispersed. Therefore, the adaptive crossover probability and mutation probability can provide the best crossover probability and mutation probability relative to a certain solution. The convergence of genetic algorithm is guaranteed while the diversity of population is maintained.The algorithm flow is as follows:(1)
Initialize the group using the “turtle diagram method” in LS grammar composition to construct the initial group. The rules of graph generation are encoded by variable length chromosome.(2)
Get the fitness value of mid-chromosome individuals of the initial population through interaction with users. Users can evaluate chromosome individuals in the population to modify their fitness values, so as to carry out genetic selection of the next generation.(3)
Make adaptive adjustment of genetic parameters and generate new populations according to the fitness of chromosomes.(4)
Cross and mutate the population.(5)
After several rounds of evaluation and elimination, if there is a satisfactory result of the user, it will end; otherwise, it will go to 2.The powerful application development function of Visualc + + 6.0 and graphing function were made full use of in the research. At the same time, by using fractal theory, computer graphics, and the related knowledge of the genetic algorithm, based on genetic algorithm, the fractal graph generation method was realized with computer language, so as to complete the fractal pattern drawing program codes. The program design structure is shown in Figure 9.Figure 9
Programming architecture diagram.A drawing method can be selected from the draw fractal drop-down menu on the main interface. After selecting the drawing method, enter the drawing parameter setting interface. After selecting the drawing method and setting the parameters, we can draw the fractal pattern and evaluate it by the user, and then calculate the adaptive value of the pattern. In the following example, we use generalized M-J set plotting. By drawing fractal patterns for many times and scoring and evaluating them, the initial population for our genetic operation can be generated. If the user is satisfied with the pattern in the population, the user can click “Save pattern” button to save the generated fractal pattern. If the user is not satisfied with the fractal pattern, the user can click the genetic operation button. And, the system will conduct the corresponding genetic operation according to the fitness value of the fractal graph to generate the second-generation population.The design of the client mainly focuses on the requirements of reading images, generating new populations, selecting/deselecting individuals, evolving, and saving images. The user case diagram of the client is shown in Figure10.Figure 10
User case diagram of the client.The picture reading function is mainly aimed at the “semifinished” images that users have saved before using the software this time. Through the picture reading function, users can continue the last unfinished evolution process, so that users do not have to give up a certain evolution process due to subjective fatigue or objective reasons. The use case rules for reading pictures are shown in Table2.Creating a new population requires that a new population be created automatically after the user enters the system, or after the user clicks the new population button. Users can initiate or reset the evolution process by generating new populations. The use case rules for generating new populations are shown in Table3.Table 3
Use case rules for generating new populations.
RoleCGP Designer system userPreconditionEnter the system interface and click the new population buttonPostconditionGenerate new populationBasic event flowParticipant actionSystem response1. The user enters the system interface1. The selected individual is retained, and the other individuals perform the new population generation operation2. The user clicks the new population buttonSelecting individuals requires users to select individuals with high selfevaluation after entering the system or during the evolution process. In this way, it facilitates the subsequent evolution and makes the evolution process more targeted. When using the function of generating new populations, individuals with high user evaluation will not be reset. At the same time, the function of selecting individuals can also help to save pictures. Selecting individual functions is an important function in the interaction interface with users. The use case rules for selecting individual are shown in Table4.Table 4
Use case rules for selecting individual.
User case nameSelecting individualRoleCGP Designer system userPreconditionEnter the system interfacePostconditionIndividual is selected, and box appears outside the selected individual.Basic event flowParticipant actionSystem response1. The user clicks on an individual in the population1. The clicked individual is selected2. A box appears outside the selected individualThe system will automatically generate a new population after the user starts the application. Or, the system will generate a new population after the user clicks the new population button. When a new population needs to be created, the system will automatically randomly select the chromosomes of the good individuals from the good gene pool and display them in the middle display area. Selecting individuals is an important step in the process of user interaction with the system. Users need to select individuals for evolution, preservation, and other interactive operations. When the user clicks on a picture, the system will judge the position of the mouse and compare it with the coordinates of each picture to find out which picture is clicked, and then draw a blue box around the picture according to the position of the clicked picture. See Figure11 for the specific process.Figure 11
Selecting individual module workflow.When the user has evolved a good image, or the user cannot continue to evolve the image for some reason, the current good individual needs to be preserved. The user needs to click the save picture option in the file menu, enter the file name to save in the dialog box that pops up, select the save path, and click OK. The system saves the selected image as a JPG or JPEG file.


## 4.1. Process

Genetic Algorithm (GA) in computer science was applied to fractal art design in the research. The application of GA in fractal pattern generation of generalized M-J sets was discussed. On the basis of Genetic Algorithm, human-computer interaction process was added and user preference was integrated into the genetic process. In this way, fractal art works that were easier to satisfy users or more “personalized” were evolved, so that fractal patterns could match the needs of users better and faster [21]. The iterative functions that generated fractal patterns of generalized M-j sets were considered as individuals in the genetic algorithm population and their iterative functions were encoded. The application of binary tree structure to represent mathematical expression had great flexibility. Therefore, the structural formula coding method was used here to express the solution of the problem in the form of binary trees, and each tree was a chromosome.The fitness function in genetic operation was the basis to evaluate the merits and demerits of genetically evolved chromosome individuals. Here, the “satisfaction degree” and “consensus degree” of users to design works were used as the index to measure the quality of genetic chromosomes [22]. Taking Table 2 as an example, although both design work A and design work B had a common score of 14, work B did not show the attitude of “dissatisfaction” and had a high degree of consistency in evaluation. Therefore, it was more in line with the actual needs of users.Table 2
Users’ scoring of works.
Design art patternUsers scoringGroup common scoringA1 3 3 2 3 214B2 2 3 2 3 214C1 1 3 2 1 210D1 1 1 2 1 28E3 3 3 2 3 115F1 3 1 2 2 211Set the sequence of user evaluation scores as follows:(14)Vii=1,2,…,n.Then,(15)Vmax=Vj;Vj≥Vi,i=1,2,…,n,Vmin=Vk;Vk≤Vi,i=1,2,…,n.Thus, the normalized value was obtained through [0,1].(16)SVi=Vi−VminVmax−Vmin.Set the consensus degree asT and calculate the consensus degree by standard deviation.(17)T=1−∑i−1nVi−V¯2n.The satisfaction degree is as follows:(18)S¯Vi=∑i=1nSVin.In formula (19), V¯ is the average value of all user evaluation results. i and n are positive integers, and 1 ≤ i ≤ n.Assuming that the proportion of consensus degreeT and satisfaction S¯Vi to the adaptive value were u and v(u + v = 1). Consensus satisfaction, as a fitness function, was as follows:(19)fitness=uS¯Vi+vT.In traditional genetic algorithms, fitness was determined by fitness function. But, each user’s subjective evaluation was different. Therefore, it was impossible to have objective fitness function, so the fitness value adopted in the research should be reflected by user scoring. This way of extracting “satisfaction degree” and “consensus degree” from users to get the adaptive value through user scoring was a full embodiment of the interactive thought [23]:(1)
Initialize the population, which randomly generates valid mathematical expressions in the set of operators and operands as iterative functions to generate fractal patterns. The expression string is represented as a binary tree by structural encoding.(2)
Get the fitness value of the middle chromosome of the initial population through interaction with the user. Users can evaluate the chromosomes in the population to modify their fitness value, so as to carry out genetic selection of the next generation.(3)
Generate new populations according to the fitness of chromosomes.(4)
Cross and mutate the population.(5)
After several rounds of evaluation and elimination, if there is a satisfactory result of the user, it will end; otherwise, it will go to 2.


## 4.2. Case Analysis

The escape radius algorithm of generalized M-J set and the escape time algorithm of Newton iterative method were taken as examples to illustrate the application of genetic algorithm in fractal pattern generation of complex dynamical systems.First assuming that the set of operands given was as follows:(20)Az,z2,z3,z4,z−1,z−2,z−3,z−4,ez,sinz,cosz,tanz,atgz,a.In the formula,(21)z=x+yi.The initial population consisted of multiple binary trees constructed from randomly selected elements in the set of operands and the set of operators. The steps to build a binary tree were as follows. Multiple elements randomly from the set of operators were selected as the intermediate nodes, and multiple elements randomly from the set of operands were selected as the final nodes of the binary tree. Each binary tree represented an iterative function. For example, we selected three spanning trees from the initial population generated according to sets A and B: Tree A, Tree B, and Tree C, as shown in Figures4–6.Figure 4
Tree A3z2−2z−2+sinz∗cos−2.Figure 5
Tree Bz−4/z4−ctgz−1.Figure 6
Tree C2z−4/z4−2sinz∗tanz−cosz.100 users were asked to score and evaluate the patterns generated by the iterative function. The consensus degree of users was calculated by the formula. The satisfaction degree of users was calculated by the formula, and finally, the adaptive value of each fractal design pattern was calculated by formula. Good chromosomes were selected according to fitness values to produce the next generation[24]. The selected chromosomes were crossed and mutated to form individuals in a new population. So here, we crossed Tree A with Tree B. The “-” node of the left subtree of Tree A and the “/” node of the left subtree of Tree B were randomly selected as the intersection points. The swapped portion was a subtree rooted at the intersection. The new individuals generated after crossing were Tree D and Tree E, as shown in Figures 7 and 8.Figure 7
Tree D3z2−2z−2−ctgz−1.Figure 8
Tree Ez−4/z4+sinz∗cosz.After the above steps, if the user is satisfied with the art design work, stop the operation; otherwise, return to continue the genetic operation. Through the above examples, it can be seen that the idea of genetic algorithm is applied to generate fractal art patterns, which automatically generates new patterns and retains the pattern elements that users are interested in for inheritance, so as to help designers quickly design fractal art patterns that users can appreciate.


## 4.3. Generation Method of Fractal Pattern Based on the LS Grammar Composition Method of Genetic Algorithm

In LS grammar composition method, the generation rule P is the core of the generative component pattern, also known as fractal element. Therefore, how to find the rules for generating fractal patterns with high artistic value and timely and accurately capture user preferences is the primary problem for every designer to solve. In this part, the idea of genetic algorithm into the generation process of fractal patterns was introduced, selecting those fractal patterns with good elements and applying genetic algorithm to conduct genetic manipulation on the generation rules of these patterns, which produced the next generation with good rules. So, the purpose of making the generated fractal art pattern closer to the user’s demand faster and better was achieved.When using LS grammar composition method for encoding, for LS grammar with single rule, chromosomes in the population are composed of axioms (initial symbols) by rewriting mechanism. That is to say, chromosomes are the successor of production rule because the precursor is always axioms (such as F). We do not need to store it. For example, the rule P: F⟶F [+F]F[--F]F, whose encoding is F[+F]F[--F]F. However, for the generation formula of multirule LS grammar, its precursor may be different characters, such asG, K, and F. So, its precursor is also stored in the encoding, and the encoding of rule P is FF[+F]F[--F]F. And, we take the first character as the precursor character in the decoding [25]. In order to enrich the rules of production, we can adopt the encoding method of variable length chromosome genetic algorithm. The selection of crossover probability and mutation probability directly affects the convergence of genetic algorithm, which is also the key to affect the performance of genetic algorithm. According to the pattern theorem, patterns with low order, short definition distance, and higher average fitness than population increase exponentially in offspring. In the early stage of the algorithm, the pattern was focused on the individuals with low fitness. If the crossover rate and mutation rate were too small, it was difficult for the population to produce excellent new individuals. In the later stage of the algorithm, the pattern began to concentrate on individuals with high fitness. If the crossover rate and mutation rate were large, the good pattern was easily destroyed and the algorithm fell into local convergence.Here, we can learn from the adaptive genetic algorithm. It can determine the individual crossover probability and mutation probability by the dynamic fitness function. Among them, crossover probability and mutation probability are adaptively changed based on individual fitness value. For individuals whose fitness is lower than the average population fitness, this solution can be eliminated by increasing crossover probability and mutation probability. For individuals with high adaptive values, the solution can be protected automatically into the next generation by making them correspond to small crossover probability and mutation probability, so as to ensure the excellence of individuals. When the fitness of each individual tends to be the same or local optimal, the crossover probability and mutation probability should be increased. The crossover probability and mutation probability should be reduced when the individual adaptive function of the population is dispersed. Therefore, the adaptive crossover probability and mutation probability can provide the best crossover probability and mutation probability relative to a certain solution. The convergence of genetic algorithm is guaranteed while the diversity of population is maintained.The algorithm flow is as follows:(1)
Initialize the group using the “turtle diagram method” in LS grammar composition to construct the initial group. The rules of graph generation are encoded by variable length chromosome.(2)
Get the fitness value of mid-chromosome individuals of the initial population through interaction with users. Users can evaluate chromosome individuals in the population to modify their fitness values, so as to carry out genetic selection of the next generation.(3)
Make adaptive adjustment of genetic parameters and generate new populations according to the fitness of chromosomes.(4)
Cross and mutate the population.(5)
After several rounds of evaluation and elimination, if there is a satisfactory result of the user, it will end; otherwise, it will go to 2.The powerful application development function of Visualc + + 6.0 and graphing function were made full use of in the research. At the same time, by using fractal theory, computer graphics, and the related knowledge of the genetic algorithm, based on genetic algorithm, the fractal graph generation method was realized with computer language, so as to complete the fractal pattern drawing program codes. The program design structure is shown in Figure 9.Figure 9
Programming architecture diagram.A drawing method can be selected from the draw fractal drop-down menu on the main interface. After selecting the drawing method, enter the drawing parameter setting interface. After selecting the drawing method and setting the parameters, we can draw the fractal pattern and evaluate it by the user, and then calculate the adaptive value of the pattern. In the following example, we use generalized M-J set plotting. By drawing fractal patterns for many times and scoring and evaluating them, the initial population for our genetic operation can be generated. If the user is satisfied with the pattern in the population, the user can click “Save pattern” button to save the generated fractal pattern. If the user is not satisfied with the fractal pattern, the user can click the genetic operation button. And, the system will conduct the corresponding genetic operation according to the fitness value of the fractal graph to generate the second-generation population.The design of the client mainly focuses on the requirements of reading images, generating new populations, selecting/deselecting individuals, evolving, and saving images. The user case diagram of the client is shown in Figure10.Figure 10
User case diagram of the client.The picture reading function is mainly aimed at the “semifinished” images that users have saved before using the software this time. Through the picture reading function, users can continue the last unfinished evolution process, so that users do not have to give up a certain evolution process due to subjective fatigue or objective reasons. The use case rules for reading pictures are shown in Table2.Creating a new population requires that a new population be created automatically after the user enters the system, or after the user clicks the new population button. Users can initiate or reset the evolution process by generating new populations. The use case rules for generating new populations are shown in Table3.Table 3
Use case rules for generating new populations.
RoleCGP Designer system userPreconditionEnter the system interface and click the new population buttonPostconditionGenerate new populationBasic event flowParticipant actionSystem response1. The user enters the system interface1. The selected individual is retained, and the other individuals perform the new population generation operation2. The user clicks the new population buttonSelecting individuals requires users to select individuals with high selfevaluation after entering the system or during the evolution process. In this way, it facilitates the subsequent evolution and makes the evolution process more targeted. When using the function of generating new populations, individuals with high user evaluation will not be reset. At the same time, the function of selecting individuals can also help to save pictures. Selecting individual functions is an important function in the interaction interface with users. The use case rules for selecting individual are shown in Table4.Table 4
Use case rules for selecting individual.
User case nameSelecting individualRoleCGP Designer system userPreconditionEnter the system interfacePostconditionIndividual is selected, and box appears outside the selected individual.Basic event flowParticipant actionSystem response1. The user clicks on an individual in the population1. The clicked individual is selected2. A box appears outside the selected individualThe system will automatically generate a new population after the user starts the application. Or, the system will generate a new population after the user clicks the new population button. When a new population needs to be created, the system will automatically randomly select the chromosomes of the good individuals from the good gene pool and display them in the middle display area. Selecting individuals is an important step in the process of user interaction with the system. Users need to select individuals for evolution, preservation, and other interactive operations. When the user clicks on a picture, the system will judge the position of the mouse and compare it with the coordinates of each picture to find out which picture is clicked, and then draw a blue box around the picture according to the position of the clicked picture. See Figure11 for the specific process.Figure 11
Selecting individual module workflow.When the user has evolved a good image, or the user cannot continue to evolve the image for some reason, the current good individual needs to be preserved. The user needs to click the save picture option in the file menu, enter the file name to save in the dialog box that pops up, select the save path, and click OK. The system saves the selected image as a JPG or JPEG file.


## 5. Conclusion

In the research, fractal theory, Genetic Algorithm theory and fractal pattern generation method were mainly investigated. On the basis, the generation method of fractal art pattern based on Genetic Algorithm was proposed, which applied Genetic Algorithm (GA) in computer science to fractal art design field. It not only broadened the design ideas of designers but also made fractal art works better and faster to meet the design needs of different users. Combining fractal theory and genetic algorithm, the generalized M-J set generation method and LS grammar graph generation method based on genetic algorithm were proposed on the basis of complex dynamical system generation method and grammar structure generation method. Based on genetic algorithm, a fractal pattern drawing system based on genetic algorithm was designed by combining human-computer interaction technology and learning mechanism. The purpose of the design was achieved, and fractal graph parametric design was realized. At the same time, the introduction of genetic algorithm effectively helped users to quickly find the fractal art pattern that met the design requirements.



---

*Source: 8926488-2022-08-30.xml*