computer graphics lab manual for iv cse

Upload: gopal-ram

Post on 29-Oct-2015

510 views

Category:

Documents


5 download

DESCRIPTION

This Lab manual contain the entire program of Computer graphics and is useful for engineering students

TRANSCRIPT

BRESENHAMS LINE DRAWING ALGORITHMEx No: 1 a

Date:

Aim:

To write a program in C language for Bresenhams line drawing algorithm.

Algorithm:

1. Input the lines two endpoint and store the left end point in (x1,y1) and right end point in(x2,y2).

2. Load (x1,y1) into the frame buffer; (i.e) plot the first point.

3. Calculate constants dx, dy, 2dy and 2dy-2dx and obtain the starting value for the decision parameter as

P0=2dy-dx

4. At each xk along the line, starting at k=0, perform the following test:

If pkxb)

{

x=xb;

y=yb;

xend=xa;

}

else

{

x=xa;

y=ya;

xend=xb;

}

putpixel(x,y,15);

while(x