Study on the Generation of Fractal Image and Animation Based on MATLAB and Flash Platform

In practice, the content of fractal graph generated by one kind of algorithm alone is relatively toneless. Combining different algorithms can not only break the limitation of single fractal object generation but also enrich the contents of scenes. In this paper, according to the needs of scene construction, more targeted algorithms are appropriately chosen. By combing two fractal algorithms of recursion and Iterator Function System (IFS for short), two static scenarios “Old Tree, Withered Grass and Snowy Night” and “Reed Land and Snowy Night” are built on MATLAB platform, which further enriches contents of the scene. Simultaneously, a trial has been made to experiment the generation of dynamic fractal graphs. Based on the fractal algorithm with parameters, a recursive windmill animation and a lunar eclipse animation based on recursion and IFS algorithm are generated on MATLAB platform, which enhances the creativity of the scene building of fractal animation. With respect to the selection of implementation platform, this paper compares the effects of fractal graph generation between MATLAB and Flash. The results show that, thanks to its powerful animation creation ability, Flash is undoubtedly more valuable than MATLAB in the implementation of relatively simple fractal animation effect in the light of speed and convenience. Nevertheless, in order to achieve richer and more realistic animation effects, the more powerful MATLAB platform is preferred. In general, it is necessary to choose the right platform according to actual requirements of creation so as to improve the development efficiency.


Introduction
As Mandelbrot [1] notes, fractal is the geometry of nature. Fractal is a new-type subject that has been developed in recent 30 years, and this word is translated from the English vocabulary "fractal", which means irregular, broken and numeral. In 1975 and 1982, a French mathematician of American nationality Benoit Mandelbrot, the creator of Fractal Theory, published two historical works: Los objetos fractales: forma, azar y dimensión and the Fractal Geometry of Nature. Since then, the fractal theory has taken shape.
The fractal theory is a strong theoretical tool for studying irregular objects in the natural world and engineering application. Overall, the fractal object has an uneven and irregular shape and such irregularity also coexists with regularity because of its self-similarity. With the development of this theory, the geometric characteristics of fractal object has no longer been limited to its self-similarity. Objects with self-affine transformation relationship between the whole and the part are also called as fractal. In general, the fractal object is featured by irregularity, self-similarity, self-affinity, selfaffinity and smart structure [2]. The fractal image can simulate vividly all kinds of scenery in the nature. It furnishes a new perspective for human beings to know the nature and the world. With the rapid development of computer technology, the computing power of the computer is increasingly strong. The computeraided fractal algorithm helps to generate complex textures and shapes, as well as producing fractal objects with physical forms and visual effects. The fractal geometry deals with the dot, line and facet of the figure from an overall perspective, so it is superior to traditional Euclidean geometry in terms of the description of nature.
At present, the fractal theory is widely applied to the fields of physics, chemistry, biology, medicine, geology and computer science [3]. In computer graphics, the fractal theory has broaden the channels and provided a new direction for computer graphics generation [4]. In aesthetics, the fractal geometry is applied to morphological creation of furniture [5], landscape design [6], architectural design [7] and textile industry [8]. In the age of digital image processing, the emergence of fractal theory has improved the compression ratio of image encoding, which is particularly important for image transmission and processing [9]. Moreover, the fractal theory also has some important applications in computer animation generative technology. It can help the computer to simulate vivid natural scenes and improve the efficiency of animation production. Therefore, it is widely applied in the field of film-making and game design.
This paper focuses on the application of fractal geometry in computer graphics. By combining recursive algorithm and IFS algorithm, corresponding fractal images are generated on MATLAB platform to build scenes and enrich the image contents. Besides the creation of static fractal images, this paper also explores the generating method of fractal animation and implements on MATLAB platform. Furthermore, in the selection of implementation platform, the effects of generating fractal images on platforms of MATLAB and Flash are compared.

Creation of snowy night image -combination of recursive and IFS algorithms
Different algorithms could simulate different natural objects in reality. The fractal image generated by one algorithm is very single in its content. If different algorithms could be used in combination in scene construction, a rather rich scene would be generated. Next, this study will apply different algorithms to generate corresponding fractal objects based on our needs and combine them in the same image to build natural scenes.

