0% found this document useful (0 votes)
3 views

computer graphics-basics2

The document contains a C program for drawing a line using the graphics library. It prompts the user for starting and ending coordinates and implements the Bresenham's line algorithm to plot the line on the screen. There are some syntax errors and missing elements in the code that need to be corrected for proper execution.

Uploaded by

hajisaad029
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

computer graphics-basics2

The document contains a C program for drawing a line using the graphics library. It prompts the user for starting and ending coordinates and implements the Bresenham's line algorithm to plot the line on the screen. There are some syntax errors and missing elements in the code that need to be corrected for proper execution.

Uploaded by

hajisaad029
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Saad Haji Enrollment no: 23111590411 Class : C03KB

Batch: 1 Subject: CGR Practical: 3


Program :
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
void main(){
int x,y,x1,y1,x2,y2,p,i;
int dx, dy;
int gd = DETECT, gm;
clrscr();
printf("\n Enter the value for starting point of line: "); scanf("%d%d", &x1, &y1);
printf("\n Enter the value for ending point: "); scanf("%d%d",&x2,y2);
dx = abs (x2 x1);
dy = abs (y2 - y1);
x = x1;
y = y1;
i = 0;
= 2 * (dy dx);
initgraph (&gd, & gm, "C:\\TURBOC3\/BGI");
while (i<=dx){
putpixel(x,y,WHITE);
if (p<=0){
x = x + 1;
p = p + 2 dy;
}
else{
x = x + 1;
y = y + 1;
p = p + 2 dy
}
i++;
delay(25);
initgraph (&g, & gm, "C:\\TURBOC3\\BGI");
while (i<=dx){
putpixel(x,y,WHITE);
if (p<=0){
x = x + 1;
p = p + 2 dy;
}
else{
x = x + 1;
y = y + 1;
p = p + 2 dy - 2 * dx;
}
i++;
delay(25);
}
getch();
closegraph();
}
Output :

You might also like