CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
Computer graphics programs in c++
1. Question(1):- Write a program of translation of line by using turbo c++.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int x1,y1,x2,y2,tx,ty,x3,y3,x4,y4;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:Turboc3BGI");
printf("enter the starting co-ordinate of point");
scanf("%d%d",&x1,&y1);
printf("enter the last point");
scanf("%d%d",&x2,&y2);
printf("enter the traslation about axis");
scanf("%d%d",&tx,&ty);
setcolor(6);
line(x1,y1,x2,y2);
outtextxy(x2+2,y2+2,"original line");
x3=x1+tx;
y3=y1+ty;
x4=x2+tx;
y4=y2+ty;
3. Question:- write a program of rotation of line by using turbo c++.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{
int x1,y1,x2,y2;
float x3,y3,deg,t;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:Turboc3BGI");
printf("enter the coordinate of line");
scanf("%d%d%d%",&x1,&y1,&x2,&y2);
line(x1,y1,x2,y2);
printf("enter the degree");
scanf("%f",°);
t=(22*deg/180*7);
x3=abs((x2*cos(t))-(y2*sin(t)));
y3=abs((x2*sin(t))+(y2*cos(t)));
line(x1,y1,x3,y3);
getch();
}
4. Question(3):- Write a program of scalling by using turbo c++.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int x1,y1,x2,y2,sx,sy,x3,y3,x4,y4;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:Turboc3BGI");
printf("enter the starting co-ordinate of point");
scanf("%d%d",&x1,&y1);
printf("enter the last point");
scanf("%d%d",&x2,&y2);
printf("enter the scalling");
scanf("%d%d",&sx,&sy);
setcolor(9);
line(x1,y1,x2,y2);
outtextxy(x2+2,y2+2,"original line");
x3=sx*x1;
y3=sy*y1;
x4=sx*x2;
y4=sy*y2;
6. Question:- Write a program of text stand horizontal and vertical axis into
screen.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int x,y,font;
int gd=DETECT,gm;
x=25,y=25,font=10;
initgraph(&gd,&gm,"c:Turboc3BGI");
for(font=0;font<=4;font+1)
{
settextstyle(font,HORIZ_DIR,font+1);
setcolor(5);
outtextxy(x,y,"ankit");
y=y+25;
}
for(font=0;font<=2;font++)
{
settextstyle(font,VERT_DIR,font+2);
setcolor(8);
x=250;
8. Question:- Write a program of create a house by using of turbo c++ .
Ans:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gdriver = DETECT,gmode;
int x,y,x1,y1,x2,y2,dx,dy;
initgraph(&gdriver,&gmode,"C:Turboc3BGI");
setcolor(5);
line(100,15,150,80);
line(60,80,100,15);
rectangle(95,140,120,200);
rectangle(60,80,150,200);
circle(100,60,10);
getch();
closegraph();
}
9. Question:- Write a program of fish by using tubo c++.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gdriver = DETECT,gmode;
int x,y,x1,y1,x2,y2,dx,dy;
initgraph(&gdriver,&gmode,"C:Turboc3BGI");
setcolor(5);
ellipse(100,90,25,335,60,40);
line(40,90,80,90);
line(200,90,160,90);
line(160,95,200,105);
line(160,100,200,110);
line(160,110,200,120);
line(160,85,200,75);
line(160,80,200,65);
line(160,70,200,55);
circle(67,75,5);
getch();
closegraph();}
10. Question:- write a program of man cartoonby using c++.
Ans:-
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:Turboc3BGI");
setcolor(5);
circle(500,100,50);
line(500,150,500,450);
line(300,300,500,250);
line(700,300,500,250);
line(300,500,500,450);
line(500,750,500,450);
getch();
closegraph();
}