#include "declare.h"
#include <graphics.h>
void st(void)
{
 FILE *f;
 extern int M;
 double x10,x11,x20,x21;
 int gr = DETECT,mode;
 switch(M)
 {
   case 1:  f = fopen("data11.dat","r");
	    break;
   case 2:  f = fopen("data12.dat","r");
	    break;
 }

 fscanf(f,"%lf %lf %lf %lf",&x10,&x11,&x20,&x21);
 fclose(f);
 initgraph(&gr,&mode,"");
 graphig_write();    //чертит линии равного уровня
 closegraph();
}

void graphig_write(void)
{
 extern int M;
 FILE *f;
 double x10,x11,x20,x21,y0,y1,xx1,x2,hx,hy;
 char color=LIGHTBLUE;
 int i,j,i0,j0;
 setbkcolor(color);
 color=WHITE;
 setcolor(color);
 switch(M)
 {
   case 1:  f = fopen("data11.dat","r");
	    break;
   case 2:  f = fopen("data12.dat","r");
	    break;
 }
 fscanf(f,"%lf %lf %lf %lf",&x10,&x11,&x20,&x21);
 hx = (x11 - x10)/getmaxx();
 hy = (x21-x20)/getmaxy();

 i0 = (int)((-x10)/hx);
 j0 = (int)((x21-x20)/hy);
  i = (int)((-x10)/hx);
  j = 0;
 line(i,j,i0,j0);
 i0 = 0;
 j0 = (int)(x21/hy);
  i = (int)((x11-x10)/hx);
  j = (int)(x21/hy);
 line(i,j,i0,j0);
 printf("         x1: %lf # %lf x2: %lf # %lf",x10,x11,x20,x21);
 color=RED;
 setcolor(color);
 fscanf(f,"%lf %lf %lf",&xx1,&x2,&y0);
 i0 = (int)((xx1-x10)/hx);
 j0 = (int)((x21-x2)/hy);
 while(!feof(f))
 {
  fscanf(f,"%lf %lf %lf",&xx1,&x2,&y1);
  i = (int)((xx1-x10)/hx);
  j = (int)((x21-x2)/hy);
  if( (j+20)<getmaxy() && (j0+20)<getmaxy() )
  if(y0 == y1) line(i,j,i0,j0);
   else
  {
   y0=y1;
  }
  i0=i;
  j0=j;
 }
 fclose(f);
 switch(M)
 {
   case 1:  f = fopen("data21.dat","r");
	    break;
   case 2:  f = fopen("data22.dat","r");
	    break;
 }
 while(!feof(f))
 {
  fscanf(f,"%lf %lf %lf",&xx1,&x2,&y1);
  i = (int)((xx1-x10)/hx);
  j = (int)((x21-x2)/hy);
  if( (j+20)<getmaxy() && (j0+20)<getmaxy() )
  if(y0 == y1)  line(i,j,i0,j0);
   else  y0=y1;
  i0=i;
  j0=j;
 }
 fclose(f);
 getch();
 switch(M)
 {
   case 1:  f = fopen("data31.dat","r");
	    break;
   case 2:  f = fopen("data32.dat","r");
	    break;
 }
 color=RED;
 setcolor(color);
 fscanf(f,"%lf%lf",&xx1,&x2);
 switch(M)
 {
   case 1: xx1=1.0;
	   x2=1.0;
	   break;
   case 2: xx1=0.0;
	   x2=-1.0;
	   break;
 }
 setlinestyle(0,0,3);
 i0 = (int)((xx1-0.05-x10)/hx);
 j0 = (int)((x21-x2)/hy);
  i = (int)((xx1+0.05-x10)/hx);
  j = (int)((x21-x2)/hy);
  line(i0,j0,i,j);
 i0 = (int)((xx1-x10)/hx);
 j0 = (int)((x21-0.05-x2)/hy);
  i = (int)((xx1-x10)/hx);
  j = (int)((x21+0.05-x2)/hy);
  line(i0,j0,i,j);
  getch();
 color=YELLOW;
 setcolor(color);
 while(!feof(f))
 {
  fscanf(f,"%lf",&xx1);
  fscanf(f,"%lf",&x2);
 i0 = (int)((xx1-x10)/hx);
 j0 = (int)((x21-x2)/hy);
  fscanf(f,"%lf",&xx1);
  fscanf(f,"%lf",&x2);
  i = (int)((xx1-x10)/hx);
  j = (int)((x21-x2)/hy);
  line(i0,j0,i,j);
  i0=i;
  j0=j;
 }
 getch();
}
