Вы находитесь на странице: 1из 11

1504511

Practical file
Of
Computer graphics
(BTCS-504)

SUBMITTED TO: SUBMITTED BY:

Ms. Sukhvir Kaur Gursharanjeet Kaur

B.tech (CSE 5th)

1504503

1
1504511

1) WAP to print a pixel .


#include<iostream.h>

#include<conio.h>

#include<graphics.h>

Void main()

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode," ");

putpixel(14,25,BLUE);

getch();

closegraph();

Output::

2
1504511

2) WAP to draw a smiley.


#include<iostream.h>

#include<conio.h>

#include<graphics.h>

void main()

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode," ");

circle(100,150,100);

circle(50,100,20);

circle(100,100,20);

arc (200,200, 180, 360,20);

getch();

closegraph();

Output:

3
1504511

3) WAP to draw a line using DDA line algorithm.


#include<iostream.h>

#include<conio.h>

#include<math.h>

#include<graphics.h>

void main()

int gdriver=DETECT,gmode;

float dx,dy,x1,x2,y1,y2,len,z1,z2,k,x,y;

cout<<"enter the intial coordinate";

cin>>x1>>y1;

cout<<"enter the ending coordinates";

cin>>x2>>y2;

dx=x2-x1;

dy=y2-y1;

dx=abs(dx);

dy=abs(dy);

if(dx>dy)

len=dx;

else

4
1504511

len=dy;

z1=dx/len;

z2=dy/len;

x=x1;

y=y1;

initgraph(&gdriver,&gmode," ");

putpixel(x,y,WHITE);

for(k=1;k<len;k++)

x=x+z1;

y=y+z2;

putpixel(x,y,WHITE);

getch();

closegraph();

OUTPUT::

5
1504511

6
1504511

4) WAP to draw a line after adding translation vector.

#include<iostream.h>

#include<conio.h>

#include<math.h>

#include<graphics.h>

void main()

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode," ");

float x1,x2,y1,y2,tx,ty;

cout<<"enter the intial coordinates";

cin>>x1>>y1;

cout<<"enter the ending coordinates";

cin>>x2>>y2;

line(x1,y1,x2,y2);

cout<<"enter translation factor";

cin>>tx>>ty;

x1=x1+tx;

y1=y1+ty;

x2=x2+tx;

y2=y2+tx;

line(x1,y1,x2,y2);

getch();

closegraph();

7
1504511

OUTPUT:

8
1504511

5) To scale an object with scaling factors along X and Y directions.

#include<iostream.h>

#include<conio.h>

#include<math.h>

#include<graphics.h>

void main()

int gdriver=DETECT,gmode;

float x1,x2,y1,y2,sx,sy;

initgraph(&gdriver,&gmode,"");

clrscr();

cout<<"enter the intial coordinate";

cin>>x1>>y1;

cout<<"enter the ending coordinates";

cin>>x2>>y2;

line(x1,y1,x2,y2);

cout<<"enter the scaling factor";

cin>>sx>>sy;

x1=sx*x1;

y1=sy*y1;

x2=sx*x2;

y2=sy*y2;

line(x1,y1,x2,y2);

getch();

9
1504511

closegraph();

10
1504511

11

Вам также может понравиться