/* 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 );