Java fractal plot cohe snowflake curve code sharing

Source: Internet
Author: User

Java fractal plot cohe snowflake curve code sharing

The section is similar to the whole in a certain form and is called a fractal. The cohe curve is a geometric curve with a shape like snowflake. Therefore, it is also called a snowflake curve. It is one of the fractal curves, the description is as follows:

First, let's give an example:

We can see that a small cluster of broccoli is a branch of the entire flower cluster, and they have their own shape at different scales. In other words, a small branch can obtain a cluster that is almost identical to the whole by enlarging the appropriate proportion. Therefore, we can say that the broccoli cluster is a fractal instance.

Fracry generally has the following characteristics:

There can be fine structures on any small scale; it is too irregular to be described in the traditional Euclidean ry language; (at least it is omitted or arbitrarily) the Self-Similar hosdorf dimension is larger than the topological dimension, and has a simple recursive definition.

(I) fragment sets all have proportional details at any small scale, or they have fine structures.

(Ii) fragment sets cannot be described in traditional geometric languages. They are neither trajectory of points that meet certain conditions nor solutions of some simple equations.

(Iii) A fragment set has some form of self-similarity, which may be an approximate self-similarity or a statistical self-similarity.

(Iv) generally, the "fragment dimension" of the fragment set is strictly greater than its corresponding topological dimension.

(V) In most situations of interest, the fragment set is defined by a very simple method and may be generated by transformation iteration.

 

When writing a fragment in java, different graphs call recursion based on different methods, for example:

Cohe curve:

 

 

The Code is as follows:

Public void draw1 (int x1, int y1, int x2, int y2, int depth) {// keleyi.com

G. drawLine (x1, y1, x2, y2 );

If (depth <= 1)

Return;

Else {// get the third-class point

Double x11 = (x1*2 + x2)/3;

Double y11 = (y1*2 + y2)/3;

 

Double x22 = (x1 + x2 * 2)/3;

Double y22 = (y1 + y2 * 2)/3;

 

Double x33 = (x11 + x22)/2-(y11-y22) * Math. sqrt (3)/2;

Double y33 = (y11 + y22)/2-(x22-x11) * Math. sqrt (3)/2;

 

G. setColor (j. getBackground ());

G. drawLine (int) x1, (int) y1, (int) x2, (int) y2 );

G. setColor (Color. black );

Draw1 (int) x1, (int) y1, (int) x11, (int) y11, depth-1 );

Draw1 (int) x11, (int) y11, (int) x33, (int) y33, depth-1 );

Draw1 (int) x22, (int) y22, (int) x2, (int) y2, depth-1 );

Draw1 (int) x33, (int) y33, (int) x22, (int) y22, depth-1 );

}

}

 

 

Square:

 

 

The Code is as follows:

Public void draw2 (int x1, int y1, int m, int depth) {// square keleyi.com

G. fillRect (x1, y1, m, m );

M = m/3;

If (depth <= 1)

Return;

Else {

Double x11 = x1-2 * m;

Double y11 = y1-2 * m;

 

Double x22 = x1 + m;

Double y22 = y1-2 * m;

 

Double x33 = x1 + 4 * m;

Double y33 = y1-2 * m;

 

Double x44 = x1-2 * m;

Double y44 = y1 + m;

 

Double x55 = x1 + 4 * m;

Double y55 = y1 + m;

 

Double x66 = x1-2 * m;

Double y66 = y1 + 4 * m;

 

Double x77 = x1 + m;

Double y77 = y1 + 4 * m;

 

Double x88 = x1 + 4 * m;

Double y88 = y1 + 4 * m;

 

Draw2 (int) x11, (int) y11, (int) m, depth-1 );

 

Draw2 (int) x22, (int) y22, (int) m, depth-1 );

 

Draw2 (int) x33, (int) y33, (int) m, depth-1 );

 

Draw2 (int) x44, (int) y44, (int) m, depth-1 );

 

Draw2 (int) x55, (int) y55, (int) m, depth-1 );

 

Draw2 (int) x66, (int) y66, (int) m, depth-1 );

 

Draw2 (int) x77, (int) y77, (int) m, depth-1 );

 

Draw2 (int) x88, (int) y88, (int) m, depth-1 );

}

 

}

 

 

Xie bingski triangle:

 

 

The Code is as follows:

Public void draw3 (int x1, int y1, int x2, int y2, int x3, int y3, int depth) {// triangle keleyi.com

 

Double s = Math. sqrt (x2-x1) * (x2-x1) + (y2-y1) * (y2-y1 ));

G. drawLine (x1, y1, x2, y2 );

G. drawLine (x2, y2, x3, y3 );

G. drawLine (x1, y1, x3, y3 );

// If (s <3)

// Return;

If (depth <= 1)

Return;

Else

{

/*

* Triangle above

*/

Double x11 = (x1*3 + x2)/4;

Double y11 = y1-(s/4) * Math. sqrt (3 );

 

Double x12 = (x1 + x2 * 3)/4;

Double y12 = y11;

 

Double x13 = (x1 + x2)/2;

Double y13 = y1;

 

/*

* Triangle on the left

*/

Double x21 = x1-s/4;

Double y21 = (y1 + y3)/2;

 

Double x22 = x1 + s/4;

Double y22 = y21;

 

Double x23 = x1;

Double y23 = y3;

 

/*

* Triangle on the right

*/

Double x31 = x2 + s/4;

Double y31 = (y1 + y3)/2;

 

Double x32 = x2-s/4;

Double y32 = y21;

 

Double x33 = x2;

Double y33 = y3;

 

Draw3 (int) x11, (int) y11, (int) x12, (int) y12, (int) x13, (int) y13, depth-1 );

Draw3 (int) x21, (int) y21, (int) x22, (int) y22, (int) x23, (int) y23, depth-1 );

Draw3 (int) x31, (int) y31, (int) x32, (int) y32, (int) x33, (int) y33, depth-1 );

}

}

 

 

The cohe curve is a geometric curve that looks like a snowflake. It is also called a snowflake curve. It is a type of fractal curve. The specific method is as follows:

1. Draw a positive triangle and divide each side into three equal points;

2. Take the middle part of the side after the triequal score as a positive triangle and erase the middle part;

3. Repeat the above two steps to draw a smaller triangle.

4. keep repeating until infinity. The drawn curve is called the cohe curve.

 

Summary: fragment is a very interesting thing. You can draw many nice-looking Images Based on your own imagination. Not only do you already exist, but you can create your own images!

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.