Java Chaos Game Noise Games Two

Source: Internet
Author: User

Java Chaos Game Noise Games Two

[Introduction]

Recently has been reading "abstruse concise", there is a chapter on the use of noise to produce a fractal map of the method, the feeling is very interesting, so try to use a computer simulation, the effect is good (noise method than the traditional iterative method in the programming of the implementation of some, and later found that such algorithms are many, search chaos Game can find more).

This program source file and its dependent jar package have been packaged and can be downloaded here at GitHub.



[Sierpinski-triangular noise generation method]


In these noisy games, the Sierpinski (Sierpiński) triangle generates the simplest rules:

1. Select three points on the plane, labeled 1, 2, 3, as the vertices of the large triangles.

2. Select one of the points as the "current point" (e.g. select number 1th).

3. Generate a random number of vertices, draw a new point at the vertex of the number expression and the midpoint of the "current point", and use the new point as the "current point".

4. Repeat step 3 to approximate the pattern.

*. Note that random numbers are best not to use time as a seed to produce a pattern.



[Simulation Program]

Package Com.geiv.chaos;import Java.awt.event.keyevent;import Com.thrblock.util.randomset;import geivcore. Defaultfactor;import Geivcore. Keyfactor;import Geivcore. Keylistener;import Geivcore. R;import Geivcore. Uesi;import Geivcore.enginedata.obj.obj;public class Sierpinski extends Defaultfactor implements Keylistener{uesi UES ; obj[] Basepoint;obj crtpoint;public Sierpinski (Uesi ues,int times) {this. UES = Ues;basepoint = new obj[3];//creates three datum points for (int i = 0;i < 3;i++) {Basepoint[i] = Ues.creatobj (Uesi. Bgindex); Basepoint[i].addglpoint ("70DBDB", 0,0); Basepoint[i].show ();} BASEPOINT[0].SETCENTRALX (400);//Set three point position basepoint[0].setcentraly; basepoint[1].setcentralx; basepoint[1]. Setcentraly (550); Basepoint[2].setcentralx (740); Basepoint[2].setcentraly (550); crtpoint = basePoint[0];// This.setkeylistener the No. 0 point as the current point (this); Ues.pushkeyboardio (this), for (int i = 0;i < times;i++) {generatenew ();}} @Overridepublic void Dokeybord (keyfactor whom, int keycode, Boolean ispressed) {//Mount callback if (ispressed) {if (keycode == Keyevent.vk_space) {//spaces correspond to create a new point generatenew ();} else if (keycode = = keyevent.vk_a) {//a corresponds to the creation of 100 new points for (int i = 0;i < 100;i++) {generatenew ();}} else if (keycode = = Keyevent.vk_b) {//b corresponds to the creation of 1000 new points for (int i = 0;i < 1000;i++) {generatenew ();}}}} public void Generatenew () {OBJ flagpoint = basepoint[randomset.getrandomnum (0, 2)];//randomly selects one of the datum points float NX = ( Flagpoint.getcentralx () + crtpoint.getcentralx ())/2f;//compute midpoint Float NY = (flagpoint.getcentraly () + crtpoint.getcentraly ())/2f;obj Newpoint = Ues.creatobj (Uesi. BGINDEX);//Create New Point Newpoint.addglpoint ("70DBDB", 0,0); Newpoint.setcolor (Randomset.getrandomcoldcolor ()); Newpoint.setcentralx (NX);//Set Coordinate Newpoint.setcentraly (NY); Newpoint.show (); crtpoint = newpoint;//to current point}public static void Main (string[] args) {Uesi ues = new R (); new Sierpinski (ues,0);//The construction parameters that follow can set the initial number of points. }}




[Simulation Results]

When the B key is pressed



[Barnsleyfern noise generation Method]



Compared to the simple rule of the Sierpinski triangle, Barnsleyfern (fractal Leymus chinensis) gives a more complicated impression, because of its complexity, chaotic disciplines often come up with the conclusion that "simple rules can also produce complex objects".

Its production rules are also not very complex:

1. First given the "Current Point" (0,0), we use Ox,oy to represent the horizontal ordinate.

2. The next point of calculation (Nx,ny) requires that one of the following four iteration formulas be selected with a random rule:

1) Select this iteration formula with the probability of%1:

NX = 0;

ny = 0.16f * Oy;

2) Select this iterative formula with the probability of%85:

