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

Computer Graphics Line

This document contains code to draw a line between two points on a graph using the Bresenham's line algorithm. It takes the starting and ending x,y coordinates as input, calculates the change in x and y, and uses those values to incrementally draw pixels between the points, outputting a line on the graph. It initializes the graphics mode, gets the start and end points, performs the line drawing calculations in a for loop pixel by pixel, and waits for user input before ending.

Uploaded by

vigvelu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Computer Graphics Line

This document contains code to draw a line between two points on a graph using the Bresenham's line algorithm. It takes the starting and ending x,y coordinates as input, calculates the change in x and y, and uses those values to incrementally draw pixels between the points, outputting a line on the graph. It initializes the graphics mode, gets the start and end points, performs the line drawing calculations in a for loop pixel by pixel, and waits for user input before ending.

Uploaded by

vigvelu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{

int gd = DETECT, gm = DETECT, s, dx, dy, m, x1, y1, x2, y2;
float xi, yi, x, y;

clrscr();

printf("Enter the sarting point x1 & y1\n");
scanf("%d%d", &x1, &y1);

printf("Enter the end point x2 & y2\n");
scanf("%d%d", &x2, &y2);

initgraph(&gd, &gm, "");
cleardevice();

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

if (abs(dx) > abs(dy))
s = abs(dx);
else
s = abs(dy);

xi = dx / (float) s;
yi = dy / (float) s;

x = x1;
y = y1;

putpixel(x1, y1, 4);

for (m = 0; m < s; m++) {
x += xi;
y += yi;
putpixel(x, y, 4);
}
getch();
}

You might also like