upload folder graphics programs (1)
TRANSCRIPT
-
8/8/2019 Upload Folder Graphics Programs (1)
1/20
Computer Graphics
Line Drawing Functions
Point structure
Asima Latif
19-Nov-2009
-
8/8/2019 Upload Folder Graphics Programs (1)
2/20
12/25/2010 2
Main Mile stones that we will cover in this course
Basic Concepts
Basic Shapes, Line Drawing Algorithms
Projection / Display of Graphics
Transformation
Parametric Equations
Graphics Pipeline OpenGL
Two dimensional Graphics
3D Graphics
-
8/8/2019 Upload Folder Graphics Programs (1)
3/20
12/25/2010 3
Book / Other Material
Computer Graphics FS Hill or the hevern one
Turbo C++ remember that there is a BGI
folder
Visual C++ , OpenGL GLUT Library
Java3D optional
-
8/8/2019 Upload Folder Graphics Programs (1)
4/20
12/25/2010 4
Origin Center of the screen
To get the center of the screen
We have two functions
Getmaxx()
Getmaxy()
Center of Screen
Int cx = getmaxx()/2;
Int cy = getmaxy()/2;
-
8/8/2019 Upload Folder Graphics Programs (1)
5/20
12/25/2010 5
Complete Program with cx, cy
int main(void)
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "\\tc\\bgi");int radius=100;
Int cx=getmaxx()/2;
Int cy=getmaxy()/2;
circle(cx, cy, radius);
getch();
closegraph();
}
-
8/8/2019 Upload Folder Graphics Programs (1)
6/20
12/25/2010 6
Drawing Lines .. 1
Line(int x1,int y1,int x2, int y2);
Draws a line between (x1,y1) AND (x2,y2)
int main(void)
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "\\tc\\bgi");
Line(cx,cy,cx+200,cy);
getch();
closegraph();
}
-
8/8/2019 Upload Folder Graphics Programs (1)
7/20
12/25/2010 7
Drawing Lines .. 1
int main(void)
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "\\tc\\bgi");
Line(cx,cy,cx+200,cy);
Line(cx,cy,cx,cy-200);
getch();
closegraph();
}
-
8/8/2019 Upload Folder Graphics Programs (1)
8/20
12/25/2010 8
Drawing Line 2
Linerel(int dx, int dy)
Draws a line from the current position to the
distance dx, and dy
Curret Position CP is achived through using
the function moveto(int x, int y);
-
8/8/2019 Upload Folder Graphics Programs (1)
9/20
12/25/2010 9
Drawing Lines .. 2
int main(void)
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "\\tc\\bgi");Moveto(cx,cy);
Linerel(200,0);
getch();
closegraph();
}
-
8/8/2019 Upload Folder Graphics Programs (1)
10/20
12/25/2010 10
Drawing Lines .. 3
Lineto(int x, int y)
Draws a line from the current position to the
given point.
-
8/8/2019 Upload Folder Graphics Programs (1)
11/20
12/25/2010 11
Drawing Lines .. 3
int main(void)
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "\\tc\\bgi");Moveto(cx,cy);
Lineto(100,200);
getch();
closegraph();
}
-
8/8/2019 Upload Folder Graphics Programs (1)
12/20
Line Drawing AlgorithmDigital Differential Analyzer
-
8/8/2019 Upload Folder Graphics Programs (1)
13/20
12/25/2010 13
DDAvoid lineDDA(int xa,int ya,int xb,int yb)
{
int dx,dy,steps;dx=xb-xa;
dy=yb-ya;
float xincrement,yincrement,x,y;
if (abs(dx)>abs(dy))
steps=abs(dx);
elsesteps=abs(dy);
xincrement=dx/steps;
yincrement=dy/steps;
x=xa,y=ya;
putpixel(round(x),round(y),2);
for (int k=1;k
-
8/8/2019 Upload Folder Graphics Programs (1)
14/20
12/25/2010 14
Main function
void main()
{
int driver=DETECT,mode;
initgraph(&driver,&mode,"C:\\tc\\bgi");
lineDDA(100,100,401,401);
getch();
closegraph();
}
-
8/8/2019 Upload Folder Graphics Programs (1)
15/20
LINE MIDPOINT
ALGORITHM(BRESHMAN ALGORITHM
void main()
{
int gd=DETECT,gm,x0,y0,x1,y1,dx,dy,d,x,y,c1,c2;
initgraph(&gd,&gm,"c:\\tc\\bgi");
clrscr();
couty0;
coutx1>>y1;
12/25/2010 15
-
8/8/2019 Upload Folder Graphics Programs (1)
16/20
dx=x1-x0;
dy=y1-y0;
d=2*dy-dx;
c1=2*dy;c2=2*(dy-dx);
if(x1>x0)
{
x=x0; y=y0;
putpixel(x,y,RED);
16
while(x
-
8/8/2019 Upload Folder Graphics Programs (1)
17/20
else
{
x=x0; y=y0;putpixel(x,y,YELLOW);
while(x>=x1)
{
if(d
-
8/8/2019 Upload Folder Graphics Programs (1)
18/20
Translation
void main()
{
int
gd=DETECT,gm,x[1
0],y[10],a,b,i,j,dx,dy;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
cout>j;
cout>y[i];
setcolor(BLUE);
for(i=1;i
-
8/8/2019 Upload Folder Graphics Programs (1)
19/20
Translation
line(x[i],y[i],x[0],y[0
]);
cout>dx>>dy;
cout
-
8/8/2019 Upload Folder Graphics Programs (1)
20/20
Thats all for Today