Non-hierarchical implementation of koch snowflake

Source: Internet
Author: User


/* Algorithm implemented by the Program: edge information is stored in a linked list.

The number of edges is used to determine the Edge Orientation.

*/

# Include <stdio. h>
# Include <math. h>
# Include <conio. h>
# Include <stdlib. h>
# Include <graphics. h>

# Define Left 0 // a constant in the direction
# Define Right 1
# Define Bottem 2

# Define fcolor 1
# Define bkcolor 0
# Define N 10
# Define PD M_PI/180

Typedef struct Point // defines the node
{
Float x;
Float y;
} Point;
Typedef struct Elegs // defines the edge
{
Point;
Point B;
Struct Elegs * next;
} Elegs;

 
Elegs * head;
Int n = 0, Trend; // The Trend direction indicator variable. n indicates the total number of edges.

/* Function Description */

Void Init ();
Void Init_draw (int x, int y, int len, int du); // initialize the triangle.
Void Draw (Point a, Point B, int du, int bool); // Draw Edges
Void Check_trand (int I); // you can specify the direction of the edge.
Void show (Elegs * head, int du); // The linked list dynamically stores edge information.
Void End ();

Elegs * New ();
Elegs * Add (Elegs * head, Point a, Point B );
Elegs * freelink (Elegs * head );

Void Init ()
{
Int gd = DETECT, gm, ec;
Elegs * p;

Initgraph (& gd, & gm, "d: \ tc3 \ bgi ");
Ec = graphresult ();
If (ec! = GrOk)
{
Printf ("The graphic error :");
Printf ("% s", grapherrormsg (ec ));
Printf ("Key any to halt :");
Getch ();
Exit (0 );
}
Setbkcolor (bkcolor );
Setcolor (fcolor );
Trend = 0;

P = New ();
Head = p;
P-> next = NULL;
}; // Init

Void Init_draw (int x, int y, int len, int du)
{
Int x1, x2, y1, y2;
Point a, B, c;
Elegs * p;

X1 = x-len * cos (60 + du) * M_PI/180 );
Y1 = y + len * sin (60 + du) * M_PI/180 );

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.