Computer Graphics lesson's
Basic's of how to draw a line in TurboC....
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<math.h>
void main()
{
clrscr();
float x,y,x1,x2,y1,y2,dx,dy,lenght;
int i,gd,gm;
cout<<"enter x1 and y1"<<endl;
cin>>x1>>y2;
cout<<"enter x2 and y2"<<endl;
cin>>x2>>y2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
{ lenght=dx;}
else
{lenght=dy;}
dx=(x2-x1)/lenght;
dy=(y2-y1)/lenght;
x=x1+0.5 ;
y=y1+0.5;
i=1;
while(i<=lenght)
{
putpixel(x,y,15);
x=x+dx;
y=y+dy;
i++;
}
delay(100);
getch();
closegraph();
}
Second basic's of drawing a line......
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<math.h>
void main()
{
clrscr();
float x,y,x1,x2,y1,y2,dx,dy,e;
int i,gd,gm;
cout<<"enter x1 and y1"<<endl;
cin>>x1>>y2;
cout<<"enter x2 and y2"<<endl;
cin>>x2>>y2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
dx=abs(x2-x1);
dy=abs(y2-y1);
x=x1;
y=y1;
e=2*dy-dx;
i=1;
do
{
putpixel(x,y,15);
while(e<=0)
{
y=y+1;
e=e+2*dx;
}
x=x+1;
e=e+2*dy;
i++;
}while(i<=dx);
getch();
closegraph();
}
#include<graphics.h>
#include<conio.h>
void main()
{
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\tc\\bgi");
circle(300,250,150);
circle(250,200,25);
circle(350,200,25);
line(300,225,300,275);
line(300,225,300,275);
arc(300,250,240,300,75);
getch();
}
Comments
Post a Comment