Sayfayı Yazdır | Pencereyi Kapat

c de cizgi ve sekil çizme

Nereden Yazdırıldığı: C#nedir?com
Kategori: C/C++
Forum Adı: C / C++ ve C++.NET
Forum Tanımlaması: C/ C++ ve C++.NET
URL: http://www.csharpnedir.com/forum2/forum_posts.asp?TID=9995
Tarih: 24 Nisan 2014 Saat 13:56
Program Versiyonu: Web Wiz Forums 8.03 - http://www.webwizforums.com


Konu: c de cizgi ve sekil çizme
Mesajı Yazan: harunkav
Konu: c de cizgi ve sekil çizme
Mesaj Tarihi: 25 Nisan 2007 Saat 05:47

#include "graphics.h"

#define INCR 1

#define DECR -1

#define PREDX 1

#define PREDY 0

int dx, dy, e, e_inc, e_noinc ;

 

main( )

{

int gd = DETECT, gm ;

initgraph ( &gd, &gm, "c:\\tc\\bgi" ) ;

bressline ( 0, 300, 300, 300 ) ;  /* m = 0, horizontal line */

bressline ( 100, 200, 100, 300 ) ;  /* m = infinity, vertical line */

bressline ( 0, 0, 100, 50 ) ;  /* 0 < m < 1 */

bressline ( 100, 50, 0, 0 ) ;  /* 0 < m < 1 */

bressline ( 0, 0, 100, 100 ) ;  /* m = 1 */

bressline ( 100, 100, 0, 0 ) ;  /* m = 1 */

bressline ( 0, 0, 100, 150 ) ;  /* 1 < m < infinity */

bressline ( 100, 150, 0, 0 ) ;  /* 1 < m < infinity */

bressline ( 0, 150, 100, 100 ) ;  /* 0 > m > -1 */

bressline ( 100, 100, 0, 150 ) ;  /* 0 > m > -1 */

bressline ( 0, 200, 100, 100 ) ;  /* m = -1 */

bressline ( 100, 100, 0, 200 ) ;  /* m = -1 */

bressline ( 100, 100, 0, 300 ) ;  /* -1 > m > 0 */

bressline ( 0, 300, 100, 100 ) ;  /* -1 > m > 0 */

getch( ) ;

closegraph( ) ;

}

 

bressline ( int x1, int y1, int x2, int y2 )

{

int incdec, t, i ;

 

if ( x1 > x2 )

{

t = x1 ; x1 = x2 ; x2 = t ;

t = y1 ; y1 = y2 ; y2 = t ;

}

 

dx = x2 - x1 ; dy = y2 - y1 ;

 

if ( dx == 0 ) /* vertical line */

{

if ( y1 > y2 )

{

t = y1 ; y1 = y2 ; y2 = t ;

}

for ( i = y1 ; i <= y2 ; i++ )

putpixel ( x1, i, WHITE ) ;

 

return ;

}

 

if ( dy == 0 )  /* horizontal line */

{

for ( i = x1 ; i < x2 ; i++ )

putpixel ( i, y1, WHITE ) ;

 

return ;

}

 

/* 0 < m < 1 */

if ( dy < dx && dy > 0 )

{

e_noinc = 2 * dy ;

e = 2 * dy - dx ;

e_inc = 2 * ( dy - dx ) ;

drawline ( x1, y1, x2, y2, PREDX, INCR ) ;

}

 

/* m = 1 */

if ( dy == dx && dy > 0 )

{

e_noinc = 2 * dy ;

e = 2 * dy - dx ;

e_inc = 2 * ( dy - dx ) ;

drawline ( x1, y1, x2, y2, PREDX, INCR ) ;

}

 

/* 1 < m < infinity */

if ( dy > dx && dy > 0 )

{

e_noinc = 2 * dx ;

e = 2 * dx - dy ;

e_inc = 2 * ( dx - dy ) ;

drawline ( x1, y1, x2, y2, PREDY, INCR ) ;

}

 

/* 0 > m > -1 */

if ( -dy < dx && dy < 0 )

{

dy = -dy ;

e_noinc = 2 * dy ;

e = 2 * dy - dx ;

e_inc = 2 * ( dy - dx ) ;

drawline ( x1, y1, x2, y2, PREDX, DECR ) ;

}

 

/* m = -1 */

if ( dy == -dx && dy < 0 )

{

dy = -dy ;

e_noinc = ( 2 * dy ) ;

e = 2 * dy - dx ;

e_inc = 2 * ( dy - dx ) ;

drawline ( x1, y1, x2, y2, PREDX, DECR ) ;

}

 

/* -1 > m > 0 */

if ( -dy > dx && dy < 0 )

{

dx = -dx ;

e_noinc = - ( 2*dx ) ; e = 2 * dx - dy ;

e_inc = - 2 * ( dx - dy ) ;

drawline ( x2, y2, x1, y1, PREDY, DECR ) ;

}

}

 

drawline ( int x1, int y1, int x2, int y2, int pred, int incdec )

{

int i, start, end, var ;

 

if ( pred == PREDX )

{

start = x1 ;  end = x2 ;  var = y1 ;

}

else

{

start = y1 ;  end = y2 ;  var = x1 ;

}

 

for ( i = start ; i <= end ; i++ )

{

if ( pred == PREDY )

putpixel ( var, i, WHITE ) ;

else

putpixel ( i, var, WHITE ) ;

 

if ( e < 0 )

e += e_noinc ;

else

{

var += incdec ;

e += e_inc ;

}

}

}

 




Cevaplar:
Mesajı Yazan: harunkav
Mesaj Tarihi: 25 Nisan 2007 Saat 05:47
daha fazla bilgisi olan varsa lütfen yardımcı olsun



Sayfayı Yazdır | Pencereyi Kapat

Bulletin Board Software by Web Wiz Forums version 8.03 - http://www.webwizforums.com
Copyright ©2001-2006 Web Wiz Guide - http://www.webwizguide.info