Java chaos game noise game example code
[introduction]
Recently, I have been reading abstruse simplicity, in which a chapter introduces several methods of generating fractal images using noise, which is very interesting. So I tried to use computer simulation, and the effect is good (the noise method is better than the traditional iterative method in programming. Later, I found that there are still many such algorithms, and more can be found by searching chaosgame).
[noise generation method of Sierpinski triangle]
In these noise games, the generation rule of Sierpinski triangle is the simplest:
1. Select three points on the plane and mark them as 1, 2 and 3 as the vertices of the large triangle.
2. Select one of the points as the "current point" (for example, select No. 1).
3. Generate a random number of 1 ~ 3, draw a new point at the midpoint between the vertex expressed by the number and the "current point", and take the new point as the "current point".
4. Repeat step 3 to approach the pattern.
*Note that it is better not to use time as the seed generation method for random numbers.
[simulator]
[simulation results]
When the B key is pressed
[barnsleyfern's noise generation method]
Compared with the simple regularity of Sierpinski triangle, barnsleyfern (fractal fern) gives people a more complex impression. Due to its complexity, chaos discipline often takes it to prove the conclusion that "simple rules can also produce complex objects".
Its generation rules are not very complex:
1. First, given the "current point" (0,0), we use ox, oy to represent the abscissa and ordinate.
2. To calculate the next point (NX, NY), you need to select one of the following four iterative formulas with certain random rules:
1) Select this iteration formula with a probability of% 1:
nx=0;
ny=0.16f*oy;
2) Select this iteration formula with a probability of% 85:
nx=0.85*ox+0.04*oy;
ny=-0.04*ox+0.85*oy+1.6;
3) Select this iteration formula with a probability of% 7:
nx=0.2*ox-0.26*oy;
ny=0.23*ox+0.22*oy+1.6;
4) Select this iteration formula with a probability of% 7:
nx=-0.15*ox+0.28*oy;
ny=0.26*ox+0.24*oy+0.44;
3. Draw (NX, NY) and set it as the current point. Repeat 2 to approach the result infinitely.
↑ the above formula is extracted from Wiki: http://en.wikipedia.org/wiki/Barnsley_fern 。 During programming, I found a problem. The wiki did not indicate the relationship between the decisive value of this coordinate and the screen size, nor the direction of the X and Y axes. It was always unsuccessful to draw in the coordinate system defined by myself. Later, I searched according to the formula and found this face: http://people.sc.fsu.edu/ ~jburkardt/cpp_ src/fern_ opengl/fern. cpp。 This is an OpenGL program in C + +, which uses the same formula as wiki, that is, this group of formulas is based on the coordinate system of OpenGL, and finally successfully drawn after corresponding transformation.
[simulator]
[simulation results]
summary
The above is all about the Java chaos game example code in this article. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site. If there are deficiencies, please leave a message to point out. Thank you for your support!