Fractal and data Structure second article

Source: Internet
Author: User

The fractal of fractal is realized by the iterative form.

The graphs are all implemented in the previous drawing tools.

First, the same as the original set up a JButton element component, and then add the listening method, and then the public void mouseclicked (MouseEvent e) {} method to implement the graph;

        Else if(S.equals ("Figure 2")) {            DoubleX1 = 0, y1 = 0, x2 = 0, y2 = 0; DoubleA =-2, B =-2, c = -1.2, d = 2;  for(intn = 0; n <= 50000; n++) {g1.setcolor (color.green);                G1.setstroke (C); / * * Calculate the value first, and then draw the drawing, note that because the value is small, it needs to be enlarged.                 * While forced transformation should be to find the value of the overall turn that should be added parentheses (x2 * +), int m = (int) x2 * * 100 + 350, no parentheses are, after X2 transformation, then multiplied by 100, plus 350, */X2= (Math.sin (A * y1)-Math.Cos (b *x1)); Y2= (Math.sin (c * x1)-Math.Cos (d *y1)); //int m = (int) (x2 * +);(x2 * 100 + 350) overall forced transformation;// int s = (int) (y2 * 100 + 350), this is X2 multiplied by 100 plus 350 to get the number to be transformed ;//G.drawline (M, S, M, s);G1.drawline ((int) (x2 * 100 + 300), (int) (y2 * 100 + 300), (int) (x2 * 100 + 300),                        (int) (y2 * 100 + 300)); //when forcing a transition, be careful to add parentheses to the overall transformationX1 =x2; Y1=Y2; }

Results:

Figure 3:

 Else if(S.equals ("Figure 3") {g1.setcolor (Color.magenta);            G1.setstroke (C); DoubleX1 = 0, y1 = 0, x2 = 0, y2 = 0; DoubleA = 1.40, B = 1.56, c = 1.40, d =-6.56;  for(intn = 0; n <= 60000; n++) {X2= d * Math.sin (A * x1)-Math.sin (b *y1); Y2= c * Math.Cos (A * x1) + Math.Cos (b *y1); G1.drawline ((int) (X2 * 50 + 550), (int) (Y2 * 50 + 300), (int) (X2 * 50 + 550), (int) (Y2 * 50 + 300)); //multiplied by the number, the control size, the overall addition changes the position;X1 =x2; Y1=Y2; }

Results:

Graphic FOUR:

    Else if(S.equals ("Figure 4") {g1.setcolor (color.blue);                    G1.setstroke (C); DoubleA = 0.4, B = 1, c = 0; DoubleX1 = 0, y1 = 0, x2 = 0, y2 = 0;  for(intn = 0; n <= 60000; n++) {X2= Y1-math.signum (x1) * MATH.SQRT (Math.Abs (b * x1-c)); Y2= A-X1; G1.drawline ((int) (X2 * 150 + 500), (int) (y2 * 150 + 250), (int) (X2 * 150 + 500), (int) (y2 * 150 + 250)); //multiplied by the number, the control size, the overall addition changes the position;X1 =x2; Y1=Y2; }        }

Results:

Graphic Five:

Else if(S.equals ("Figure 5") {g1.setcolor (color.blue);            G1.setstroke (C); intA = 1, b = 4, c = 60; DoubleX1 = 0, y1 = 0, x2 = 0, y2 = 0;  for(intn = 0; n <= 60000; n++) {X2= Y1-math.signum (x1) * MATH.SQRT (Math.Abs (b * x1-c)); Y2= A-X1; G1.drawline ((int) (x2 + 600), (int) (Y2*3 + 400), (int) (X2*3 + 600), (int) (Y2*3 + 400));//Note the value of the drawing line;//multiplied by the number, the control size, the overall addition changes the position; The graph's multiplier cannot be too large, preferably between 0-5X1 =x2; Y1=Y2; }        }

Results:

Summary: These fractal graphs are also very easy, but pay attention to the values obtained when drawing, (should be in the window, XY should be positive,)

/**
* The form is the origin of the upper- left corner, the visible part of the form is an integer, i.e. the first quadrant of the axis;
*/

The formula used this time: all in the Math method:

/**
* Signum (double D): Returns the symbolic function of the parameter, returns 0 if the argument is 0, or 1.0 if the argument is greater than 0, or 0 if the argument is less than 1.0.
ABS (Double A): Returns the absolute value of a double.
sqrt (double A): Returns the positive square root of the double value that is rounded correctly.
*/

Fractal and data Structure second 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.