Important Note:Login & Check Your Email Inbox and Activate Confirmation Link |
---|
Section 107 of the Copyright Act Fair Use Contents . We are forwarding content link(s) from our website to content website & We are not serving any contents. Main Source:Google.com.All the Content PDF link(s) is/are obtained from GoogleSearch for the purpose of Education & Teaching Intention. Not for commercial purpose. Technicalsymposium.com is not liable/responsible for any copyright issues. |
---|
|
---|
Computer Graphics Lab Codings-BRESENHAM’S LINE ALGORITHM
Aim:
To write a C++ Program to draw a line using Bresenhams algorithm.
Algorithm:
1. Start the program .
2. Initialize the variables.
3. Call the initgraph() function
4. Get the values for left and right end points for drawing a line..
5. Calculate the distance to be traveled by the line.
6. Put the pixels in the given color to draw the line.
7. Display the output.
8. stop the program
PROGRAM
void main()
{
int gd=DETECT,gm,x0,y0,x1,y1,p,dx,dy,i,x2,y2,ec;
ec=graphresult();
if(ec!=grOk)
{
cout<<"Graphics error:%s\n",grapherrormsg(ec);
cout<<"press any key to halt";
getch();
exit(1);
}
initgraph(&gd,&gm,"");
cout<<"enter left end pt";
cin>>x0>>y0;
cout<<"Enter right end pts";
cin>>x1>>y1;
cleardevice();
dx=abs(x1-x0);
dy=(y1-y0);
if(dx
{
y2=dx;
dx=dy;
dy=y2;
x2=x0;
y2=y0;
}
else
{
x2=y0;
y2=x0;
} p=2*dx*dy;
putpixel(x2,y2,RED);
for(i=0;i<=x0;i++)
{
if(p<0)
{
y2=y2+1;
p=p+2*dy;
}
else
{
x1++;
p=p+2*dy-2*dx;
}
putpixel(x1,y1,RED);
}
setbkcolor(GREEN);
getch();
return;
}
|
---|
|
---|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
![]() |
|
![]() |
---|
![]() |
Official Contact: +91-9245556793 (Whatsapp Message / SMS / Voice Call)Our Expert team is ready to answer all your questions immediately-Feel free to speak in Tamil/English. (Example:Events info/Lecture Notes/Off-Campus & All Jobs/Projects & All education information) Working hrs (IST): (Morning: 10:00AM-3:00 PM) and (Evening:5:00 PM to 10:00 PM)
|
---|