NX = 0.85*ox+ 0.04*oy;

ny = -0.04*ox + 0.85*oy + 1.6;

3) Select this iterative formula with the probability of%7:

NX = 0.2*ox-0.26*oy;

ny = 0.23*ox+ 0.22*oy + 1.6;

4) Select this iterative formula with the 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 to the current point, repeat 2, you can approximate the result infinitely.

↑ The above formula is excerpted from the wiki:Http://en.wikipedia.org/wiki/Barnsley_fern. When I was programming, I found a problem where the wiki did not indicate the relationship between the value of this coordinate and the size of the screen, or the direction of the X and Y axes, and it was always unsuccessful to draw in my own defined coordinate system, and then I searched the formula and found the face:/http People.sc.fsu.edu/~jburkardt/cpp_src/fern_opengl/fern.cpp. This is a C + + OpenGL program, which uses the same formula as the wiki, that is, the set of formulas is based on OpenGL's coordinate system, after the corresponding transformation has been successfully drawn.



[Simulation Program]

Package Com.geiv.chaos;import Geivcore. Defaultfactor;import Geivcore. Keyfactor;import Geivcore. Keylistener;import Geivcore. R;import Geivcore. Uesi;import Geivcore.enginedata.obj.obj;import Java.awt.color;import Java.awt.event.keyevent;import Com.thrblock.util.randomset;public class Barnsleyfern extends Defaultfactor implements Keylistener{uesi UES;OBJ Crtpoint;public Barnsleyfern (Uesi ues,int times) {this. UES = Ues;crtpoint = Ues.creatobj (Uesi. Bgindex); Crtpoint.addglpoint ("70DBDB", 0,0); Crtpoint.show (); crtpoint.setcentralx (0); crtpoint.setcentraly (0); UES.SETVIEWOFFSETX (n); This.setkeylistener (this); Ues.pushkeyboardio (this), for (int i = 0;i < times;i++) {generatenew ();}} @Overridepublic void Dokeybord (keyfactor whom, int keycode, Boolean ispressed) {///keyboard IO in the same way as if (ispressed) {if (keycode = = Keyevent.vk_space) {generatenew ();} else if (keycode = = keyevent.vk_a) {for (int i = 0;i < 100;i++) {generatenew ();}} else if (keycode = = Keyevent.vk_b) {for (int i = 0;i < 1000;i++) {generatenew ();}}}} Public VOID generatenew () {float Nx,ny;float ox = crtpoint.getcentralx ()/150f,oy = (600-crtpoint.getcentraly ())/60f;// The OpenGL coordinate transformation is done here, corresponding to the reversal when setting the new point position.    Double code = 100.0 * RANDOMSET.GETRANDOMFLOATIN_1 ();//random floating-point number 0~100if (code >= 0&&code <= 1) {nx = 0; NY = 0.00f * OX + 0.16f * OY;} else if (Code > 1&& Code <=) {NX = 0.85f*ox + 0.04f*oy;ny = -0.04f*ox + 0.85f*oy + 1.6f;} else if (Code > 86&& Code <=) {NX = 0.2f*ox-0.26f*oy;ny = 0.23f*ox + 0.22f*oy + 1.6f;} Else{nx = -0.15f*ox + 0.28f*oy;ny = 0.26f*ox + 0.24f*oy + 0.44f;} OBJ Newpoint = Ues.creatobj (Uesi. Bgindex); Newpoint.addglpoint ("70DBDB", 0,0); Newpoint.setcolor (Color.green); Newpoint.setcentralx (nx*150f);// Offsets the previous coordinate transformation newpoint.setcentraly (600-ny*60f); Newpoint.show (); crtpoint = newpoint;//Sets the new point as the current point. }public static void Main (string[] args) {Uesi ues = new R (); new Barnsleyfern (ues,0);}}



[Simulation Results]


Java Chaos Game Noise Games Two

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.