Graphics Practical
Graphics Practical
CERTIFICATE
This is certify that Mr. / Miss_______________________________ of T.Y.BSc.
Student Seat No. ___________ from G.T.Patil College, Nandurbar has Satisfactory completed
his/her practical in the course of Computer Science as per syllabus in academic year 2018-2019.
Place:-
Date:-
VB.NET
1 Write a VB.Net Program to demonstrate Array.
2 Write a Window based application to find maximum of three
numbers
3 Write a Window based application to find factorial of a given
numbers.
4 Write a Window based application for Armstrong numbers
5 Write a VB.Net Program to demonstrate Exception handling.
6 Write a VB.Net Program to demonstrate Constructor.
7 Write a VB.Net Program to demonstrate Single Inheritance.
8 Write a VB.Net Program to demonstrate Interface.
9 Write a VB.Net Program to demonstrate Polymorphism.
10 Design GUI and write Code for the following in VB.Net
(ADO.Net) without wizard: Accept employee details like emp_no,
emp_name, emp_age and save these details in emp_TBL.
initgraph
Syntax
#include <graphics.h>
Description
initgraph initializes the graphics system by loading a graphics driver from disk (or
validating a registered driver), and putting the system into graphics mode.
To start the graphics system, first call the initgraph function. initgraph loads the graphics
driver and puts the system into graphics mode. You can tell initgraph to use a particular
graphics driver and mode, or to autodetect the attached video adapter at run time and pick
the corresponding driver.
If you tell initgraph to autodetect, it calls detectgraph to select a graphics driver and mode.
initgraph also resets all graphics settings to their defaults (current position, palette, color,
viewport, and so on) and resets graphresult to 0.
*graphmode is an integer that specifies the initial graphics mode (unless *graphdriver
equals DETECT; in which case, *graphmode is set by initgraph to the highest resolution
available for the detected driver).
pathtodriver specifies the directory path where initgraph looks for graphics drivers.
initgraph first looks in the path specified in pathtodriver, then (if they are not there) in the
current directory. Accordingly, if pathtodriver is null, the driver files (*.BGI) must be in the
current directory.
/* Program to draw block diagram of Computer */
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm=DETECT;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
outtextxy(180,370,"Figure:- Block Diagram of Computer");
rectangle(20,200,120,250);
outtextxy(50,220,"Input");
line(120,225,220,225);
outtextxy(212,222,">");
rectangle(220,100,420,350);
rectangle(240,120,400,160);
outtextxy(300,135,"ALU");
line(300,160,300,200);
outtextxy(293,194,"\\/");
line(340,160,340,200);
outtextxy(333,160,"/\\");
rectangle(240,200,400,240);
outtextxy(300,220,"Memory");
line(300,240,300,280);
outtextxy(293,274,"\\/");
line(340,240,340,280);
outtextxy(333,240,"/\\");
rectangle(240,280,400,320);
outtextxy(300,300,"CU");
line(420,225,520,225);
outtextxy(512,222,">");
rectangle(520,200,620,250);
outtextxy(550,220,"output");
getch();
}
/* Prgram to Display the FLAG of India */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gi,gd;
int i,j;
gd=DETECT;
gm=DETECT;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setfillstyle(1,23);
bar(200,50,210,450);
setfillstyle(1,6);
bar(210,50,440,110);
setfillstyle(1,WHITE);
bar(210,110,440,170);
setfillstyle(1,GREEN);
bar(210,170,440,230);
setlinestyle(SOLID_LINE,1,NORM_WIDTH);
setcolor(1);
circle(325,140,20);
line(325,120,325,160);
line(315,121,335,158);
line(335,121,315,158);
line(305,140,345,140);
line(306,130,343,150);
line(306,150,343,130);
getch();
}
/* Program to display the various Symbols used in Flow charts */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm=DETECT;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
line(10,10,130,10);
line(10,40,130,40);
arc(15,25,90,270,15);
arc(125,25,270,90,15);
outtextxy(20,20,"Start / Stop");
rectangle(10,60,130,90);
outtextxy(15,70,"Initialization");
line(65,110,10,150);
line(65,110,120,150);
line(65,190,10,150);
line(65,190,120,150);
outtextxy(25,145,"Condition");
line(30,210,130,210);
line(10,230,110,230);
line(30,210,10,230);
line(130,210,110,230);
outtextxy(50,215,"Loop");
circle(65,270,20);
line(65,290,65,310);
circle(115,290,20);
line(115,250,115,270);
outtextxy(145,270,"Connecter");
line(10,350,130,350);
line(10,350,30,360);
line(10,350,30,340);
outtextxy(145,350,"Arrow");
getch();
}
/* Program to draw a line using Bresnham's Algorithm */
# include <stdio.h>
# include <conio.h>
# include <graphics.h>
void main()
{
int dx,dy,x,y,p,x1,y1,x2,y2;
int gd=DETECT;
int gm=DETECT;
initgraph(&gd,&gm,"c:\\tc\\bgi");
dx = (x2 - x1);
dy = (y2 - y1);
p = 2 * (dy) - (dx);
x = x1;
y = y1;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"e:\\tc\\bgi");
putpixel(x,y,WHITE);
}
/* Program for Bresenham's Circle Drawing Algorithm */
# include<stdio.h>
# include<conio.h>
# include<graphics.h>
# include<math.h>
void main()
{
int gd=DETECT,gm;
int r,x,y,p,xc=320,yc=240;
initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();
x=0;
y=r;
putpixel(xc+x,yc-y,1);
p=3-(2*r);
for(x=0;x<=y;x++)
{
if (p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;
p=p+((4*(x-y)+10));
}
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,8);
}
getch();
closegraph();
}
/* Prgoram for the line Drawing using DDA Algorithm */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<ctype.h>
#include<math.h>
#include<stdlib.h>
void draw(int x1,int y1,int x2,int y2);
void main()
{
int x1,y1,x2,y2;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\n Enter the x and y value for starting point: \n");
scanf("%d%d",&x1,&y1);
printf("\n Enter the x and y value for ending point: \n");
scanf("%d%d",&x2,&y2);
printf("\n The Line is shown below: \n");
draw(x1,y1,x2,y2);
getch();
}
void draw(int x1,int y1,int x2,int y2)
{
float x,y,xinc,yinc,dx,dy;
int k;
int step;
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
step=abs(dx);
else
step=abs(dy);
xinc=dx/step;
yinc=dy/step;
x=x1;
y=y1;
putpixel(x,y,1);
for(k=1;k<=step;k++)
{
x=x+xinc;
y=y+yinc;
putpixel(x,y,2);
}
}
/*Implementing translation, scaling and rotation transformation on
polygons with respect to any point. */
void draw();
void tri();
void main() {
int gd = DETECT, gm;
int c;
initgraph(&gd, &gm, "c:\\tc\\bgi ");
printf("Enter the 1st point for the triangle:");
scanf("%d%d", &x1, &y1);
printf("Enter the 2nd point for the triangle:");
scanf("%d%d", &x2, &y2);
printf("Enter the 3rd point for the triangle:");
scanf("%d%d", &x3, &y3);
cleardevice();
draw();
getch();
tri();
getch();
}
void draw() {
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
}
void tri() {
int x, y, a1, a2, a3, b1, b2, b3;
printf("Enter the Translation coordinates");
scanf("%d%d", &x, &y);
cleardevice();
a1 = x1 + x;
b1 = y1 + y;
a2 = x2 + x;
b2 = y2 + y;
a3 = x3 + x;
b3 = y3 + y;
line(a1, b1, a2, b2);
line(a2, b2, a3, b3);
line(a3, b3, a1, b1);
}
/*prog for scaling*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>
#include<math.h>
void draw();
void scale();
void main() {
int gd = DETECT, gm=DETECT;
initgraph(&gd, &gm, "c:\\tc\\bgi");
printf("Enter the 1st point for the triangle:");
scanf("%d%d", &x1, &y1);
printf("Enter the 2nd point for the triangle:");
scanf("%d%d", &x2, &y2);
printf("Enter the 3rd point for the triangle:");
scanf("%d%d", &x3, &y3);
draw();
scale();
}
void draw() {
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
}
void scale() {
int x, y, a1, a2, a3, b1, b2, b3;
int mx, my;
mx = (x1 + x2 + x3) / 3;
my = (y1 + y2 + y3) / 3;
cleardevice();
a1 = mx + (x1 - mx) * x;
b1 = my + (y1 - my) * y;
a2 = mx + (x2 - mx) * x;
b2 = my + (y2 - my) * y;
a3 = mx + (x3 - mx) * x;
b3 = my + (y3 - my) * y;
void TriAngle(int x1, int y1, int x2, int y2, int x3, int y3);
void Rotate(int x1, int y1, int x2, int y2, int x3, int y3);
void main() {
int gd = DETECT, gm=DETECT;
int x1, y1, x2, y2, x3, y3;
initgraph(&gd, &gm, "c:\\tc\\bgi");
void TriAngle(int x1, int y1, int x2, int y2, int x3, int y3) {
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
}
void Rotate(int x1, int y1, int x2, int y2, int x3, int y3) {
int x, y, a1, b1, a2, b2, a3, b3, p = x2, q = y2;
float Angle;
printf("Enter the angle for rotation:");
scanf("%f", &Angle);
cleardevice();
Angle = (Angle * 3.14) / 180;
a1 = p + (x1 - p) * cos(Angle)-(y1 - q) * sin(Angle);
b1 = q + (x1 - p) * sin(Angle)+(y1 - q) * cos(Angle);
a2 = p + (x2 - p) * cos(Angle)-(y2 - q) * sin(Angle);
b2 = q + (x2 - p) * sin(Angle)+(y2 - q) * cos(Angle);
a3 = p + (x3 - p) * cos(Angle)-(y3 - q) * sin(Angle);
b3 = q + (x3 - p) * sin(Angle)+(y3 - q) * cos(Angle);
printf("Rotate");
TriAngle(a1, b1, a2, b2, a3, b3);
}
//cohen-sutherland
#include<stdio.h>
#include<graphics.h>
//#include<process.h>
void main()
{
float i,xmax,ymax,xmin,ymin,x11,y11,x22,y22,m;
float a[4],b[4],c[4],x1,y1;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\nEnter the bottom-left coordinate of viewport: ");
scanf("%f %f",&xmin,&ymin);
printf("\nEnter the top-right coordinate of viewport: ");
scanf("%f %f",&xmax,&ymax);
rectangle(xmin,ymin,xmax,ymax);
printf("\nEnter the coordinates of 1st end point of line: ");
scanf("%f %f",&x11,&y11);
printf("\nEnter the coordinates of 2nd endpoint of line: ");
scanf("%f %f",&x22,&y22);
line(x11,y11,x22,y22);
//initgraph(&gd,&gm,"c:\\tc\\bin");
for(i=0;i<4;i++)
{
a[i]=0;
b[i]=0;
}
m=(y22-y11)/(x22-x11);
if(x11<xmin) a[3]=1;
if(x11>xmax) a[2]=1;
if(y11<ymin) a[1]=1;
if(y11>ymax) a[0]=1;
if(x22<xmin) b[3]=1;
if(x22>xmax) b[2]=1;
if(y22<ymin) b[1]=1;
if(y22>ymax) b[0]=1;
printf("\nRegion code of 1st pt ");
for(i=0;i<4;i++)
{printf("%f",a[i]);}
printf("\nRegion code of 2nd pt ");
for(i=0;i<4;i++)
{printf("%f",b[i]);}
printf("\nAnding : ");
for(i=0;i<4;i++)
{c[i]=a[i]&&b[i];}
for(i=0;i<4;i++)
printf("%f",c[i]);
getch();
if((c[0]==0)&&(c[1]==0)&&(c[2]==0)&&(c[3]==0))
{
if((a[0]==0)&&(a[1]==0)&&(a[2]==0)&&(a[3]==0)&&
(b[0]==0)&&(b[1]==0)&&(b[2]==0) &&(b[3]==0))
{
clrscr();
clearviewport();
printf("\nThe line is totally visible \nand not a clipping
candidate");
rectangle(xmin,ymin,xmax,ymax);
line(x11,y11,x22,y22);
getch();
}
else
{
clrscr();
clearviewport();
printf("\nLine is partially visible");
rectangle(xmin,ymin,xmax,ymax);
line(x11,y11,x22,y22);
getch();
if((a[0]==0)&&(a[1]==1))
{
x1=x11+(ymin-y11)/m;
x11=x1;
y11=ymin;
}
else if((b[0]==0)&&(b[1]==1))
{
x1=x22+(ymin-y22)/m;
x22=x1;
y22=ymin;
}
if((a[0]==1)&&(a[1]==0))
{
x1=x11+(ymax-y11)/m;
x11=x1; y11=ymax;
}
else if((b[0]==1)&&(b[1]==0))
{
x1=x22+(ymax-y22)/m;
x22=x1; y22=ymax;
}
if((a[2]==0)&&(a[3]==1))
{
y1=y11+m*(xmin-x11);
y11=y1; x11=xmin;
}
else if((b[2]==0)&&(b[3]==1))
{
y1=y22+m*(xmin-x22);
y22=y1;
x22=xmin;
}
if((a[2]==1)&&(a[3]==0))
{
y1=y11+m*(xmax-x11);
y11=y1; x11=xmax;
}
else if((b[2]==1)&&(b[3]==0))
{
y1=y22+m*(xmax-x22);
y22=y1;
x22=xmax;
}
clrscr();
clearviewport();
printf("\nAfter clippling:");
rectangle(xmin,ymin,xmax,ymax);
line(x11,y11,x22,y22);
getch();
}
}
else
{
clrscr();
clearviewport();
printf("\nLine is invisible");
rectangle(xmin,ymin,xmax,ymax);
getch();
}
closegraph();
getch();
}