int main(){ Point P[5]; P[0].x = 50; P[0].y = 50; P[1].x = 100; P[1].y = 100; P[2].x = 150; P[2].y = 50; P[3].x = 140; P[3].y = 150; P[4].x = 60; P[4].y = 150; set_mode(VGA_256_COLOR_MODE); line_bresenham(P[0],P[1],2); line_bresenham(P[1],P[2],2); line_bresenham(P[2],P[3],2); line_bresenham(P[3],P[4],2); line_bresenham(P[4],P[0],2); scanline(P,5,100); getch(); set_mode(TEXT_MODE); return 0; }
void line(struct point start, struct point end, struct color line_color, struct paint *painter) { /* dda */ // line_dda(start, end, line_color, painter); /* mid point */ // line_midpoint(start, end, line_color, painter); /* bresenham */ line_bresenham(start, end, line_color, painter); }
void main(){ int color; int clip1X, clip1Y, clip2X, clip2Y; int end1X, end1Y, end2X, end2Y, retval; srand(*my_clock); set_mode(VGA_256_COLOR_MODE); // color=rand()%NUM_COLORS; color=175; // membuat view (kotak) line_bresenham(KIRI,ATAS,KANAN,ATAS,color); line_bresenham(KANAN,ATAS,KANAN,BAWAH,color); line_bresenham(KANAN,BAWAH,KIRI,BAWAH,color); line_bresenham(KIRI,BAWAH,KIRI,ATAS,color); // garis pemotong 1 clip1X = clip1Y = clip2X = clip2Y = 0; end1X = 130; end1Y = 30; end2X = 150; end2Y = 150; line_bresenham(end1X,end1Y,end2X,end2Y,color); retval = clipLine(end1X,end1Y,end2X,end2Y,&clip1X,&clip1Y,&clip2X,&clip2Y); if(retval) { line_bresenham(clip1X,clip1Y,clip2X,clip2Y,color-99); } // garis pemotong 2 end1X = 50; end1Y = 90; end2X = 215; end2Y = 90; line_bresenham(end1X,end1Y,end2X,end2Y,color); retval = clipLine(end1X,end1Y,end2X,end2Y,&clip1X,&clip1Y,&clip2X,&clip2Y); if(retval) { line_bresenham(clip1X,clip1Y,clip2X,clip2Y,color-99); } // garis tak memotong end1X = 200; end1Y = 15; end2X = 200; end2Y = 170; line_bresenham(end1X,end1Y,end2X,end2Y,color); retval = clipLine(end1X,end1Y,end2X,end2Y,&clip1X,&clip1Y,&clip2X,&clip2Y); if(retval) { line_bresenham(clip1X,clip1Y,clip2X,clip2Y,color-99); } // garis memotong di dalam (trivial accept) end1X = KANAN; end1Y = ATAS; end2X = KIRI; end2Y = BAWAH; line_bresenham(end1X,end1Y,end2X,end2Y,color); retval = clipLine(end1X,end1Y,end2X,end2Y,&clip1X,&clip1Y,&clip2X,&clip2Y); if(retval) { line_bresenham(clip1X,clip1Y,clip2X,clip2Y,color-99); } sleep(2); set_mode(TEXT_MODE); return; }