Creation of the scene "Old Tree, Withered Grass and Snowy Night"
This scene graph contains a row of withered grasses and a withered tree as its main scenery, in which the withered grasses are generated by recursive algorithm that is relatively simple among so many fractal algorithms, in consideration of the efficiency of program execution. Although IFS algorithm can be used to simulate high-fidelity natural scene, its implementation complexity is far higher than that of the recursive algorithm, and the IFS code is required to be obtained in the first place. If each withered grass is generated by calling IFS algorithm, time and memory resources will be consumed highly. In view of these problems of IFS algorithm, the part of withered grass is finished by recursive algorithm. As the withered grass is small in shape, it can just be generated at a low frequency of recursion. The final results of creation shows that the effects can be satisfied ( Figure 1). As only one withered tree is required to be generated, IFS algorithm is used to achieve a vivid effect. The generation process of the scene graph and part of the codes (MATLAB) used are listed as follows. (1) Determine the hierarchy relationship of the scenery (also known as the layer relationship) to further sequence creation. In figure 1, the crescent is on the bottom layer, the fractal tree is on the second layer, the withered tree is on the third layer and the snow is on the top layer. (2) The image takes shape from the bottom layer. Firstly one moon is generated -a white circle is drawn. Then cover the white circle partly with another circle of the same background color to present a crescent effect. (3) Generation of a clump of grasses. The codes used for creating a clump of grasses are listed as follows.
(4) IFS algorithm is applied to generate fractal tree. function f=tree_ifs_2(ax,ay) figure('color', [ The snowflakes are produced by drawing "*" at the coordinate points which are generated by random numbers. The final effect is shown in figure 1.

Creation of the scene "Reed Land and Snowy Night"
An attempt of the 3D visual richness is conducted in the above situations and the reeds are further turned to a reed land. Such 3D visual presentation from close-by examples to those far off just requires, from the perspective of visual principle, a deceasing tendency of the reeds row by row, thereby producing effects of a piece of reed land. The codes for generating this image are just required to be modified from the code of reed part in figure 1  n=0; for N=1:9 n=n+1; for N1=1:t(n) ax=((rand()*2)-1)*a_x(n); ay=-0.8; bx=rand()*0.02-0.01+ax; by=-rand()*b_y_1(n)-b_y_2(n); bulrush(ax,ay,bx,by,15); hold on; end end The vectors "t", "a_x", "b_y_1" and "b_y_2" are parameters used to control the number and height ranges of reeds in each row, in which "t" denotes the number of reeds in each row, "a_x" is used to control the range of reeds, "b_y_1" and "b_y_2" is used to control the height range of the reeds.

Basic principle of fractal animation: fractal algorithm with parameters
Most fractal algorithms are required to contain parameters to control the appearance of the fractal objects. In other words, if one wants to change the appearance of the object generated by fractal algorithm, only the parameters of fractal algorithm are required to be modified. Taking IFS algorithm as an example, the appearance of the fractal object generated by IFS algorithm rests on IFS code. If the IFS codes are changed, so does the appearance of the fractal object. Such changes may be trivial or great, which is dependent on the role of the IFS codes play in the whole code block. Based on this principle, control of the continuous change of one key parameter in the algorithm can produce a fractal image with a series of continuous changes. If we consider these continuously changing fractal images as the animation frame and play them continuously, an effect of fractal animation could be produced. The following study is based on MATLAB platform. It generates several pieces of fractal animation respectively by recursive algorithm and IFS algorithm with parameters.

Basic ideas of generating animation on MATLAB platform
Generating continuously changing fractal image by continuously changing parameters also mean that a new piece of fractal image will be generated after a change of parameter each time. As the implementation of fractal algorithm may consume some time, the time interval between two adjacent images may be long. If the animation is generated by drawing firstly and displaying next, it will appear so discontinuous and affect the visual effect. Therefore, this study uses a method of generation frame by frame firstly and centralized playback next. After each piece of image is generated, the command "getframe" in MATLAB will be used to get each fractal image generated, namely, each frame of the animation. Then the frames will be saved via the command of "movie2avi" as an avi file. Finally, the effects of fractal animation will be seen continuously by playing this avi file. In addition, the play speed and loop playback may be set through relevant commands. Next this study will analyze in detail the design process and key codes of the fractal animation generated on MATLAB platform.

Windmill animation based on recursion
The animation effects of the windmill animation in this design are presented by controlling the continuous changes of the reed shape via the continuously changing parameters. In order to control the reed shape more intuitively and conveniently, the reed generated function is required to be modified. Specific details are shown as follows.
function f=bulrush_2(ax,ay,b,alfa_1,alfa_2) PI=3.1415926; alfa_1=alfa_1*(PI/180); bx=b*cos(alfa_1); by=b*sin(alfa_1); bulrush(ax,ay,bx,by,alfa_2); end Unlike the generated function of the above-mentioned reed bulrush (ax,ay,bx,by,alfa_1), bulrush_2 controls the shape of reed directly by passing its height (b) and angle (alfa_1) and both contribute to calculations of "bx" and "by" value, then the bulrush function will be called again to generate the reed. Such modification enables more intuitive and convenient control of the reed shape and simplifies the animation process of windmill animation. The generation process of the windmill animation is listed as follows.
(1) Generation of the windmill. bulrush_2(0,0,1,0,-18); M(1)=getframe; r=0; dr=5; for N=1:72 clf; r=r+dr; bulrush_2(0,0,1,r,-18); if(r>=50) bulrush_2(0,0,1,45,-18); end Similar to if(r>=50), the other 6 reeds will be generated respectively at 90°, 135°, 180°, 225°, 270° and 315°, and form a complete windmill when the precondition of "if" statement changes. So specific codes are not given here.The processes and effects of windmill generation are shown in figure 3. (2) Rotation of the windmill.  (3) The windmill changes in size while rotating with smear. Four parameters should be defined in this step. The first one controls the pendulum angle of small subbranches of the reeds and the amplitude of swing ranges from -18 to 18. The second one denotes the swing pace of the small subbranch and the subbranch swings 1° in each frame. The third one controls the length of the reeds, ranging from 0.028 to 1. The last one denotes the pace of length changing. The animation effects are shown in figure 5. (4) Generation of .avi files.

Lunar eclipse based on recursive and IFS algorithms
In the image of "Old Tree, Withered Grass and Snowy Night" (Figure 1), the crescent is formed by partial overlap of two circles and its shape changes with the movement of the circle-cover. If the process of continuous crescent changes is gotten in the form of frame, continuous playback helps to get the whole process of lunar eclipse. In addition, the continuous changes of parameters allow the reeds to render an effect of swinging with the wind. The generation process in shown as follows.
(1) Generate the 1st frame of animation. In this step, we can define two vectors "ax" and "1", both are used to save the length information of each reed generated in the first frame. Only in this way can the reed of same length be generated at the same location in each of the following frames and the discontinuity between frames could be avoided.
(2) The process of lunar eclipse and swinging reeds.
There are four parameters defined in this step. The parameter "s" denotes the horizontal coordinate of the circle-cover, and "ds" denotes the pace of its change in each frame. The parameter "angel" is used to control the angle of reed, "da" is the pace of its change in each frame. In this animation, firstly the reeds swing to an angle of 105° and then swing back and forth between 103°and 105°. This effect is controlled by mark bit "flag". Once these parameters are defined, we can simply start to generate frame by frame through using a "for" loop.
The final effects are shown in figure 6.

Implementation of multi-rule LS algorithm
"Multi-rule" in the multi-rule LS algorithm refers to the rule of multiple replacement. In the singlerule LS algorithm, replacement is required only when character 'F' appears in a string, while multirule requires to replace multi characters. Hence, the script codes only need to be partially modified.  What can be concluded from the above figure 7 and figure 8 is that although it's easier to implement LS algorithm on Flash, deeper sense of recursion can't be realized because of the limitation of Flash computing power, thus the effect of plant simulation is not as expected. The main idea of LS algorithm is moving forward and drawing lines, which limits the animation effect of Flash and makes the effect monotonous and not obvious. From this perspective, the MATLAB platform's computing power is obviously much stronger than Flash because it is capable of deep recursion, and the simulation of plants on MATLAB is better than Flash in terms of fidelity.

Conclusion and discussion
In practice, the content of fractal graph generated by one kind of algorithm alone is relatively toneless. Combining different algorithms can not only break the limitation of single fractal object generation but also enrich the contents of scenes. In this paper, according to the needs of scene construction, more targeted algorithms are appropriately chosen. By combing two fractal algorithms of recursion and IFS, two static scenarios "Old Tree, Withered Grass and Snowy Night" and "Reed Land and Snowy Night" are built on MATLAB platform, which further enriches contents of the scene. Simultaneously, a trial has been made to experiment the generation of dynamic fractal graphs. Based on the fractal algorithm with parameters, a recursive windmill animation and a lunar eclipse animation based on recursion and IFS algorithm are generated on MATLAB platform, which enhances the creativity of the scene building of fractal animation.
With respect to the selection of implementation platform, this paper compares the effects of fractal graph generation between MATLAB and Flash. The results show that, the computing power of Flash is far less than that of MATLAB, so it might not be possible to realize the complex fractal algorithm on Flash. However, thanks to its powerful animation creation ability, Flash is undoubtedly more valuable than MATLAB in the implementation of relatively simple fractal animation effect in the light of speed and convenience. What's more, Flash has great flexibility, which can create vivid animation effect freely and also can make the realization of man-machine interactive operation more convenient. Nevertheless, in order to achieve richer and more realistic animation effects, the more powerful MATLAB platform is preferred. In general, MATLAB and Flash both have their advantages and disadvantages. Therefore, it is necessary to choose the right platform according to actual requirements of creation so as to improve the development efficiency.
Fractal geometry, with its unique charm, enormously enriches human's cognition of the world. It has extremely high theoretical value and has attracted many scholars' attentions in the academic circle. Nowadays, fractal theory has been applied in many fields such as signal processing, image coding, as well as new material research and development. In the future, fractal theory will achieve more fruitful results with further explorations being done. For example, in the field of architecture and home decoration, architect and building designer can use a complete fractal graph to decorate the whole surface of a wall or produce wallpaper and home ornamentation composed of fractal pattern. In the field of information security, fractal theory can contribute to information encryption technology as well. In the aspect of natural disaster warning, prediction accuracy of natural disasters such as earthquake and tsunami can be improved by using fractal theory. Besides, in the area of computer graphics, with the development of computer technology, the process of fractal image exploitation in computer will become more efficient and convenient, and the contents will be more colorful.