• µ±Ç°Î»ÖãºÊ×Ò³>>CÓïÑÔ>>CÓïÑÔ±à³ÌʵÀý>>mypaint»­Í¼³ÌÐò
  • mypaint»­Í¼³ÌÐò
  • #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 )