⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 et2.c

📁 线程描述。主程序创建两个线程myThread1 和 myThread2
💻 C
字号:
#include<stdio.h>
typedef struct{
int y_top;
float x_int;
int delta_y;
float x_change_per_scan;
}EACH_ENTRY;
	EACH_ENTRY sides [MAX_POINT];
int side_count,first_s,last_s,scan,bottomscan,x_int_count,r;
fill_area(count,x,y)
int count,x[],y[];
{
sort_on_bigger_y(count);
first_s=1;
last_s=1;
for(sacn=side[1],y_top;scan>bottomscan?;scan--)
{    update_first_and_last(count,scan);
     process_x_intersection(scan,first_s,last_s);
     draw_lines(scan,x_int_count,first_s);
     update_sides_list();
     }
 }
 void put_in_sides_list(entry,x1,y1,x2,y2,next_y)
   int entry,x1,y1,x2,y2,next_y;
   {
  int maxy;
   float x2_temp,x_change_temp;
   x_change_temp=(float)(x2-x1)/(float)(y2-y1);
   x2_temp=x2;            /* 以下为退缩一点操作*/
   if((y2>y1)&&(y2<next_y)){
           y--;
   x2_temp--=x_change_temp;
   }
   else{    if((y2<y1)&&(y2>next_y)){
               y2++;
               x2_temp+=x_change_temp;
       }
   }
     /*以下为插入活性表操作*/
 maxy=(y1>y2)?y1:y2;
 while((entry>1)&&(maxy>sides[entry-1].y_top))
     {
     sides[entry]=sides[entry?];
     entry--;
 }
 sides[entry].y_top=maxy;
 sides[entry].delta_y=abs(y2-y1)+1;
 if(y1>y2)
         sides[entry].x_int=x1;
 else{
         sides[entry].x_int=x2_temp;
         sides[entry].x_change_per_sca=x_change_temp;
         }
   }
   void sort_on_bigger_y(n)
   int n;
   {
   int k,x1,y1;
   side_count=0;
   y1=y[n];
   x1=x[n];
   bottomscan=y[n];
   for(k=1;k<n+1;k++)
   {
           if(y1!=y[k]){
                           side_count++;
                           put_in_sides_list(side_count,x1,y1,x[k],y[k]);
                           }
         else{
         move((short)x1,(short)y1);
         line((short)x[k],(short)y1,status);
         }
        if(y[k]<bottomscan)bottomscan=y[k];
        y1=y[k];x1=x[k];
        }
     }
     void update_first_and_last(count,scan)
     int count,scan;
     {
     while ((sides[last_s+1].y_top>=scan)&&(last_s<count))last_s++;
     while(sides[first_s].delta_y==0) first_s++;
     }
     void swap(x,y)
     EACH_ENTRY x,y;
     {
     int i_temp;
     float f_temp;
     i_temp=x.y_top;x.y_top=y.y_top;y.y_top=i_temp;
     f_temp=x.x_int;x.x_int=y.x_int;y.x_int=f_temp;
     i_temp=x.delta_y;x.delta=y.delta_y;y.delta_y=i_temp;
     f_temp=x.x_change_per_scan;x.x_change_per_scan=y.x_change_per_scan;
     y.x_change_per_scan=f_temp;
     }
     void sort_on_x(entry,first_s)
     int entry,first_s;
     {
     while((entry>first_s)&&(sides[entry].x_int<sides[entry-1].x_int))
             {
                         swap(sides[entry],sides[entry-1]);
                         entry--;
                        }
        }
        void process_x_intersections(scan,first_s,last_s)
        int scan,first_s,last_s;
        {
        int k;
        x_int_count=0;
        for(k=first_s;k<last_s+1;k++)
        {
        if(sides[k].delta_y>0){
                    x_int_count++;
                    sort_on_x(k,first_s);
                    }
          }
          }
          void draw_lines(scan,x_int_count,index)
          int scan,x_int_count,index;
          {
          int k,x,x1,x2;
          for(k=1;k<(int)(x_int_count/2+1.5);k++)
          {
          while(sides[index].delta_y==0)index++;
          x2=(int)(sides[index].x_int+0.5);
          move((short)x1,(short)scan);
          line((short)x2,(short)scan,status);
            index++;
}
}
        void update_sides_list()
{
int k;
for(k=first_s;k<last_s+1;k++)
    {
          if(sides[k].delta_y>0)
          {
          sides[k].delta_y--;
          sides[k].x_int-=sides[k].x_change_per_scan;
          }
          }
          }          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -