First, I update the svg parser to allow user to specify three new elements sierpinksi, barnsley and flame, you can see how to use them from examples in svg/asst5
Then, I try to draw the Sierpinski Triangle using the basic algorithm outlined in Wiki. First, I have three points, Then I calculate the middle point of each line segement and use those 6 new points to form 3 triangles. I recursively divide those triagnles untill reach to certain depth. The user can specify the intial 3 points of the biggest triangle and depth. Example is in svg/ass5/sierpinski.svg. Below is the graph generated. I use depth 6 in this example.
Next, I implement the Barnsley Fern also using the algorithm outlined in Wiki. I start with 0,0 and recursively transform the point and rasterize that point and below is the picture of such picture
However, the picture looks not that good since it only draws scattered point with no sense of frequency and no gradient change of backgrond color. Thus, I use irradience caching and distance function outlined in writeup to make it more aesthetically looking. Whenever I try to rasterize a point from barnsely algorithm, I call my own fill_energy and add energy to that point, so that some points will be added several times which results that it has a very high energy. Then when I draw the picture, I find the largest energy and get the ratio of each point's energy to this largest energy to be its grey scale. However, the problem of such method is that 1 point will have a very huge energy, in barnsley is the tip of the leave. Therefore, most of the points have very low ratio and thus can't be easily distinguished from the background. So, I gain some inspiration from the paper about flame algorithm in the writeup, and take the log of the energy instead which result in a much smoother picture. I also try to use square root twice and it results in very similar picture as of taking the log.
I also use the distance function outlined in writeup, I use bfs to propagate all points in the background and use a half-life decreasing factor to calculate their energy. Below is the picture I get from using the irrdadiance cache and distance function.
In the end, I read the paper about flame algorithm and try to replicate one, however, in the paper the author mentioned that he would disclose the parameter he uses in Appendix B, however I couldn't find Appendix B in the paper and have no idea what kind of parameter he uses. Still I implement some of the non-affine transformation he mentioned in the paper, such as sinusoidal, spherical, swirl and try to use those to create my own ifs system
I encounter most difficuties in this part. I try to design some system but it usually diverges very quickly which results in only a few points on the screen or converges very fast to a single point which also results in only a few points in the graph. I still couldn't find a way to systematically design a ifs system that will not diverge or converge to a point. Finally, I use the affine transformations in Barnsley as starting point and change some parameters and add some non-affine transformation like sinusoidal, spherical and swirl after the affine, below is the picture. This is a quite contrived example and if I change a few parameter the picture will look drametically different and may also diverge or converge to a point again.
another difficuties I encounter is that my system is seperate from the previous rasterization one. So if the program sees a flame or barnsley in the svg, it will call resolve_ir_cahe and ignore other elements. Otherwise, it will call the normal resolve.