论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

mypaint画图程序

文章类别:C语言程序设计 | 发表日期:2008-9-24 14:43:56

#include <graphics.h>
#include <math.h>
#define ESC 0x1b
#define YES 1
#define NO 0
#define BI      0.72917
#define SHEZ1 { setcolor( MAGENTA ) ; color = 5 ; }
#define SHEZ2 setcolor( LIGHTBLUE ) ; color = 9;
int color = 9;
void line_dda( int x1 , int y1 , int x2 , int y2 , int k )
{ float x = 0.0;
 float y = 0.0;
 float x3 = ( float )x1;
 float y3 = ( float )y1;
 float n;
 n=( float )( abs( x2-x1 ) >= abs( y2-y1 ) ? abs( x2-x1 ) : abs( y2-y1 ) );
 if( n != 0.0 )
 { x=( ( float )( x2-x1 ) ) / n;
  y=( ( float )( y2-y1 ) ) / n;
 }
 while( n >= 0 )
 {       if( 153 < ( int )x3 && ( int )x3 < 595 && 43 < ( int )y3 && ( int )y3 < 305 || k == 1 )
   putpixel( ( int )x3 , ( int )y3 , color );
  x3 += x ;
  y3 += y ;
  n -= 1.0;
 }
}
void line_dda_1( int x1 , int y1 , int x2 , int y2 , int a , int b , int k )
{ float x = 0.0;
 float y = 0.0;
 float x3 = ( float )x1;
 float y3 = ( float )y1;
 float n;
 n=( float )( abs( x2-x1 ) >= abs( y2-y1 ) ? abs( x2-x1 ) : abs( y2-y1 ) );
 if( n != 0.0 )
 { x=( ( float )( x2-x1 ) ) / n;
  y=( ( float )( y2-y1 ) ) / n;
 }
 while( n >= 0 )
 {       if( 153 < a + ( int )x3 && a + ( int )x3 < 595 && 43 < b - (int)(y3*BI + 0.5 ) && b - (int)(y3*BI + 0.5 ) < 305 || k == 1 )
   putpixel( a + ( int )x3 ,  b - (int)(y3*BI + 0.5 ) , color );
  x3 += x ;
  y3 += y ;
  n -= 1.0;
 }
}
void circle_ad( int x , int y , int r )
{       float a , b , n , j , x1 , y1 , x2 , y2;
 float c[ 2 ];
 n = 0.5*( float )r+20 ; j = 2.0*M_PI/n;
 a = cos( j ) ; b = sin( j );
 x1 = ( float )r ; y1 = 0;
 while( ( int )n >= 0 )
 { x2 = x1*a - y1*b ; y2 = y1*a + x1*b;
  c[ 0 ] = x2 ; c[ 1 ] = y2;
  line_dda_1( ( int )x1 , (int)y1 , (int)x2 , (int)y2 , x , y , 0 );
  x1 = c[ 0 ]; y1 = c[ 1 ] ; n -= 1;
 }
}
void circle_bre( int x , int y , int r , int k )
{ int x1 = 0;
 int y1 = r;
 int d = 2*(x1+1)*(x1+1)+(y1-1)*(y1-1)+y1*y1-2*r*r;
 for( ; x1<=y1 ; x1++ )
 {       if( 153  < ( x+x1 ) && ( x+x1 ) < 595 && 43 < ( y-(int)( (float)y1*BI + 0.5 ) ) && ( y-(int)( (float)y1*BI + 0.5 ) ) < 305 || k )
   putpixel( x+x1 , y-(int)( (float)y1*BI + 0.5 ) , color );
  if( 153  < ( x+y1 ) && ( x+y1 ) < 595 && 43 < ( y-(int)( (float)x1*BI + 0.5 ) ) && ( y-(int)( (float)x1*BI + 0.5 ) ) < 305 || k )
   putpixel( x+y1 , y-(int)( (float)x1*BI + 0.5 ) , color );
  if( 153  < ( x+y1 ) && ( x+y1 ) < 595 && 43 < ( y+(int)( (float)x1*BI + 0.5 ) ) && ( y+(int)( (float)x1*BI + 0.5 ) ) < 305 || k )
   putpixel( x+y1 , y+(int)( (float)x1*BI + 0.5 ) , color );
  if( 153  < ( x+x1 ) && ( x+x1 ) < 595 && 43 < ( y+(int)( (float)y1*BI + 0.5 ) ) && ( y+(int)( (float)y1*BI + 0.5 ) ) < 305 || k )
   putpixel( x+x1 , y+(int)( (float)y1*BI + 0.5 ) , color );
  if( 153  < ( x-x1 ) && ( x-x1 ) < 595 && 43 < ( y+(int)( (float)y1*BI + 0.5 ) ) && ( y+(int)( (float)y1*BI + 0.5 ) ) < 305 || k )
   putpixel( x-x1 , y+(int)( (float)y1*BI + 0.5 ) , color );
  if( 153  < ( x-y1 ) && ( x-y1 ) < 595 && 43 < ( y+(int)( (float)x1*BI + 0.5 ) ) && ( y+(int)( (float)x1*BI + 0.5 ) ) < 305 || k )
   putpixel( x-y1 , y+(int)( (float)x1*BI + 0.5 ) , color );
  if( 153  < ( x-y1 ) && ( x-y1 ) < 595 && 43 < ( y-(int)( (float)x1*BI + 0.5 ) ) && ( y-(int)( (float)x1*BI + 0.5 ) ) < 305 || k )
   putpixel( x-y1 , y-(int)( (float)x1*BI + 0.5 ) , color );
  if( 153  < ( x-x1 ) && ( x-x1 ) < 595 && 43 < ( y-(int)( (float)y1*BI + 0.5 ) ) && ( y-(int)( (float)y1*BI + 0.5 ) ) < 305 || k )
   putpixel( x-x1 , y-(int)( (float)y1*BI + 0.5 ) , color );
  if( d < 0 )
   d += 4*x1+6;
  else
  { d = d+4*( x1-y1 )+10;
   y1 -= 1;
  }
 }
}
void ellipse_ad(int x , int y , int a , int b )
{ int n;
 float x1 , y1 , x2 , y2 , s , c , j;
 x1 = ( float )a;
 y1 = 0.0;
 n = a + 30;
 j = 2*M_PI / ( float )n;
 s = sin ( j );
 c = cos ( j );
 while( n > 0 )
 { x2 = x1 * c - y1 * ( float )a / ( float )b * s;
  y2 = y1 * c + x1 * ( float )b / ( float )a * s;
  line_dda( x1+x , y-y1 , x2+x , y-y2 , 0 );
  x1 = x2 ; y1 = y2;
  n -= 1;
 }
}
void ellipse_bre( int x , int y , int a , int b , int k )
{ float d , x1 , y1 , a1 , b1;
 int x2 , y2;
 x1 = 0.0;
 y1 = ( float )b;
 a1 = ( float )a;
 b1 = y1;
 d = b1*b1 - a1*a1*b1 + a1*a1/4;
 x2 = ( int )x1;
 y2 = ( int )y1;
 if( 153 < ( x2+x ) && ( x2+x ) <595 && 43 < ( y-y2 ) && ( y-y2 ) < 305 ||k )
  putpixel( x2+x , y-y2 , color );
 if( 153 < ( x2+x ) && ( x2+x ) <595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
  putpixel( x+x2 , y+y2 , color );
 while( b1*b1*x1 < a1*a1*y1 )
 { if( d < 0 )
  { d = d + 2*b1*b1*x1 + b1*b1;
   x1 += 1.0;
   x2 = ( int )x1;
   y2 = ( int )y1;
   if( 153 < ( x2+x ) && ( x2+x ) < 595 && 43 < ( y-y2 ) && ( y-y2 ) < 305 ||k )
    putpixel( x2+x , y-y2 , color );
   if( 153 < ( x2+x ) && ( x2+x ) < 595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
    putpixel( x2+x , y+y2 , color );
   if( 153 < ( x-x2 ) && ( x-x2 ) < 595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
    putpixel( x-x2 , y+y2 , color );
   if( 153 < ( x-x2 ) && ( x-x2 ) < 595 && 43 < ( y-y2 ) && ( y-y2 ) < 305 ||k )
    putpixel( x-x2 , y-y2 , color );
  }
  else
  { d = d - 2*a1*a1*y1 + 2*b1*b1*x1 + b1*b1;
   x1 += 1.0;
   y1 -= 1.0;
   x2 = ( int )x1;
   y2 = ( int )y1;
   if( 153 < ( x+x2 ) && ( x+x2 ) <595 && 43 < ( y-y2 ) && ( y-y2 ) < 305 ||k )
    putpixel( x2+x , y-y2 , color );
   if( 153 < ( x+x2 ) && ( x+x2 ) <595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
    putpixel( x2+x , y+y2 , color );
   if( 153 < ( x-x2 ) && ( x-x2 ) <595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
    putpixel( x-x2 , y+y2 , color );
                        if( 153 < ( x-x2 ) && ( x-x2 ) <595 && 43 < ( y-y 2 ) && ( y-y2 ) < 305 ||k )
    putpixel( x-x2 , y-y2 , color );
  }
 }
 if( b1*b1*x1 >= a1*a1*y1 )
  d = d + 3*( a1*a1 - b1*b1 )/4 - ( b1*b1*x1 + a1*a1*y1 );
 while( b1*b1*x1 >= a1*a1*y1 && y1 > 0.0 )
 { if( d >= 0 )
  { d = d - 2*a1*a1*y1 + a1*a1;
   y1 -= 1.0;
   x2 = ( int )x1;
   y2 = ( int )y1;
   if( 153 < ( x2+x ) && ( x2+x ) < 595 && 43 < ( y-y2 ) && ( y-y2 ) < 305 ||k )
    putpixel( x2+x , y-y2 , color );
   if( 153 < ( x2+x ) && ( x2+x ) < 595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
    putpixel( x2+x , y+y2 , color );
   if( 153 < ( x-x2 ) && ( x-x2 ) < 595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
    putpixel( x-x2 , y+y2 , color );
                        if( 153 < ( x-x2 ) && ( x-x2 ) < 595 && 43 < ( y-y2 ) && ( y-y2 ) < 305 ||k )
    putpixel( x-x2 , y-y2 , color );
  }
  else
  { d = d + 2*b1*b1*x1 - 2*a1*a1*y1 + a1*a1;
   x1 += 1.0;
   y1 -= 1.0;
   x2 = ( int )x1;
   y2 = ( int )y1;
   if( 153 < ( x+x2 ) && ( x+x2 ) < 595 && 43 < ( y-y2 ) && ( y-y2 ) < 305 ||k )
    putpixel( x2+x , y-y2 , color );
   if( 153 < ( x+x2 ) && ( x+x2 ) < 595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
    putpixel( x2+x , y+y2 , color );
   if( 153 < ( x-x2 ) && ( x-x2 ) < 595 && 43 < ( y+y2 ) && ( y+y2 ) < 305 ||k )
    putpixel( x-x2 , y+y2 , color );
   if( 153 < ( x-x2 ) && ( x-x2 ) < 595 && 43 < ( y-y2 ) && ( y-y2 ) < 305 ||k )
    putpixel( x-x2 , y-y2 , color );
  }
 }
}
void juxing( int x1 , int y1 , int x2 , int y2 )
{ line_dda( x1 , y1 , x2 , y1 , 1 );
 line_dda( x2 , y1 , x2 , y2 , 1 );
 line_dda( x2 , y2 , x1 , y2 , 1 );
 line_dda( x1 , y2 , x1 , y1 , 1 );
}
void clear( int x1 , int y1 , int x2 , int y2 )
{ int min , i ;
 color = 0;
 min = abs(y1 - y2 ) >= abs( x1 - x2 ) ? abs( x1 - x2 ) : abs ( y1 - y2 );
 for( i = 0 ; i < ( min + 2 )/2 ; i++ )
  juxing( x1 + i , y1 + i , x2 - i , y2 - i );
 color = 9;
}
main()
{       int gdriver = VGA;
 int gmodel = VGAMED;
 int textlong = 0;
 int textwide = 20;
 int minlong = 37;
 int minwide = 37;
 int maxlong = 601;
 int maxwide = 311;
 int buttonx = 40;
 int buttony = 40;
 int blackx1 = 153;
 int blacky1 = 43;
 int blackx2 = 595;
 int blacky2 = 305;
 int colors = 5;
 int up = 304;
 int left = 154;
 int select = 0;
 int page = 0;
 int key;
 int i = 0;
 int k = 0;
        int x = 0;
 int y = 0;
 int x1 = 0;
 int y1 = 258;
 int x2 = 0;
 int y2 = 0;
 int data = 0;
 int renew = 0;
 int sure = 0;
 int exit = NO;
 int pixelx = 0;
 int pixely = 0;
 int pixels;
 int a[ 600 ];
 char b[ 10 ];
 char c[ 10 ];
 char d[ 10 ];
 char e[ 10 ];
 char help[] = "ESC-exit I/K-select W/S/A/D-move SPACE-sure R-remove H-renew C-clear 0/9-color ";
 clrscr();
 printf( "<<My Paint 1.2>> program was maded by Jadelight.author - LJL\n\n" );
 printf( "Please input the pixel point number (1-5):");
 scanf( "%d" , &pixels );
 printf( "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nPlease Waiting" );
 for( i = 1 ; i < 60  ; i++ )
 {       delay( 30000 - i*500 );
  printf( ">" );
 }
 printf( "[OK]" );
 sleep( 2 );
 while( pixels > 5 || pixels < 1 )
  pixels = 5;
 registerbgidriver( EGAVGA_driver );
 initgraph( &gdriver , &gmodel , "" );
 while( YES )
 { setactivepage( page );
  clearviewport();
  for( k = 0 ; k < 2 ; k++ )
   juxing( k , k , getmaxx() - k , getmaxy() - k );
  setcolor( RED );
  outtextxy( textlong + 474 , textwide , "Jadelight" );
  line_dda( textlong+20 , textwide+3 , textlong + 160*3 - 10 ,textwide+3 , 1 );
  line_dda( textlong + 474 + textwidth("Jadelight")+2 , textwide+3 , textlong+getmaxx()-20 , textwide+3 , 1 );
  for( i=0 ; i<3 ; i++ )
  { juxing( minlong+i , minwide+i , maxlong-i , maxwide-i );
   line_dda( buttonx+107+i , buttony , buttonx+107+i , maxwide-3 , 1 );
  }
  for( i=1 ; i<9 ; i++ )
   line_dda( buttonx , buttony + 30*i , buttonx+109 , buttony + 30*i , 1 );
  for( i=0 ; i<8 ; i++ )
   juxing( buttonx + 2 , buttony + i*30 + 3 , buttonx + 104 , buttony + i*30 + 27 );
  setcolor( LIGHTBLUE );
  if(select == 0 )
   SHEZ1
  line_dda( buttonx+8 , buttony+8  , buttonx+20 , buttony+20 , 1 );
  outtextxy( buttonx+30 , buttony+15 , "Dda");
  SHEZ2
  if( select ==1 )
   SHEZ1
  line_dda( buttonx+8 , buttony+8+30 , buttonx+20 , buttony+20+30 , 1 );
  outtextxy( buttonx+30 , buttony+30+15 , "Bresenham");
  SHEZ2
  if( select == 2 )
   SHEZ1
  circle_bre( buttonx+15 , buttony + 60 + 15  , 8 , 1 );
  outtextxy( buttonx+30 , buttony+60+15 , "Angle");
  SHEZ2
  if( select == 3 )
   SHEZ1
  circle_bre( buttonx+15 , buttony+60+15+30 , 8 , 1 );
  outtextxy( buttonx+30 , buttony+90+15 , "Bresenham");
  SHEZ2
  if( select == 4 )
   SHEZ1
  ellipse_bre( buttonx+15 , buttony+120+15 , 8 , 5 , 1 );
  outtextxy( buttonx+30 , buttony+120+15 , "Angle" );
  SHEZ2
  if( select == 5 )
   SHEZ1
  ellipse_bre( buttonx+15 , buttony+120+15+30 , 8 , 5 , 1 );
  outtextxy( buttonx+30 , buttony+150+15 , "Bresenham" );
  SHEZ2
                if( select == 6 )
   SHEZ1
  juxing( buttonx+5 , buttony+180+10 , buttonx+25 , buttony+180+20 );
  outtextxy( buttonx+30 , buttony+180+15 , "Rectangle" );
  SHEZ2
  if( select == 7 )
   SHEZ1
  outtextxy( buttonx+30 , buttony+210+15 , "About" );
  SHEZ2
  setfillstyle( SOLID_FILL , RED );
  floodfill( buttonx+1 , buttony + select*30 + 2 , LIGHTBLUE );
  juxing( blackx1 , blacky1 , blackx2 , blacky2 );
  line_dda( 0 , getmaxy()-25 , getmaxx() , getmaxy()-25 , 1 );
  setcolor( MAGENTA );
  outtextxy( textlong+9 , getmaxy()-15 , help );
  for( i = 0 ; i < data/6 ; i++)
  { if( a[ i*6 ] == 0 )
   { color = a[ i*6+5 ];
    line_dda( a[ i*6+1 ] , a[ i*6+2 ] , a[ i*6+3 ] , a[ i*6+4 ] , 1 );
   }
   else if( a[ i*6 ] == 1 )
   { color = a[ i*6+5 ];
    line_dda( a[ i*6+1 ] , a[ i*6+2 ] , a[ i*6+3 ] , a[ i*6+4 ] , 1 );
   }
   else if( a[ i*6 ] == 2)
   { color = a[ i*6+5 ];
    circle_ad( a[ i*6+1 ] , a[ i*6+2 ] , abs( a[ i*6+3 ] - a[ i*6+1 ] ) );
   }
   else if( a[ i*6 ] == 3 )
   { color = a[ i*6+5 ];
    circle_bre( a[ i*6+1 ] , a[ i*6+2 ] , abs( a[ i*6+3 ] - a[ i*6+1] ) , 0 );
   }
   else if( a[ i*6 ] == 4 )
   {       color = a[ i*6+5 ];
    if( a[ i*6+1 ] - a[ i*6+3 ] == 0 )
     line_dda( a[ i*6+1 ] , a[ i*6+2 ] , a[ i*6+1 ] , a[ i*6+2 ] + 2 * ( a[ i*6+4] - a[ i*6+2 ] ) , 0 );
    else if( a[ i*6+2 ] - a[ i*6+4 ] == 0 )
     line_dda( a[ i*6+3 ] , a[ i*6+4 ] , a[ i*6+3 ] - 2 * ( a[ i*6+3 ] - a[ i*6+1 ] ) , a[ i*6+2 ] , 0 );
    else
     ellipse_ad( a[ i*6+1 ] , a[ i*6+4 ] , abs( a[ i*6+3 ] - a[ i*6+1 ] ) , abs( a[ i*6+4 ] - a[ i*6+2 ] ) );
   }
   else if( a[ i*6 ] == 5 )
   { color = a[ i*6+5 ];
    if( a[ i*6 + 1 ] - a[ i*6 + 3 ] == 0 )
     line_dda( a[ i*6 + 1 ] , a[ i*6 + 2 ] , a[ i*6 + 1 ] , a[ i*6 + 2 ] + 2 * ( a[ i*6 + 4] - a[ i*6 + 2 ] ) , 0 );
    else if( a[ i*6 + 2 ] - a[ i*6 + 4 ] == 0 )
     line_dda( a[ i*6 + 3 ] , a[ i*6 + 4 ] , a[ i*6 + 3 ] - 2 * ( a[ i*6 + 3 ] - a[ i*6 + 1 ] ) , a[ i*6 + 2 ] , 0 );
    else
     ellipse_bre( a[ i*6 + 1 ] , a[ i*6 + 4] , abs( a[ i*6 + 3 ] - a[ i*6 + 1 ] ) , abs( a[ i*6 + 4 ] - a[ i*6 + 2 ] ) , 0 );
   }
   else if( a[ i*6 ] == 6 )
   {      color = a[ i*6 + 5 ];
          juxing( a[ i*6 + 1 ] , a[ i*6 + 2 ] , a[ i*6 + 3 ] , a[ i*6 + 4 ] );
   }
  }
  if( colors == 1 )
  { setcolor( BLUE );
   outtextxy( buttonx-3 , getmaxy()-33 , "Blue" );
  }
  else if( colors == 2 )
  { setcolor( GREEN );
   outtextxy( buttonx-3 , getmaxy()-33 , "Green");
  }
  else if( colors == 3 )
  { setcolor( CYAN );
   outtextxy( buttonx-3 , getmaxy()-33 , "Cyan");
  }
  else if( colors == 4 )
  { setcolor( RED );
   outtextxy( buttonx-3 , getmaxy()-33 , "Red");
  }
  else if( colors == 5 )
  { setcolor( MAGENTA );
   outtextxy( buttonx-3 , getmaxy()-33 , "Magenta");
  }
  else if( colors == 7 )
  { setcolor( WHITE  );
   outtextxy( buttonx-3 , getmaxy()-33 , "White");
  }
  else if( colors == 8 )
  { setcolor( DARKGRAY );
   outtextxy( buttonx-3 , getmaxy()-33 , "Darkgray");
  }
  else if( colors == 9 )
  { setcolor( LIGHTBLUE );
   outtextxy( buttonx-3 , getmaxy()-33 , "Lightblue");
  }
  else if( colors == 10 )
  { setcolor( LIGHTGREEN );
   outtextxy( buttonx-3 , getmaxy()-33 , "Lightgreen");
  }
                else if( colors == 14 )
  { setcolor( YELLOW );
   outtextxy( buttonx-3 , getmaxy()-33 , "Yellow");
  }
  if( sure == YES )
  {       if( colors != 7 )
    putpixel( x , y , colors );
   else
    putpixel( x , y , colors + 8 );
   sprintf( d , "%d" , x2 );
   sprintf( e , "%d" , y2 );
   outtextxy( buttonx+20 , buttony+240+5 , d );
   outtextxy( buttonx+60 , buttony+240+5 , e );
  }
                sprintf( b , "%d" , pixelx );
  sprintf( c , "%d" , pixely );
  setcolor( MAGENTA );
  outtextxy( buttonx+20 , buttony+240+20 , b );
  outtextxy( buttonx+60 , buttony+240+20 , c );
  color = 2;
  line_dda( left , up , left+3 , up , 0 );
  line_dda( left , up , left-3 , up , 0 );
  line_dda( left , up , left , up+3 , 0 );
  line_dda( left , up , left , up-3 , 0 );
  color = 9;
  if( exit == YES )
  { setcolor( MAGENTA );
   if( page == YES )
   outtextxy( buttonx+405 , getmaxy()-33 , "Are you exit ? <Y/N>");
  }
  if( select == 7 )
  {       color = 7;
   juxing( blackx1 + 77 , blacky1 + 77 , blackx2 - 75 ,blacky2-75 );
   setfillstyle( SOLID_FILL , LIGHTGRAY );
   floodfill( blackx1 + 78 , blacky1 + 78 , LIGHTGRAY );
   color = 15;
   for( i = 0 ; i < 2 ; i++ )
   juxing( blackx1 + 82 + i*2 , blacky1 + 80 + i*2 , blackx2 - 80 - i*2 , blacky2 - 78 - i*2 );
   setcolor( 0 );
   outtextxy( blacky2 + 40 , 140 , "My Paint" );
   outtextxy( blacky2 + 22 , 170 , "Version  2.0" );
   outtextxy( blacky2 - 40 , 185 , "Copyright (c) 2004 - 2005 by");
   outtextxy( blacky2 - 40 , 200 , "Join corporation author-LJL.");
   color = 9;
  }
  setvisualpage( page );
  page = YES - page;
  if( exit == NO )
  { if( kbhit() )
   { if( ( key = getch() ) == ESC )
     exit = YES;
    else if( key == 'i' || key == 'I' || key == 'j' || key == 'J' )
    { if( select == 0 )
      select = 7;
     else
      select--;
    }
    else if( key == 'k' || key == 'K' || key == 'l' || key == 'L' )
    { if( select == 7 )
      select = 0;
     else
      select++;
    }
    else if( key == 'w' || key == 'W' )
    { if( up <= blacky1 + 1 );
     else
     { up -= pixels;
      y1 -= pixels;
      pixely = up;
      pixely = 304 - pixely;
      if( sure == YES )
       y2 = abs( up - y );
     }
    }
    else if( key == 's' || key == 'S' )
    { if( up >= blacky2 - 1 );
     else
     { up += pixels;
      y1 += pixels;
      pixely = up;
      pixely = 304 - pixely;
                                                if( sure == YES )
       y2 = abs( up - y );
     }
    }
    else if( key == 'a' || key == 'A' )
    { if( left <= blackx1 + 1 );
     else
     { left -= pixels;
      x1 -= pixels;
      pixelx = left;
      pixelx -= 154;
                                                if( sure == YES )
       x2 = abs( left - x );
     }
    }
    else if( key == 'd' || key == 'D' )
    { if( left >= blackx2 - 1 );
     else
     { left += pixels;
      x1 += pixels;
      pixelx = left;
      pixelx -= 154;
                                                if( sure == YES )
       x2 = abs( left - x );
     }
    }
    else if( key == 'c' || key =='C' )
    { clear( blackx1+1 , blacky1+1 , blackx2-1 , blacky2-1 );
     data = 0;
     renew = 0;
    }
    else if( key == 0x20 )
    {       if( sure == NO && select != 7 )
     { x = left ; y = up ;
      sure = YES;
     }
     else if( sure == YES && select != 7 )
     {       a[ data + 1 ] = x ; a[ data + 2 ] = y ;
      a[ data + 3 ] = left ; a[ data + 4 ] = up;
      a[ data ] = select;
      if( colors != 7 )
       a[ data+5 ] = colors;
      else
       a[ data+5 ] = colors + 8;
      sure = NO;
      data += 6;
      renew = 0;
      x2 = 0;
      y2 = 0;
     }
    }
    else if( key >= '0' && key <= '9' )
    { if( key != '5' )
      colors = key - 47;
     else
      colors = 14;
    }
    else if( key == 'r' | | key == 'R' )
    {       if( data > 0 )
     { data -= 6;
      renew++;
     }
    }
    else if( key == 'h' || key == 'H' )
    { if( renew > 0 )
     { data += 6;
      renew--;
     }
    }
    while( kbhit() )
     getch();
   }
  }
  else if( kbhit() )
  { key = getch();
   if( key == 'n' || key == 'N' || key == ESC )
   exit = NO;
   if( key == 'y' || key == 'Y' )
   break;
  }
 }
 clear( 0 , 0 , getmaxx() , getmaxy() );
 closegraph();
}

视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058