0% found this document useful (0 votes)
26 views11 pages

Graphic Practical

Uploaded by

pranavbadhe20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views11 pages

Graphic Practical

Uploaded by

pranavbadhe20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

a) Block Diagram of Computer

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"d:\\tc\\bgi");
setbkcolor(WHITE);
setcolor(10);
rectangle(20,170,120,230);
line(180,190,200,200);
line(120,200,200,200);
line(180,210,200,200);
rectangle(200,50,400,400);
rectangle(220,70,380,380);
line(220,170,380,170);
line(220,280,380,280);
setcolor(5);
settextstyle(1,0,2);
outtextxy(40,185,"INPUT");
outtextxy(270,210,"ALU");
outtextxy(230,100,"MEMORY UNIT");
outtextxy(235,320,"CONTROL UNIT");
outtextxy(490,185,"OUTPUT");
setcolor(10);
rectangle(480,170,580,230);
line(460,190,480,200);
line(400,200,480,200);
line(460,210,480,200);
setcolor(20);
outtextxy(150,430,"BLOCK DIAGRAM OF
COMPUTER");
getch();
closegraph();
}
b) Display Flag of India

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int x,y,i,gd=DETECT,gm;
float PI=3.14;
clrscr();
initgraph(&gd,&gm," C://TurboC++//Disk//TurboC3//BGI");
setbkcolor(WHITE);
setcolor(4);
rectangle(200,30,450,80);
setfillstyle(1,4);
floodfill(201,31,4);
setcolor(15);
rectangle(200,80,450,130);
setfillstyle(1,15);
floodfill(201,81,15);
setcolor(2);
rectangle(200,130,450,180);
setfillstyle(1,2);
floodfill(201,131,2);
setcolor(1);
circle(325,105,20);
for(i=0;i<=360;i=i+15)
{
x=20*cos(i*PI/180);
y=20*sin(i*PI/180);
line(325,105,325+x,105-y);
}
setcolor(7);
rectangle(195,30,200,400);
setfillstyle(1,7);
floodfill(196,31,7);
getch();
closegraph();
}
c) Flow Chart Symbols, DFD Symbols, ER-Diagram Symbols

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
setbkcolor(WHITE);
setcolor(BLUE);
settextstyle(1,0,1);
outtextxy(160,30,"SYMBOL OF THE FLOWCHART");
settextstyle(0,0,1);
outtextxy(130,80,"NAME");
outtextxy(430,80,"SYMBOL");
outtextxy(125,110,"TERMINAL SYMBOL");
line(420,100,480,100);
line(420,120,480,120);
arc(420,110,90,270,10);
arc(480,110,270,450,10);
outtextxy(125,150,"INPUT/OUTPUT SYMBOL");
line(420,140,410,160);
line(420,140,490,140);
line(490,140,480,160);
line(410,160,480,160);
outtextxy(125,190,"PROCESSING SYMBOL");
rectangle(420,180,490,200);
outtextxy(125,260,"DECISION SYMBOL");
line(455,220,420,260);
line(455,220,490,260);
line(420,260,455,300);
line(455,300,490,260);
outtextxy(125,335,"ON-PAGE CONECTOR");
circle(455,340,25);
outtextxy(125,420,"FLOW LINES");
line(430,420,450,420);
outtextxy(427,417,"<");
line(460,420,480,420);
outtextxy(477,417,">");
line(455,390,455,410);
outtextxy(452,387,"^");
line(455,430,455,450);
outtextxy(452,447,"v");
getch();
closegraph();
}
DFD Symbols
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
settextstyle(1,0,1);
outtextxy(190,100,"DATA FLOW DIAGRAM SYMBOL");
outtextxy(130,180,"External Entity");
rectangle(420,170,500,190);
outtextxy(130,240,"Process");
circle(450,250,30);
outtextxy(130,300,"Data Store");
line(400,310,469,310);
line(400,340,469,340);
outtextxy(130,360,"Data Flow");
line(400,380,465,380);
outtextxy(462,367,">");
getch();
closegraph();
}
, ER-Diagram Symbols
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
settextstyle(1,0,1);
outtextxy(230,60,"ER-DIAGRAM SYMBOL");
outtextxy(130,120,"Attribute");
ellipse(460,120,0,360,40,15);
outtextxy(130,180,"Entity");
rectangle(420,170,500,190);
outtextxy(130,240,"Multivalued Attribute");
ellipse(460,240,0,360,70,20);
ellipse(460,240,0,360,65,15);
outtextxy(130,300,"Relationship");
line(450,275,410,300);
line(410,300,450,323);
line(450,323,490,300);
line(490,300,450,275);
outtextxy(130,360,"Weak Entity");
rectangle(390,335,515,379);
rectangle(395,340,510,375);
getch();
}
6.Implementing Scaling transformation on polygons

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int x,y,x1,y1,x2,y2,sx,sy,a,b,c,d,e,f;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\n Enter first co_ordinate:");
scanf("%d%d",&x,&y);
printf("\n Enter second co_ordinate:");
scanf("%d%d",&x1,&y1);
printf("\n Enter third co_ordinate:");
scanf("%d%d",&x2,&y2);
outtextxy(x-10,y-20,"Before Scaling");
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
printf("Enter the value of sx and sy:");
scanf("%d%d",&sx,&sy);
a=x*sx;
b=y*sy;
c=x1*sx;
d=y1*sy;
e=x2*sx;
f=y2*sy;
line(a,b,c,d);
line(c,d,e,f);
line(e,f,a,b);
outtextxy(x-20,y-30,"Before Scaling");
getch();
closegraph();
}
5. Implementing Translation transformation on polygon

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int driver=DETECT,mode;
int x,y,x1,y1,x2,y2,tx,ty,a,b,c,d,e,f;
clrscr();
initgraph(&driver,&mode,"");
printf("\nenter the first co_ordinate:");
scanf("%d%d",&x,&y);
printf("\nenter the second co_ordinate:");
scanf("%d%d",&x1,&y1);
printf("\nenter the third co_ordinate:");
scanf("%d%d",&x2,&y2);
outtextxy(x-10,y-20,"before translation");
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
printf("Enter the value of tx and ty:");
scanf("%d%d",&tx,&ty);
a=x+tx;
b=y+ty;
c=y1+tx;
d=y1+ty;
e=x2+tx;
f=y2+ty;
line(a,b,c,d);
line(c,d,e,f);
line(e,f,a,b);
outtextxy(a-20,b-30,"after translation.");
getch();
closegraph();
}
7. Implementing Rotation transformation on polygons

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int drive=DETECT,mode;
int x1,y1,x2,y2,x,y,x4,y4,a,b,x3,y3;
clrscr();
initgraph(&drive,&mode,"d\\t\\bgi");
printf("\n Enter the first point:");
scanf("%d%d",&x1,&y1);
printf("\n Enter the second point:");
scanf("%d%d",&x2,&y2);
printf("\n Enter the third point:");
scanf("%d%d",&x3,&y3);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
outtextxy(10,y1-20,"before rotation transformation");
getch();
x=x1*cos(45*3.14/180)+y1*sin(45*3.14/180);
y=x1*sin(45*3.14/180)+y1*cos(45*3.14/180);
x4=x2*cos(45*3.14/180)+y2*sin(45*3.14/180);
y4=x1*sin(45*3.14/180)+y2*cos(45*3.14/180);
a=x3*cos(45*3.14/180)+y3*cos(45*3.14/180);
b=x3*sin(45*3.14/180)+y3*cos(45*3.14/180);
line(x,y,x4,y4);
line(x4,y4,a,b);
line(a,b,x,y);
outtextxy(x+50,y+30,"After rotation transformation");
getch();
closegraph();
}
4 . Implement DDA line drowing algorithm
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void DDA(int x1,int y1,int x2,int y2);
void main()
{
int gd=DETECT,gm;
int x1,x2,y1,y2;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("\nEnter the co-ordinate of point 1:");
scanf("%d%d",&x1,&y1);
printf("\nEnter the co-ordinate of point 2:");
scanf("%d%d",&x2,&y2);
DDA(x1,y1,x2,y2);
getch();
closegraph();
}
void DDA(int x1,int y1,int x2,int y2)
{
int length,i;
float x,y,xinc,yinc;
length=abs(x2-x1);
if(abs(y2-y1)>length)
{
length=abs(y2-y1);
}
xinc=(x2-x1)/length;
yinc=(y2-y1)/length;
x=x1+0.5;
y=y1+0.5;
for(i=1;i<=length;i++)
{
putpixel(x,y,5);
x=x+xinc;
y=y+yinc; }}
2. program to implement Bresenham's Line Drawing Algorithm.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void DDA(int x1,int y1,int x2,int y2);
void main()
{
int gd=DETECT,gm,errorcode;
int x1,x2,y1,y2;
initgraph(&gd,&gm,"C:\\TC\\BGI");
printf("\nEnter the coordinate of point 1:");
scanf("%d%d",&x1,&y1);
printf("\nEnter the coordinate of point 2:");
scanf("%d%d",&x2,&y2);
DDA(x1,y1,x2,y2);
getch();
closegraph();
}
void DDA(int x,int y,int x2,int y2)
{
int i,e,deltax,deltay;
deltax=x2-x;
deltay=y2-y;
e=2*deltay-deltax;
for(i=1;i<=deltax;i++)
{
putpixel(x,y,15);
if(e>0)
{
y=y+1;
e=e+(2*deltay-2*deltax);
}
else
{
e=e+2*deltay;
}
x=x+1;
}
}
3.Program to implement Bresenham's Circle Drawing Algorithm.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x,y,r;
float x1,y1,p;
clrscr();
initgraph(&gd,&gm,"c:\\turboc4\\tc\\bgi");
printf("Enter the radius:");
scanf("%d",&r);
x=getmaxx()/2;
y=getmaxy()/2;
x1=0,y1=r;
p=3-(2*r);
while(x1<=y1)
{
x1=x1+0.1;
if(p<0)
{
p=p+(4*x1)+6;
}
else
{
y1=y1-0.1;
p=p+(4*(x1-y1))+10;
}
putpixel(x+x1,y+y1,10);
putpixel(x-x1,y-y1,10);
putpixel(x+x1,y-y1,10);
putpixel(x-x1,y+y1,10);
putpixel(x+y1,y+x1,10);
putpixel(x-y1,y-x1,10);
putpixel(x+y1,y-x1,10);
putpixel(x-y1,y+x1,10);
}
getch();
closegraph();
}

You might also like