SlideShare a Scribd company logo
Programming Laboratory (210251)
Index
Batch: C1 & C2
Title Date Sign
Group A
1.
Writing a C++ Program to emulate CPU Architecture (Central
Bus) Develop register, ALU level GUI to display results.
2. Writing a C++ class for displaying pixel or point on the screen.
3.
Write a C++ class for a Line drawing method using overloading
DDA and Bresenham’s Algorithms, inheriting the pixel or point.
4. Write a C++ class for a circle drawing inheriting line class.
Group B
1.
Write a program in C++ to draw a line with line style (Thick,
Thin, Dotted).
2. Write a program in C++ to draw a circle of desired radius.
3.
Write a C++ program to draw convex polygons (Square,
Rectangle, Triangle).
4.
Write a program in C++ to test that given point is inside the
polygon.
5. Write a C++ program to fill polygon using scan line algorithm.
6.
Write a Java program to draw a line with line style (Thick, Thin,
Dotted).
Group C
1. Use Maya to draw a Bouncing ball animation.
Programming Laboratory (210251)
Title: Writing a C++ Program to emulate CPU Architecture (Central Bus) Develop register,
ALU level GUI to display results.
Aim: To understand the working of CPU architecture, perform some arithmetic operation using
ALU and display results.
C++ code:
#include<string.h>
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<stdio.h>
class computer
{
int c1;
int j;
char n1[5],n2[5];
char *d1;
int a1,b1;
char a[5];
int poly[20];
public:
computer()
{ j=0;
}
void biu();
void alu();
void flags();
void registers();
void segments();
void buses();
void exp1();
void display();
};
void computer::biu()
{
rectangle(300,20,600,470); //CPU
poly[]={340,35,335,100,355,100,360,70,395,100,415,100,410,35,340,35};//draw CPU polygon
setfillstyle(1,RED);
char ope[2];
2
Programming Laboratory (210251)
ope[0]=a[2];
ope[1]='0';
outtextxy(340,45,"Operation");
outtextxy(370,60,ope);
}
void computer::segments()
{
rectangle(320,130,420,230); //segments
for(int k=1;k<5;k++)
{ int a=320;
int b=130+20*k;
int c= 420;
int d=130+20*k;
line(a,b,c,d);
}
outtextxy(330,133,"ES=0000h");
outtextxy(330,153,"DS=0000h");
outtextxy(330,173,"CS:0000h");
outtextxy(330,193,"IP:0001h");
outtextxy(330,213,"DI:ALU");
rectangle(480,28,560,50); //memory interface
outtextxy(494,38,"Memory ");
rectangle(480,80,540,180); // instn queue
for(k=1;k<5;k++)
{ int a=480;
int b=80+20*k;
int c= 540;
int d=80+20*k;
line(a,b,c,d);
}
outtextxy(510,167,"1");
outtextxy(546,100,"Instruction");
outtextxy(546,115,"Queue");
rectangle(470,220,550,240); //control sys
outtextxy(480,222,"Program Counter");
}
void computer::registers()
{
rectangle(320,310,420,450); //registers
for(int k=1;k<8;k++)
{ int a=320;
int b=310+20*k;
int c= 420;
int d=310+20*k;
line(a,b,c,d);
3
Programming Laboratory (210251)
outtextxy(304,312,"AX");
outtextxy(304,332,"BX");
outtextxy(304,352,"CX");
outtextxy(304,372,"DX");
outtextxy(330,394,"SP=0001h");
outtextxy(330,414,"BP=0000h");
outtextxy(367,434,"FLAG");
}
}
void computer::alu()
{
outtextxy(490,320,"ALU");
int poly2[]={450,330,470,390,530,390,550,330,530,330,520,350,480,350,470,330,450,330};
drawpoly(9,poly2);
fillpoly(1,poly2);
}
void computer::flags()
{
rectangle(440,410,540,450); //flags
line(440,430,540,430);
for(int k=1;k<8;k++)
{ int a=440+12.5*k;
int b=410;
int c= 440+12.5*k;
int d=450;
line(a,b,c,d);
}
outtextxy(443,420,"-");
outtextxy(456,420,"-");
outtextxy(469,420,"-");
outtextxy(482,420,"-");
outtextxy(494,420,"O");
outtextxy(507,420,"D");
outtextxy(520,420,"I");
outtextxy(533,420,"T");
outtextxy(443,437,"S");
outtextxy(456,437,"Z");
outtextxy(469,437,"-");
outtextxy(482,437,"A");
outtextxy(494,437,"-");
outtextxy(507,437,"P");
outtextxy(520,437,"-");
outtextxy(533,437,"C");
char l=a[2];
switch(l)
4
Programming Laboratory (210251)
{
case '+': setfillstyle(1,RED);
floodfill(538,448,15); //carry
setfillstyle(1,RED);
floodfill(512,442,15); //parity
setfillstyle(1,RED);
floodfill(489,443,15); //auxill
setfillstyle(1,RED);
floodfill(492,424,15); //over
break;
case '-': setfillstyle(1,BLUE);
floodfill(441,441,15); //sign
setfillstyle(1,BLUE);
floodfill(454,441,15) ; //zero
setfillstyle(1,BLUE);
floodfill(538,448,15);
setfillstyle(1,BLUE);
floodfill(512,442,15);
break;
case '*': setfillstyle(1,GREEN);
floodfill(454,441,15) ;
setfillstyle(1,GREEN);
floodfill(489,443,15);
setfillstyle(1,GREEN);
floodfill(538,448,15);
setfillstyle(1,GREEN);
floodfill(512,442,15);
break;
case '/': setfillstyle(1,BROWN);
floodfill(454,441,15) ;
setfillstyle(1,BROWN);
floodfill(489,443,15);
setfillstyle(1,BROWN);
floodfill(538,448,15);
setfillstyle(1,BROWN);
floodfill(512,442,15);
break;
}
}
void computer::buses()
{
setcolor(10);
line(420,40,470,40);
line(470,40,460,37);
line(470,40,460,43);
5
Programming Laboratory (210251)
delay(500);
line(510,55,510,75);
line(510,75,505,72);
line(510,75,515,72);
delay(500);
line(510,185,510,210);
line(510,210,505,206);
line(510,210,515,206);
delay(500);
setcolor(15);
int
poly1[]={340,260,340,280,455,280,455,290,460,310,470,290,465,290,465,280,535,280,535,290,
540,310,550,290,545,290,545,280,570,280,570,440,590,440,590,260,340,260};
setfillstyle(8,RED);
fillpoly(21,poly1);
delay(1000);
setcolor(10);
line(540,360,570,360);
line(570,360,560,350);
line(570,360,560,370);
delay(1000);
line(490,390,490,410);
line(490,410,487,405);
line(490,410,493,405);
delay(1000);
line(540,430,570,430);
line(540,430,543,425);
line(540,430,543,435);
line(570,430,568,425);
line(570,430,568,435);
setcolor(15);
}
void computer::exp1()
{
cout<<"n Enter expression:";
for(int i=0;i<3;i++)
{
cin>>a[i];
}
a[3]='0';
i=0;
while(isdigit(a[i]))
{ n1[i]=a[i];
i++;
}
6
Programming Laboratory (210251)
n1[i]='0';
i=2;
while(isdigit(a[i]))
{ n2[j]=a[i];
i++;
j++;
}
n2[j]='0';
a1= atoi(n1);
b1=atoi(n2);
if(a[1]=='+')
c1=a1+b1;
else if(a[1]=='-')
c1=a1-b1;
else if(a[1]=='*')
c1=a1*b1;
else if(a[1]=='/')
c1=a1/b1;
else if(a[1]=='%')
c1=a1%b1;
else
cout<<"n Enter correctly:";
}
void computer:: display()
{
outtextxy(324,313,n1);
outtextxy(324,333,n2);
char n3[2];
n3[0]='=';
n3[1]='0';
char n4[50];
itoa(a1,n1,2);
itoa(b1,n2,2);
outtextxy(340,313,strcat("=",n1));
outtextxy(340,333,n3);
outtextxy(346,333,n2);
itoa(c1,n4,2);
outtextxy(322,373,n4);
outtextxy(480,365,n4);
flushall();
char v[20];
itoa(c1,v,10);
outtextxy(72,130,v);
}
void main()
7
Programming Laboratory (210251)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:tcbgi");
computer c;
c.exp1();
delay(500);
c.biu();
delay(500);
c.segments();
delay(500);
c.registers();
delay(500);
c.display();
delay(500);
c.alu();
delay(500);
c.flags();
delay(500);
c.buses();
getch();
}
Graphics function used:
1. outtextxy
2. line
3. rectangle
4. drawpoly
5. fillpoly
6. setfillstyle
7. floodfill
Output:
Title: Writing a C++ class for displaying pixel or point on the screen.
8
Programming Laboratory (210251)
Aim: To understand, how to display pixel on screen.
C++ Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
class pixel
{
public:
int x,y;
void disp(int,int);
};
void pixel::disp(int p,int q)
{
putpixel(p,q,WHITE);
}
void main()
{
class pixel p;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:tcplusbgi");
cout<<"Enter position of pixel";
cin>>p.x>>p.y;
p.disp(p.x,p.y);
getch();
}
Output:
9
Programming Laboratory (210251)
Title: Write a C++ class for a Line drawing method using overloading DDA and Bresenham’s
Algorithms, inheriting the pixel or point.
DDA Line Drawing Algorithm:
Bresenham’s Line Drawing Algorithm:
10
Programming Laboratory (210251)
C++ Code for DDA Line Drawing Algorithm:
#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>
class line
{
public:
int x1,y1,x2,y2;
void drawl(int,int,int,int);
};
void line::drawl(int x1,int y1,int x2,int y2)
{
int i=1,dx,dy,step,x,y;
float xinc,yinc;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx<=dy)
{
step=dy;
}
else
{step=dx;}
xinc=dx/step;
yinc=dy/step;
x=x1;y=y1;
putpixel(x,y,WHITE);
while(i<=step)
{
x=x+xinc+0.5;
y=y+yinc+0.5;i++;
putpixel(x,y,WHITE);
}
}
void main()
{
class line l;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:tcbgi");
cout<<"Enter coordinates of end points";
cin>>l.x1>>l.y1>>l.x2>>l.y2;
l.drawl(l.x1,l.y1,l.x2,l.y2);
getch();
}
11
Programming Laboratory (210251)
Output:
C++ Code for Bresenham’s Line Drawing Algorithm:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
class line
{
public:
int x1,y1,x2,y2;
void drawl(int,int,int,int);
};
void line::drawl(int x1,int y1,int x2,int y2)
{
int dx=x2-x1,dy=y2-y1,di=2*dx-dy,ds=2*dy,dt=2*(dy-dx);
putpixel(x1,y1,WHITE);
while(x1<=x2)
{
x1++;
if(di<0)
{di+=ds;}
else
{
y1++;
di+=dt;
}
putpixel(x1,y1,WHITE);
}
}
void main()
{
class line l;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:tcbgi");
cout<<"Enter coordinates of end points x1,y1,x2,y2";
cin>>l.x1>>l.y1>>l.x2>>l.y2;
l.drawl(l.x1,l.y1,l.x2,l.y2);
getch();
}
Output:
12
Programming Laboratory (210251)
Title: Write a C++ class for a circle drawing inheriting line class.
C++ Code:
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
class linep //line class
{
public:
int x1,y1,x2,y2;
};
class circle:public linep //circle class inherit from linep class
{
public:
void disp(int,int,int);
};
void circle::disp(int x,int y,int r)
{
int p,x1,y1;
x1=0;
y1=r;
p=3-r;
while(x1<=y1)
{
if(p<0)
{
x1++;
p+=4*x1+6;
}
else
{
x1++;y1--;
p+=4*(x1-y1)+10;
}
putpixel(x1+x,y1+y,1);
putpixel(x1+x,y-y1,1);
putpixel(x-x1,y1+y,1);
putpixel(x-x1,y-y1,1);
putpixel(x+y1,y+x1,1);
putpixel(x+y1,y-x1,1);
putpixel(x-y1,y+x1,1);
putpixel(x-y1,y-x1,1);
}
13
Programming Laboratory (210251)
}
void main()
{
class circle c;
class linep p;
int gd=DETECT,gm,r;
initgraph(&gd,&gm,"C:tcbgi");
cout<<"Enter radius of circle";
cin>>r;
cout<<"Enter co-ordinates of circle";
cin>>p.x2>>p.y2;
c.disp(p.x2,p.y2,r);
getch();
}
Output:
14
Programming Laboratory (210251)
Title: Write a program in C++ to draw a line with line style (Thick, Thin, Dotted).
C++ code:
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
class linep
{
public:
int x1,y1,x2,y2;
void drawl(int,int,int,int);
void thick(int,int,int,int,int);
void dotted(int,int,int,int);
};
void linep::thick(int x1,int y1,int x2,int y2,int w)
{
int i,dx,dy,step,xinc,yinc;
dx=x2-x1;
dy=y2-y1;
if(dy>=dx)
{
step=dy;
}
else
{
step=dx;
}
xinc=dx/step;
yinc=dy/step;
while(x1<=x2)
{
x1=x1+xinc+0.5;
y1=y1+yinc+0.5;
for(i=0;i<w;i++)
{
putpixel(x1+i,y1,WHITE);
}
}
}
void linep::drawl(int x1,int y1,int x2,int y2)
{
int dx,dy,step,xinc,yinc;
dx=x2-x1;
dy=y2-y1;
if(dy>=dx)
15
Programming Laboratory (210251)
{
step=dy;
}
else
{
step=dx;
}
xinc=dx/step;
yinc=dy/step;
putpixel(x1,y1,WHITE);
while(x1<=x2)
{
x1=x1+xinc+0.5;
y1=y1+yinc+0.5;
putpixel(x1,y1,WHITE);
}
}
void linep::dotted(int x1,int y1,int x2,int y2)
{
int i=0,dx,dy,step,xinc,yinc;
dx=x2-x1;
dy=y2-y1;
if(dy>=dx)
{
step=dy;
}
else
{
step=dx;
}
xinc=dx/step;
yinc=dy/step;
putpixel(x1,y1,WHITE);
while(x1<=x2)
{
if(i%2==0)
{
putpixel(x1,y1,WHITE);
}
x1=x1+xinc+0.5;
y1=y1+yinc+0.5;
i++;
}
}
void main()
16
Programming Laboratory (210251)
{
class linep p;
int gd=DETECT,gm,n,i,w;
initgraph(&gd,&gm,"C:TCbgi");
cout<<"Enter co-ordinates of line x1,y1,x2,y2";
cin>>p.x1>>p.y1>>p.x2>>p.y2;
cout<<"Enter your choice 1. Thin Line 2. Thick line 3. Dotted line";
cin>>i;
switch(i)
{
case 1: p.drawl(p.x1,p.y1,p.x2,p.y2); break;
case 2:
cout<<"Enter width of line in pixel";
cin>>w;
p.thick(p.x1,p.y1,p.x2,p.y2,w); break;
case 3: p.dotted(p.x1,p.y1,p.x2,p.y2); break;
default:
cout<<"Enter proper choice";
}
getch();
}
Output:
17
Programming Laboratory (210251)
Title: Write a program in C++ to draw a circle of desired radius.
C++ Code:
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
void display(int,int,int,int);
void main()
{
int p,gd=DETECT,gm,x1,y1,x,y,r;
initgraph(&gd,&gm,"c :tcbgi");
cout<<"Enter radius of circle";
cin>>r;
cout<<"Enter co-ordinates of circle";
cin>>x>>y;
x1=0;
y1=r;
p=3-r;
while(x1<=y1)
{
if(p<0)
{
x1++;
p+=4*x1+6;
}
else
{
x1++;y1--;
p+=4*(x1-y1)+10;
}
display(x1,y1,x,y);
}
getch();
}
void display(int x1,int y1,int x,int y)
{
putpixel(x1+x,y1+y,1);
putpixel(x1+x,y-y1,1);
putpixel(x-x1,y1+y,1);
putpixel(x-x1,y-y1,1);
putpixel(x+y1,y+x1,1);
putpixel(x+y1,y-x1,1);
putpixel(x-y1,y+x1,1);
putpixel(x-y1,y-x1,1);
18
Programming Laboratory (210251)
}
Output:
19
Programming Laboratory (210251)
Title: Write a C/C++ program to draw convex polygons (Square, Rectangle, and Triangle).
C++ Code:
#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>
class line
{
public:
int x1,y1,x2,y2;
void drawl(int,int,int,int);
};
void line::drawl(int x1,int y1,int x2,int y2)
{
int i=1,dx,dy,step,x,y;
float xinc,yinc;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx<=dy)
{
step=dy;
}
else
{step=dx;}
xinc=dx/step;
yinc=dy/step;
x=x1;y=y1;
while(i<=step)
{
x=x+xinc+0.5;
y=y+yinc+0.5;i++;
putpixel(x,y,WHITE);
}
}
void main()
{
int i,x1,y1,x2,y2,gd=DETECT,gm,len,wid,size, base,height;
initgraph(&gd,&gm,"c:tcbgi");
class line l;
cout<<"Enter value of x1,y1";
cin>>x1>>y1;
cout<<"Enter your choice 1. Rectangle 2. Square 3. Triangle";
cin>>i;
20
Programming Laboratory (210251)
switch(i)
{
case 1:
cout<<"Enter length & Width of Rectangle";
cin>>len>>wid;
x2=x1+wid;
y2=y1;
l.drawl(x1,y1,x2,y2);
x1=x1+wid;
y1=y2;
y2=y2+len;
x2=x1;
l.drawl(x1,y1,x2,y2);
x1=x2;
y1=y2;
x2=x2-wid;
y2=y2;
l.drawl(x2,y2,x1,y1);
x1=x2;
y1=y2;
x2=x1;
y2=y2-len;
l.drawl(x2,y2,x1,y1);
break;
case 2:
cout<<"Enter Size of Square";
cin>>size;
x2=x1+size;
y2=y1;
l.drawl(x1,y1,x2,y2);
x1=x1+size;
y1=y2;
y2=y2+size;
x2=x1;
l.drawl(x1,y1,x2,y2);
x1=x2;
y1=y2;
x2=x2-size;
y2=y2;
l.drawl(x2,y2,x1,y1);
x1=x2;
y1=y2;
x2=x1;
y2=y2-size;
l.drawl(x2,y2,x1,y1);
21
Programming Laboratory (210251)
break;
case 3:
int x3,y3;
cout<<"Enter base and height of triangle ";
cin>>base>>height;
x2=x1+base;
y2=y1;
l.drawl(x1,y1,x2,y2);
x3=x1;
y3=y1+height;
l.drawl(x1,y1,x3,y3);
l.drawl(x2,y2,x3,y3);
break;
default: cout<<"Enter correct choice";
}
getch();
}
Output:
22
Programming Laboratory (210251)
Title: Write a program in C++ to test that given point is inside the polygon (Rectangle).
C++ Code:
#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>
class line
{
public:
int x1,y1,x2,y2;
void drawl(int,int,int,int);
};
void line::drawl(int x1,int y1,int x2,int y2)
{
int i=1,dx,dy,step,x,y;
float xinc,yinc;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx<=dy)
{
step=dy;
}
else
{step=dx;}
xinc=dx/step;
yinc=dy/step;
x=x1;y=y1;
putpixel(x,y,WHITE);
while(i<=step)
{
x=x+xinc+0.5;
y=y+yinc+0.5;
i++;
putpixel(x,y,WHITE);
}
}
void main()
{
class line l;
int i,x1=100,y1=100,x2,y2,gd=DETECT,gm,len=50,wid=34,x,y;
initgraph(&gd,&gm,"c:tcbgi");
x2=x1+wid;
y2=y1;
23
Programming Laboratory (210251)
l.drawl(x1,y1,x2,y2);
x1=x1+wid;
y1=y2;
y2=y2+len;
x2=x1;
l.drawl(x1,y1,x2,y2);
x1=x2;
y1=y2;
x2=x2-wid;
y2=y2;
l.drawl(x2,y2,x1,y1);
x1=x2;
y1=y2;
x2=x1;
y2=y2-len;
l.drawl(x2,y2,x1,y1);
cout<<"Enter position of point";
cin>>x>>y;
if(((x<x1)&&(y<y1))||((x>x2)&&(y>y2)))
{
putpixel(x,y,BLUE);
cout<<"Point outside of the polgon";
}
else
{
cout<<"Point inside of the polgon";
}
getch();
}
Output:
24
Programming Laboratory (210251)
Title: Write a C++ program to fill polygon using scan line algorithm.
C++ Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
struct edge
{
int x1,y1,x2,y2,flag;
};
void main()
{
int n,i,j,k,gd=DETECT,gm, x[10],y[10],ymax=0,ymin=480,yy,temp;
struct edge ed[10],temped;
float dx,dy,m[10],x_int[10],inter_x[10];
initgraph(&gd,&gm,"c:tcbgi");
cout<<"n Enter the number of vertices of the graph: ";
cin>>n;
cout<<"n Enter the co-ordinates of vertices: n";
for(i=0;i<n;i++)
{
cout<<"x"<<i;
cin>>x[i]>>endl;
cout<<"y"<<i;
cin>>y[i]>>endl;
if(y[i]>ymax)
ymax=y[i];
if(y[i]<ymin)
ymin=y[i];
ed[i].x1=x[i];
ed[i].y1=y[i];
}
for(i=0;i<n-1;i++) //store the edge information
{
ed[i].x2=ed[i+1].x1;
ed[i].y2=ed[i+1].y1;
ed[i].flag=0;
}
ed[i].x2=ed[0].x1;
ed[i].y2=ed[0].y1;
ed[i].flag=0;
for(i=0;i<n-1;i++) //check for y1>y2 if not then interchange it
{
25
Programming Laboratory (210251)
if(ed[i].y1<ed[i].y2)
{
temp=ed[i].x1;
ed[i].x1=ed[i].x2;
ed[i].x2=temp;
temp=ed[i].y1;
ed[i].y1=ed[i].y2;
ed[i].y2=temp;
}
}
for(i=0;i<n;i++) //draw polygon
{
line(ed[i].x1,ed[i].y1,ed[i].x2,ed[i].y2);
}
for(i=0;i<n-1;i++) //storing the edges as y1,y2,x1
{
for(j=0;j<n-1;j++)
{
if(ed[j].y1<ed[j+1].y1)
{
temped=ed[j];
ed[j]=ed[j+1];
ed[j+1]=temped;
}
if(ed[j].y1==ed[j+1].y1)
{
if(ed[j].y2<ed[j+1].y2)
{
temped=ed[j];
ed[j]=ed[j+1];
ed[j+1]=temped;
}
if(ed[j].y2==ed[j+1].y2)
{
if(ed[j].x1<ed[j+1].x1)
{
temped=ed[j];
ed[j]=ed[j+1];
ed[j+1]=temped;
}
}
}
}
}
26
Programming Laboratory (210251)
for(i=0;i<n;i++) //calculate 1/slope
{
dx=ed[i].x2-ed[i].x1;
dy=ed[i].y2-ed[i].y1;
if(dy==0)
m[i]=0;
else
m[i]=dx/dy;
inter_x[i]=ed[i].x1;
}
yy=ymax;
while(yy>ymin) //Mark active edges
{
for(i=0;i<n;i++)
{
if(yy>ed[i].y2 && yy<=ed[i].y1 && ed[i].y1!=ed[i].y2)
ed[i].flag=1;
else
ed[i].flag=0;
}
j=0;
for(i=0;i<n;i++) //Finding x intersections
{
if(ed[i].flag==1)
{
if(yy==ed[i].y1)
{
x_int[j]=ed[i].x1;
j++;
if(ed[i-1].y1==yy&&ed[i-1].y1<yy)
{
x_int[j]=ed[i].x1;
j++;
}
if(ed[i+1].y1==yy&&ed[i+1].y1<yy)
{
x_int[j]=ed[i].x1;
j++;
}
}
else
{
x_int[j]=inter_x[i]+(-m[i]);
inter_x[i]=x_int[j];
27
Programming Laboratory (210251)
j++;
}
}
}
for(i=0;i<j;i++) //sorting the x intersections
{
for(k=0;k<j-1;k++)
{
if(x_int[k]>x_int[k+1])
{
temp=x_int[k];
x_int[k]=x_int[k+1];
x_int[k+1]=temp;
}
}
}
for(i=0;i<j;i+=2) //Extracting x values to draw a line
{
line(x_int[i],yy,x_int[i+1],yy);
}
yy--;
}
delay(3000);
getch();
}
Output:
28
Programming Laboratory (210251)
Title: Write a Java program to draw a line with line style (Thick, Thin, Dotted).
JAVA Code:
import java.awt.*;
import javax.swing.*;
public class drawline extends JFrame{
public drawline(){
super("Lines");
setSize(400,400);
setVisible(true);
}
Stroke[] linestyles=new Stroke[]{
new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL),
new BasicStroke(25.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER),
new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND),};
Stroke thindashed=new
BasicStroke(2.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL,1.0f, new float[]
{8.0f,3.0f,2.0f,3.0f},0.0f);
final static float dash1[]={10.0f};
final static BasicStroke dashed =new BasicStroke(1.0f,
BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
final static float thick1[]={10.0f};
final static BasicStroke thickdash =new BasicStroke(10.0f,
BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER, 10.0f, thick1, 0.0f);
public void paint(Graphics g){
int xpoints[]={220,350,350,220};
int ypoints[]={220,220,320,320};
int npoints=4;
int xpoints1[]={60,120,180};
int ypoints1[]={320,220,320};
int npoints1=3;
Graphics2D g2d = (Graphics2D) g;
super.paint(g);
((Graphics2D)g).setStroke(dashed);
g.setColor(Color.black);
g2d.drawLine(50,50,200,50);
g2d.setColor(Color.black);
g.drawString("Dotted Line", 210,55);
((Graphics2D)g).setStroke(linestyles[3]);
g.setColor(Color.red);
g2d.drawLine(50,170,200,170);
g2d.setColor(Color.black);
g.drawString("Thin Line", 210,175);
29
Programming Laboratory (210251)
}
public static void main(String[] args){
Lines application = new Lines();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Steps for running this program:
1. Compilation of Program
C:Program FilesJavajdk1.7bin>javac drawline.java
2. Run the Program
C:Program FilesJavajdk1.7bin>java drawline
Output:
30
Programming Laboratory (210251)
Title: Use Maya to draw a Bouncing ball animation.
Introduction:
Maya 3D animation, modeling, simulation, rendering and compositing software offers a
comprehensive creative feature set for 3D computer animation, modeling, simulation and
rendering on a highly extensible production platform. Maya provides high-end character
and effects toolsets along with increased productivity for modeling, texturing and shade
creation tasks.
31
Programming Laboratory (210251)
C graphics using graphics.h functions or WinBGIM (Windows 7) can be used to draw different
shapes, display text in different fonts, change colors and many more. Using functions of
graphics.h in turbo C compiler you can make graphics programs, animations, projects and
games.
In a C/C++ Program first of all, we have to initialize the graphics drivers on the computer. This
is done using the initgraph method provided in graphics.h library.
Graphics mode Initialization:
First of all we have to call the initgraph function that will intialize the graphics mode on the
computer.
Prototype of initigraph:
void initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);
Initgraph initializes the graphics system by loading a graphics driver from disk (or validating a
registered driver) then putting the system into graphics mode. Initgraph also resets all graphics
settings (color, palette, current position, viewport, etc.) to their defaults, then resets graph result
to 0.
*graphdriver
Integer that specifies the graphics driver to be used. You can give graphdriver a value using a
constant of the graphics_drivers enumeration type.
*graphmode
Integer that specifies the initial graphics mode (unless *graphdriver = DETECT). If *graphdriver
= DETECT, initgraph sets *graphmode to the highest resolution available for the detected driver.
You can give *graphmode a value using a constant of the graphics_modes enumeration type.
*pathtodriver
Specifies the directory path where initgraph looks for graphics drivers (*.BGI) first.
1. If they’re not there, initgraph looks in the current directory.
2. If pathtodriver is null, the driver files must be in the current
directory.
*graphdriver and *graphmode must be set to valid graphics_drivers and graphics_mode values or
you’ll get unpredictable results. (The exception is graphdriver = DETECT.)
After a call to initgraph, *graphdriver is set to the current graphics driver, and *graphmode is set
to the current graphics mode. You can tell initgraph to use a particular graphics driver and mode,
32
Programming Laboratory (210251)
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.
Generally, initgraph loads a graphics driver by allocating memory for the driver (through
_graphgetmem), then loading the appropriate .BGI file from disk. As an alternative to this
dynamic loading scheme, you can link a graphics driver file directly into your executable
program file.
List of few functions from graphics.h file:
Name of Function
Circle Drawing circle
Arc Drawing arc
Screen getbkcolor, getcolor, setbkcolor, setcolor
Pixel getpixel, getx, gety, putpixel
Rectangle rectangle
Polygon drawpoly, fillpoly, floodfill
Line line, linerel, lineto
Text print outtextxy
getpixel(int x, int y);
putpixel(int x,int y, int color);
setbkcolor(BLUE);
getbkcolor(void);
setcolor(int color);
getcolor(void);
outtextxy function display text or string at a specified point(x,y) on the screen.
void outtextxy(int x, int y, char *string);
x, y are coordinates of the point and third argument contains the address of string to be
displayed.
line(int x1, int y1, int x2, int y2)
linerel(int dx,int dy): draw a line relative distance.
lineto(int x,int y): draw a line original point to x,y point.
rectangle(left,top,right,bottom)
circle(int x, int y, int radius)
33
Programming Laboratory (210251)
arc(int x,int y, int stangle, int endangle, int radius)
drawpoly(int numpoints, int far *polypoints);
setfillstyle(int pattern, int color);
EMPTY_FILL: 0, SOLID_FILL: 1
fillpoly(int numpoints, int far *polypoints);
fillpoly draws outline of polygon using current line style and color.
floodfill(int x,int y int border);
floodfill function is used to fill an enclosed area. Current fill pattern and fill color is used to fill
the area.(x, y) is any point on the screen if (x,y) lies inside the area then inside will be filled
otherwise outside will be filled, border specifies the color of boundary of area. To change fill
pattern and fill color use setfillstyle. Code given below draws a circle and then fills it.
Computer Graphics:
Computer graphics remains one of the most existing and rapidly growing computer fields.
Computer graphics may be defined as a pictorial representation or graphical representation of
objects in a computer.
Applications of computer graphics:
There are many interesting applications of computer graphics. Three common applications are
graphic user interface (GUI), computer-aided design (CAD), and computer games.
Major components (hardware and software) are needed for computer graphics:
Besides the basic computer, some special devices and software may be required especially for
computer graphics. For hardware, a special high-resolution, color monitor is often demanded and
some input tools, e.g. mouse and joy-sticker, and hard-copy devices, e.g. high-resolution color
printer, may be required. For software, some special purpose utilities (device-dependent and
device-independent) are needed for handling processing in computer graphics.
Random/Raster Scan:
Random scan is a method in which the display is made by the electronic beam, which is
directed, only to the points or part of the screen where the picture is to be drawn.
The Raster scan system is a scanning technique in which the electrons sweep from top to
bottom and from left to right. The intensity is turned on or off to light and unlight the pixel.
Refreshing of the screen:
Refreshing of screen is done by keeping the phosphorus glowing to redraw the picture
repeatedly. i.e. by quickly directing the electronic beam back to the same points.
34
Programming Laboratory (210251)
Aspect Ratio:
The ratio of vertical points to the horizontal points necessary to produce length of lines in both
directions of the screen is called Aspect Ratio. Usually the aspect ratio is ¾.
Addressability:
Addressability is the number of individual dots per inch (d.p.i.) that can be created. If the address
of the current dot is (x, y) then the next dot will be (x + y), (x + y + 1) etc.
Dot size:
The diameter of a single dot on the devices output.
Interdot distance:
Interdot distance is the reciprocal of addressability. If the addressability is large, the interdot
distance will be less. The interdot distance should be less to get smooth shapes.
C++:
Purpose of C++ programming was to add object orientation to the C programming language,
which is in itself one of the most powerful programming languages.
The core of the pure object-oriented programming is to create an object, in code, that has certain
properties and methods. While designing C++ modules, we try to see whole world in the form of
objects.
There are a few principle concepts that form the foundation of object-oriented
programming:
1. Object:
This is the basic unit of object oriented programming. That is both data and function that
operate on data are bundled as a unit called as object.
2. Class:
We define a blueprint for an object. This doesn't actually define any data, but it does
define what the class name means, that is, what an object of the class will consist of and
what operations can be performed on such an object.
There are three types of data members:
• Public
• Private
• Protected
Syntax:
class classname{
private: //by default data members are private
public:
protected:
}; // end of the Class
35
Programming Laboratory (210251)
3. Inheritance:
One of the most useful aspects of object-oriented programming is code reusability. As the
name suggests Inheritance is the process of forming a new class from an existing class
that is from the existing class called as base class, new class is formed called as derived
class. This is a very important concept of object-oriented programming since this feature
helps to reduce the code size.
When creating a class, instead of writing completely new data members and member
functions, the programmer can designate that the new class should inherit the members of
an existing class. This existing class is called the base class, and the new class is referred
to as the derived class.
A class can be derived from more than one classes, which means it can inherit data and
functions from multiple base classes. To define a derived class, we use a class derivation
list to specify the base class(es). A class derivation list names one or more base classes
and has the form:
class derived-class: access-specifier base-class
Where access-specifier is one of public, protected, or private, and base-class is the
name of a previously defined class. If the access-specifier is not used, then it is private by
default.
class shape // shape is base class
{
public:
int length, width;
};
class rectangle:public shape // rectangle is derived class
{
public:
int get area()
{ int a;
a=length*width;
return a;
}
};
4. Abstraction:
Data abstraction refers to, providing only essential information to the outside world and
hiding their background details, i.e., to represent the needed information in program
without presenting the details. For example, a database system hides certain details of
how data is stored and created and maintained. Similar way, C++ classes provides
36
Programming Laboratory (210251)
different methods to the outside world without giving internal detail about those methods
and data.
5. Encapsulation:
Encapsulation is placing the data and the functions that work on that data in the same
place. While working with procedural languages, it is not always clear which functions
work on which variables but object-oriented programming provides you framework to
place the data and the relevant functions together in the same object.
6. Overloading:
The concept of overloading is also a branch of polymorphism. When the exiting operator
or function is made to operate on new data type, it is said to be overloaded.
When we call overloaded function or operator, the compiler determines the most
appropriate definition to use by comparing the argument types you used to call the
function or operator with the parameter types specified in the definitions. The process of
selecting the most appropriate overloaded function or operator is called overload
resolution
class dispdata{
public:
void disp(int i) {cout<<i;}
void disp(float f) {cout<<f;}
void disp(double b){cout<<b;}
};
void main()
{
int a=5;
float b=2.6;
double c=1.98654;
cout<<a<<endl<<b<<endl<<c;
getch();
}
7. Polymorphism:
The ability to use an operator or function in different ways in other words giving different
meaning or functions to the operators or functions is called polymorphism. Poly refers
too many. That is a single function or an operator functioning in many ways different
upon the usage is called polymorphism.
TIFF:
TIFF is a computer file format for storing raster graphics images, popular among graphic artists,
the publishing industry. The TIFF format is widely supported by image-manipulation
applications, by publishing and page layout applications, and by scanning, faxing, word
37
Programming Laboratory (210251)
processing, optical character recognition and other applications. Adobe Systems, which acquired
Aldus, now holds the copyright to the TIFF specification.
GTK+:
GTK+ (previously GIMP Toolkit, sometimes incorrectly referred to as the GNOME Toolkit) is
a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the
terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the
most popular toolkits for the Wayland and X11 windowing systems, along with Qt.
The name GTK+ originates from GTK; the plus was added to distinguish an enhanced version. It
was originally created for the GNU Image Manipulation Program (GIMP), a free software raster
graphics editor.
38

More Related Content

What's hot

2d-transformation
2d-transformation2d-transformation
2d-transformation
Pooja Dixit
 
Fixed point scaling
Fixed point scalingFixed point scaling
Fixed point scaling
rishi ram khanal
 
Composite transformations
Composite transformationsComposite transformations
Composite transformationsMohd Arif
 
Augmented reality documentation
Augmented reality documentationAugmented reality documentation
Augmented reality documentation
Bhargav Doddala
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
Bijoy679
 
COMP 4010 Lecture5 VR Audio and Tracking
COMP 4010 Lecture5 VR Audio and TrackingCOMP 4010 Lecture5 VR Audio and Tracking
COMP 4010 Lecture5 VR Audio and Tracking
Mark Billinghurst
 
COMP 4010 - Lecture 3 VR Systems
COMP 4010 - Lecture 3 VR SystemsCOMP 4010 - Lecture 3 VR Systems
COMP 4010 - Lecture 3 VR Systems
Mark Billinghurst
 
COMP 4010: Lecture 4 - 3D User Interfaces for VR
COMP 4010: Lecture 4 - 3D User Interfaces for VRCOMP 4010: Lecture 4 - 3D User Interfaces for VR
COMP 4010: Lecture 4 - 3D User Interfaces for VR
Mark Billinghurst
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.Mohd Arif
 
COMPUTER GRAPHICS
COMPUTER GRAPHICSCOMPUTER GRAPHICS
COMPUTER GRAPHICS
Jagan Raja
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitivesvinay arora
 
Comp4010 Lecture9 VR Input and Systems
Comp4010 Lecture9 VR Input and SystemsComp4010 Lecture9 VR Input and Systems
Comp4010 Lecture9 VR Input and Systems
Mark Billinghurst
 
Virtual Reality
Virtual RealityVirtual Reality
Virtual Reality
Jayalakshmi L
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformationsMohd Arif
 
Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
R S Anu Prabha
 
AR/VR in real estate
AR/VR in real estateAR/VR in real estate
AR/VR in real estate
Sunanda Priyadarshini
 
HSV color model
HSV color modelHSV color model
HSV color model
Pooja Jaiswal
 
Computer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2DComputer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2D
2013901097
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
Alamgir Hossain
 

What's hot (20)

2d-transformation
2d-transformation2d-transformation
2d-transformation
 
Fixed point scaling
Fixed point scalingFixed point scaling
Fixed point scaling
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 
Augmented reality documentation
Augmented reality documentationAugmented reality documentation
Augmented reality documentation
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
 
COMP 4010 Lecture5 VR Audio and Tracking
COMP 4010 Lecture5 VR Audio and TrackingCOMP 4010 Lecture5 VR Audio and Tracking
COMP 4010 Lecture5 VR Audio and Tracking
 
COMP 4010 - Lecture 3 VR Systems
COMP 4010 - Lecture 3 VR SystemsCOMP 4010 - Lecture 3 VR Systems
COMP 4010 - Lecture 3 VR Systems
 
COMP 4010: Lecture 4 - 3D User Interfaces for VR
COMP 4010: Lecture 4 - 3D User Interfaces for VRCOMP 4010: Lecture 4 - 3D User Interfaces for VR
COMP 4010: Lecture 4 - 3D User Interfaces for VR
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
COMPUTER GRAPHICS
COMPUTER GRAPHICSCOMPUTER GRAPHICS
COMPUTER GRAPHICS
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
 
Comp4010 Lecture9 VR Input and Systems
Comp4010 Lecture9 VR Input and SystemsComp4010 Lecture9 VR Input and Systems
Comp4010 Lecture9 VR Input and Systems
 
Virtual Reality
Virtual RealityVirtual Reality
Virtual Reality
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
 
Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
 
AR/VR in real estate
AR/VR in real estateAR/VR in real estate
AR/VR in real estate
 
HSV color model
HSV color modelHSV color model
HSV color model
 
Computer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2DComputer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2D
 
Pixelrelationships
PixelrelationshipsPixelrelationships
Pixelrelationships
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 

Viewers also liked

Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
Abhishek Sharma
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
Vivek Kumar Sinha
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics PracticalNeha Sharma
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
Vivek Kumar Sinha
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
Priya Goyal
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Ankit Kumar
 
Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)
Tushar B Kute
 
Computer graphics file
Computer graphics fileComputer graphics file
Computer graphics fileaman1001
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
baabtra.com - No. 1 supplier of quality freshers
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
Rafi_Dar
 
Design Patterns for Interactive Graphics
Design Patterns for Interactive GraphicsDesign Patterns for Interactive Graphics
Design Patterns for Interactive GraphicsChristian Kohls
 
Oracle Notes
Oracle NotesOracle Notes
Oracle Notes
Abhishek Sharma
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
Ankit Kumar
 
Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manualinteldualcore
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
Graphics point clipping c program
Graphics point clipping c programGraphics point clipping c program
Graphics point clipping c program
Dr.M.Karthika parthasarathy
 

Viewers also liked (20)

Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Graphics Programming in C
Graphics Programming in CGraphics Programming in C
Graphics Programming in C
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)
 
Computer graphics file
Computer graphics fileComputer graphics file
Computer graphics file
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 
Design Patterns for Interactive Graphics
Design Patterns for Interactive GraphicsDesign Patterns for Interactive Graphics
Design Patterns for Interactive Graphics
 
syed mohd naqi zaidi
syed mohd naqi zaidisyed mohd naqi zaidi
syed mohd naqi zaidi
 
Oracle Notes
Oracle NotesOracle Notes
Oracle Notes
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manual
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
Graphics point clipping c program
Graphics point clipping c programGraphics point clipping c program
Graphics point clipping c program
 
Qt Animation
Qt AnimationQt Animation
Qt Animation
 

Similar to SE Computer, Programming Laboratory(210251) University of Pune

3rd Semester Computer Science and Engineering (ACU-2022) Question papers
3rd Semester Computer Science and Engineering  (ACU-2022) Question papers3rd Semester Computer Science and Engineering  (ACU-2022) Question papers
3rd Semester Computer Science and Engineering (ACU-2022) Question papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
AAlha PaiKra
 
Cd practical file (1) start se
Cd practical file (1) start seCd practical file (1) start se
Cd practical file (1) start se
dalipkumar64
 
c programs.pptx
c programs.pptxc programs.pptx
c programs.pptx
LavanyaDiet1
 
Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
Sri Harsha Pamu
 
C-programs
C-programsC-programs
C-programs
SSGMCE SHEGAON
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
PayalJindal19
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
Animesh Chaturvedi
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
Joseph Kuo
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
Kandarp Tiwari
 
sysprog1
sysprog1sysprog1
sysprog1
Ahmed Mekkawy
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
Yi-Hsiu Hsu
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116
Paulo Morgado
 

Similar to SE Computer, Programming Laboratory(210251) University of Pune (20)

3rd Semester Computer Science and Engineering (ACU-2022) Question papers
3rd Semester Computer Science and Engineering  (ACU-2022) Question papers3rd Semester Computer Science and Engineering  (ACU-2022) Question papers
3rd Semester Computer Science and Engineering (ACU-2022) Question papers
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Cd practical file (1) start se
Cd practical file (1) start seCd practical file (1) start se
Cd practical file (1) start se
 
Revision1schema C programming
Revision1schema C programmingRevision1schema C programming
Revision1schema C programming
 
c programs.pptx
c programs.pptxc programs.pptx
c programs.pptx
 
Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
 
C-programs
C-programsC-programs
C-programs
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
Vcs23
Vcs23Vcs23
Vcs23
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
sysprog1
sysprog1sysprog1
sysprog1
 
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
 
C
CC
C
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116
 

Recently uploaded

English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 

Recently uploaded (20)

English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 

SE Computer, Programming Laboratory(210251) University of Pune

  • 1. Programming Laboratory (210251) Index Batch: C1 & C2 Title Date Sign Group A 1. Writing a C++ Program to emulate CPU Architecture (Central Bus) Develop register, ALU level GUI to display results. 2. Writing a C++ class for displaying pixel or point on the screen. 3. Write a C++ class for a Line drawing method using overloading DDA and Bresenham’s Algorithms, inheriting the pixel or point. 4. Write a C++ class for a circle drawing inheriting line class. Group B 1. Write a program in C++ to draw a line with line style (Thick, Thin, Dotted). 2. Write a program in C++ to draw a circle of desired radius. 3. Write a C++ program to draw convex polygons (Square, Rectangle, Triangle). 4. Write a program in C++ to test that given point is inside the polygon. 5. Write a C++ program to fill polygon using scan line algorithm. 6. Write a Java program to draw a line with line style (Thick, Thin, Dotted). Group C 1. Use Maya to draw a Bouncing ball animation.
  • 2. Programming Laboratory (210251) Title: Writing a C++ Program to emulate CPU Architecture (Central Bus) Develop register, ALU level GUI to display results. Aim: To understand the working of CPU architecture, perform some arithmetic operation using ALU and display results. C++ code: #include<string.h> #include<iostream.h> #include<conio.h> #include<dos.h> #include<graphics.h> #include<stdlib.h> #include<math.h> #include<ctype.h> #include<stdio.h> class computer { int c1; int j; char n1[5],n2[5]; char *d1; int a1,b1; char a[5]; int poly[20]; public: computer() { j=0; } void biu(); void alu(); void flags(); void registers(); void segments(); void buses(); void exp1(); void display(); }; void computer::biu() { rectangle(300,20,600,470); //CPU poly[]={340,35,335,100,355,100,360,70,395,100,415,100,410,35,340,35};//draw CPU polygon setfillstyle(1,RED); char ope[2]; 2
  • 3. Programming Laboratory (210251) ope[0]=a[2]; ope[1]='0'; outtextxy(340,45,"Operation"); outtextxy(370,60,ope); } void computer::segments() { rectangle(320,130,420,230); //segments for(int k=1;k<5;k++) { int a=320; int b=130+20*k; int c= 420; int d=130+20*k; line(a,b,c,d); } outtextxy(330,133,"ES=0000h"); outtextxy(330,153,"DS=0000h"); outtextxy(330,173,"CS:0000h"); outtextxy(330,193,"IP:0001h"); outtextxy(330,213,"DI:ALU"); rectangle(480,28,560,50); //memory interface outtextxy(494,38,"Memory "); rectangle(480,80,540,180); // instn queue for(k=1;k<5;k++) { int a=480; int b=80+20*k; int c= 540; int d=80+20*k; line(a,b,c,d); } outtextxy(510,167,"1"); outtextxy(546,100,"Instruction"); outtextxy(546,115,"Queue"); rectangle(470,220,550,240); //control sys outtextxy(480,222,"Program Counter"); } void computer::registers() { rectangle(320,310,420,450); //registers for(int k=1;k<8;k++) { int a=320; int b=310+20*k; int c= 420; int d=310+20*k; line(a,b,c,d); 3
  • 4. Programming Laboratory (210251) outtextxy(304,312,"AX"); outtextxy(304,332,"BX"); outtextxy(304,352,"CX"); outtextxy(304,372,"DX"); outtextxy(330,394,"SP=0001h"); outtextxy(330,414,"BP=0000h"); outtextxy(367,434,"FLAG"); } } void computer::alu() { outtextxy(490,320,"ALU"); int poly2[]={450,330,470,390,530,390,550,330,530,330,520,350,480,350,470,330,450,330}; drawpoly(9,poly2); fillpoly(1,poly2); } void computer::flags() { rectangle(440,410,540,450); //flags line(440,430,540,430); for(int k=1;k<8;k++) { int a=440+12.5*k; int b=410; int c= 440+12.5*k; int d=450; line(a,b,c,d); } outtextxy(443,420,"-"); outtextxy(456,420,"-"); outtextxy(469,420,"-"); outtextxy(482,420,"-"); outtextxy(494,420,"O"); outtextxy(507,420,"D"); outtextxy(520,420,"I"); outtextxy(533,420,"T"); outtextxy(443,437,"S"); outtextxy(456,437,"Z"); outtextxy(469,437,"-"); outtextxy(482,437,"A"); outtextxy(494,437,"-"); outtextxy(507,437,"P"); outtextxy(520,437,"-"); outtextxy(533,437,"C"); char l=a[2]; switch(l) 4
  • 5. Programming Laboratory (210251) { case '+': setfillstyle(1,RED); floodfill(538,448,15); //carry setfillstyle(1,RED); floodfill(512,442,15); //parity setfillstyle(1,RED); floodfill(489,443,15); //auxill setfillstyle(1,RED); floodfill(492,424,15); //over break; case '-': setfillstyle(1,BLUE); floodfill(441,441,15); //sign setfillstyle(1,BLUE); floodfill(454,441,15) ; //zero setfillstyle(1,BLUE); floodfill(538,448,15); setfillstyle(1,BLUE); floodfill(512,442,15); break; case '*': setfillstyle(1,GREEN); floodfill(454,441,15) ; setfillstyle(1,GREEN); floodfill(489,443,15); setfillstyle(1,GREEN); floodfill(538,448,15); setfillstyle(1,GREEN); floodfill(512,442,15); break; case '/': setfillstyle(1,BROWN); floodfill(454,441,15) ; setfillstyle(1,BROWN); floodfill(489,443,15); setfillstyle(1,BROWN); floodfill(538,448,15); setfillstyle(1,BROWN); floodfill(512,442,15); break; } } void computer::buses() { setcolor(10); line(420,40,470,40); line(470,40,460,37); line(470,40,460,43); 5
  • 6. Programming Laboratory (210251) delay(500); line(510,55,510,75); line(510,75,505,72); line(510,75,515,72); delay(500); line(510,185,510,210); line(510,210,505,206); line(510,210,515,206); delay(500); setcolor(15); int poly1[]={340,260,340,280,455,280,455,290,460,310,470,290,465,290,465,280,535,280,535,290, 540,310,550,290,545,290,545,280,570,280,570,440,590,440,590,260,340,260}; setfillstyle(8,RED); fillpoly(21,poly1); delay(1000); setcolor(10); line(540,360,570,360); line(570,360,560,350); line(570,360,560,370); delay(1000); line(490,390,490,410); line(490,410,487,405); line(490,410,493,405); delay(1000); line(540,430,570,430); line(540,430,543,425); line(540,430,543,435); line(570,430,568,425); line(570,430,568,435); setcolor(15); } void computer::exp1() { cout<<"n Enter expression:"; for(int i=0;i<3;i++) { cin>>a[i]; } a[3]='0'; i=0; while(isdigit(a[i])) { n1[i]=a[i]; i++; } 6
  • 7. Programming Laboratory (210251) n1[i]='0'; i=2; while(isdigit(a[i])) { n2[j]=a[i]; i++; j++; } n2[j]='0'; a1= atoi(n1); b1=atoi(n2); if(a[1]=='+') c1=a1+b1; else if(a[1]=='-') c1=a1-b1; else if(a[1]=='*') c1=a1*b1; else if(a[1]=='/') c1=a1/b1; else if(a[1]=='%') c1=a1%b1; else cout<<"n Enter correctly:"; } void computer:: display() { outtextxy(324,313,n1); outtextxy(324,333,n2); char n3[2]; n3[0]='='; n3[1]='0'; char n4[50]; itoa(a1,n1,2); itoa(b1,n2,2); outtextxy(340,313,strcat("=",n1)); outtextxy(340,333,n3); outtextxy(346,333,n2); itoa(c1,n4,2); outtextxy(322,373,n4); outtextxy(480,365,n4); flushall(); char v[20]; itoa(c1,v,10); outtextxy(72,130,v); } void main() 7
  • 8. Programming Laboratory (210251) { int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi"); computer c; c.exp1(); delay(500); c.biu(); delay(500); c.segments(); delay(500); c.registers(); delay(500); c.display(); delay(500); c.alu(); delay(500); c.flags(); delay(500); c.buses(); getch(); } Graphics function used: 1. outtextxy 2. line 3. rectangle 4. drawpoly 5. fillpoly 6. setfillstyle 7. floodfill Output: Title: Writing a C++ class for displaying pixel or point on the screen. 8
  • 9. Programming Laboratory (210251) Aim: To understand, how to display pixel on screen. C++ Code: #include<iostream.h> #include<conio.h> #include<graphics.h> class pixel { public: int x,y; void disp(int,int); }; void pixel::disp(int p,int q) { putpixel(p,q,WHITE); } void main() { class pixel p; int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcplusbgi"); cout<<"Enter position of pixel"; cin>>p.x>>p.y; p.disp(p.x,p.y); getch(); } Output: 9
  • 10. Programming Laboratory (210251) Title: Write a C++ class for a Line drawing method using overloading DDA and Bresenham’s Algorithms, inheriting the pixel or point. DDA Line Drawing Algorithm: Bresenham’s Line Drawing Algorithm: 10
  • 11. Programming Laboratory (210251) C++ Code for DDA Line Drawing Algorithm: #include<iostream.h> #include<math.h> #include<conio.h> #include<graphics.h> class line { public: int x1,y1,x2,y2; void drawl(int,int,int,int); }; void line::drawl(int x1,int y1,int x2,int y2) { int i=1,dx,dy,step,x,y; float xinc,yinc; dx=abs(x2-x1); dy=abs(y2-y1); if(dx<=dy) { step=dy; } else {step=dx;} xinc=dx/step; yinc=dy/step; x=x1;y=y1; putpixel(x,y,WHITE); while(i<=step) { x=x+xinc+0.5; y=y+yinc+0.5;i++; putpixel(x,y,WHITE); } } void main() { class line l; int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi"); cout<<"Enter coordinates of end points"; cin>>l.x1>>l.y1>>l.x2>>l.y2; l.drawl(l.x1,l.y1,l.x2,l.y2); getch(); } 11
  • 12. Programming Laboratory (210251) Output: C++ Code for Bresenham’s Line Drawing Algorithm: #include<iostream.h> #include<conio.h> #include<graphics.h> class line { public: int x1,y1,x2,y2; void drawl(int,int,int,int); }; void line::drawl(int x1,int y1,int x2,int y2) { int dx=x2-x1,dy=y2-y1,di=2*dx-dy,ds=2*dy,dt=2*(dy-dx); putpixel(x1,y1,WHITE); while(x1<=x2) { x1++; if(di<0) {di+=ds;} else { y1++; di+=dt; } putpixel(x1,y1,WHITE); } } void main() { class line l; int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi"); cout<<"Enter coordinates of end points x1,y1,x2,y2"; cin>>l.x1>>l.y1>>l.x2>>l.y2; l.drawl(l.x1,l.y1,l.x2,l.y2); getch(); } Output: 12
  • 13. Programming Laboratory (210251) Title: Write a C++ class for a circle drawing inheriting line class. C++ Code: #include<conio.h> #include<iostream.h> #include<graphics.h> class linep //line class { public: int x1,y1,x2,y2; }; class circle:public linep //circle class inherit from linep class { public: void disp(int,int,int); }; void circle::disp(int x,int y,int r) { int p,x1,y1; x1=0; y1=r; p=3-r; while(x1<=y1) { if(p<0) { x1++; p+=4*x1+6; } else { x1++;y1--; p+=4*(x1-y1)+10; } putpixel(x1+x,y1+y,1); putpixel(x1+x,y-y1,1); putpixel(x-x1,y1+y,1); putpixel(x-x1,y-y1,1); putpixel(x+y1,y+x1,1); putpixel(x+y1,y-x1,1); putpixel(x-y1,y+x1,1); putpixel(x-y1,y-x1,1); } 13
  • 14. Programming Laboratory (210251) } void main() { class circle c; class linep p; int gd=DETECT,gm,r; initgraph(&gd,&gm,"C:tcbgi"); cout<<"Enter radius of circle"; cin>>r; cout<<"Enter co-ordinates of circle"; cin>>p.x2>>p.y2; c.disp(p.x2,p.y2,r); getch(); } Output: 14
  • 15. Programming Laboratory (210251) Title: Write a program in C++ to draw a line with line style (Thick, Thin, Dotted). C++ code: #include<conio.h> #include<iostream.h> #include<graphics.h> class linep { public: int x1,y1,x2,y2; void drawl(int,int,int,int); void thick(int,int,int,int,int); void dotted(int,int,int,int); }; void linep::thick(int x1,int y1,int x2,int y2,int w) { int i,dx,dy,step,xinc,yinc; dx=x2-x1; dy=y2-y1; if(dy>=dx) { step=dy; } else { step=dx; } xinc=dx/step; yinc=dy/step; while(x1<=x2) { x1=x1+xinc+0.5; y1=y1+yinc+0.5; for(i=0;i<w;i++) { putpixel(x1+i,y1,WHITE); } } } void linep::drawl(int x1,int y1,int x2,int y2) { int dx,dy,step,xinc,yinc; dx=x2-x1; dy=y2-y1; if(dy>=dx) 15
  • 16. Programming Laboratory (210251) { step=dy; } else { step=dx; } xinc=dx/step; yinc=dy/step; putpixel(x1,y1,WHITE); while(x1<=x2) { x1=x1+xinc+0.5; y1=y1+yinc+0.5; putpixel(x1,y1,WHITE); } } void linep::dotted(int x1,int y1,int x2,int y2) { int i=0,dx,dy,step,xinc,yinc; dx=x2-x1; dy=y2-y1; if(dy>=dx) { step=dy; } else { step=dx; } xinc=dx/step; yinc=dy/step; putpixel(x1,y1,WHITE); while(x1<=x2) { if(i%2==0) { putpixel(x1,y1,WHITE); } x1=x1+xinc+0.5; y1=y1+yinc+0.5; i++; } } void main() 16
  • 17. Programming Laboratory (210251) { class linep p; int gd=DETECT,gm,n,i,w; initgraph(&gd,&gm,"C:TCbgi"); cout<<"Enter co-ordinates of line x1,y1,x2,y2"; cin>>p.x1>>p.y1>>p.x2>>p.y2; cout<<"Enter your choice 1. Thin Line 2. Thick line 3. Dotted line"; cin>>i; switch(i) { case 1: p.drawl(p.x1,p.y1,p.x2,p.y2); break; case 2: cout<<"Enter width of line in pixel"; cin>>w; p.thick(p.x1,p.y1,p.x2,p.y2,w); break; case 3: p.dotted(p.x1,p.y1,p.x2,p.y2); break; default: cout<<"Enter proper choice"; } getch(); } Output: 17
  • 18. Programming Laboratory (210251) Title: Write a program in C++ to draw a circle of desired radius. C++ Code: #include<conio.h> #include<iostream.h> #include<graphics.h> void display(int,int,int,int); void main() { int p,gd=DETECT,gm,x1,y1,x,y,r; initgraph(&gd,&gm,"c :tcbgi"); cout<<"Enter radius of circle"; cin>>r; cout<<"Enter co-ordinates of circle"; cin>>x>>y; x1=0; y1=r; p=3-r; while(x1<=y1) { if(p<0) { x1++; p+=4*x1+6; } else { x1++;y1--; p+=4*(x1-y1)+10; } display(x1,y1,x,y); } getch(); } void display(int x1,int y1,int x,int y) { putpixel(x1+x,y1+y,1); putpixel(x1+x,y-y1,1); putpixel(x-x1,y1+y,1); putpixel(x-x1,y-y1,1); putpixel(x+y1,y+x1,1); putpixel(x+y1,y-x1,1); putpixel(x-y1,y+x1,1); putpixel(x-y1,y-x1,1); 18
  • 20. Programming Laboratory (210251) Title: Write a C/C++ program to draw convex polygons (Square, Rectangle, and Triangle). C++ Code: #include<iostream.h> #include<math.h> #include<conio.h> #include<graphics.h> class line { public: int x1,y1,x2,y2; void drawl(int,int,int,int); }; void line::drawl(int x1,int y1,int x2,int y2) { int i=1,dx,dy,step,x,y; float xinc,yinc; dx=abs(x2-x1); dy=abs(y2-y1); if(dx<=dy) { step=dy; } else {step=dx;} xinc=dx/step; yinc=dy/step; x=x1;y=y1; while(i<=step) { x=x+xinc+0.5; y=y+yinc+0.5;i++; putpixel(x,y,WHITE); } } void main() { int i,x1,y1,x2,y2,gd=DETECT,gm,len,wid,size, base,height; initgraph(&gd,&gm,"c:tcbgi"); class line l; cout<<"Enter value of x1,y1"; cin>>x1>>y1; cout<<"Enter your choice 1. Rectangle 2. Square 3. Triangle"; cin>>i; 20
  • 21. Programming Laboratory (210251) switch(i) { case 1: cout<<"Enter length & Width of Rectangle"; cin>>len>>wid; x2=x1+wid; y2=y1; l.drawl(x1,y1,x2,y2); x1=x1+wid; y1=y2; y2=y2+len; x2=x1; l.drawl(x1,y1,x2,y2); x1=x2; y1=y2; x2=x2-wid; y2=y2; l.drawl(x2,y2,x1,y1); x1=x2; y1=y2; x2=x1; y2=y2-len; l.drawl(x2,y2,x1,y1); break; case 2: cout<<"Enter Size of Square"; cin>>size; x2=x1+size; y2=y1; l.drawl(x1,y1,x2,y2); x1=x1+size; y1=y2; y2=y2+size; x2=x1; l.drawl(x1,y1,x2,y2); x1=x2; y1=y2; x2=x2-size; y2=y2; l.drawl(x2,y2,x1,y1); x1=x2; y1=y2; x2=x1; y2=y2-size; l.drawl(x2,y2,x1,y1); 21
  • 22. Programming Laboratory (210251) break; case 3: int x3,y3; cout<<"Enter base and height of triangle "; cin>>base>>height; x2=x1+base; y2=y1; l.drawl(x1,y1,x2,y2); x3=x1; y3=y1+height; l.drawl(x1,y1,x3,y3); l.drawl(x2,y2,x3,y3); break; default: cout<<"Enter correct choice"; } getch(); } Output: 22
  • 23. Programming Laboratory (210251) Title: Write a program in C++ to test that given point is inside the polygon (Rectangle). C++ Code: #include<iostream.h> #include<math.h> #include<conio.h> #include<graphics.h> class line { public: int x1,y1,x2,y2; void drawl(int,int,int,int); }; void line::drawl(int x1,int y1,int x2,int y2) { int i=1,dx,dy,step,x,y; float xinc,yinc; dx=abs(x2-x1); dy=abs(y2-y1); if(dx<=dy) { step=dy; } else {step=dx;} xinc=dx/step; yinc=dy/step; x=x1;y=y1; putpixel(x,y,WHITE); while(i<=step) { x=x+xinc+0.5; y=y+yinc+0.5; i++; putpixel(x,y,WHITE); } } void main() { class line l; int i,x1=100,y1=100,x2,y2,gd=DETECT,gm,len=50,wid=34,x,y; initgraph(&gd,&gm,"c:tcbgi"); x2=x1+wid; y2=y1; 23
  • 24. Programming Laboratory (210251) l.drawl(x1,y1,x2,y2); x1=x1+wid; y1=y2; y2=y2+len; x2=x1; l.drawl(x1,y1,x2,y2); x1=x2; y1=y2; x2=x2-wid; y2=y2; l.drawl(x2,y2,x1,y1); x1=x2; y1=y2; x2=x1; y2=y2-len; l.drawl(x2,y2,x1,y1); cout<<"Enter position of point"; cin>>x>>y; if(((x<x1)&&(y<y1))||((x>x2)&&(y>y2))) { putpixel(x,y,BLUE); cout<<"Point outside of the polgon"; } else { cout<<"Point inside of the polgon"; } getch(); } Output: 24
  • 25. Programming Laboratory (210251) Title: Write a C++ program to fill polygon using scan line algorithm. C++ Code: #include<iostream.h> #include<conio.h> #include<graphics.h> #include<dos.h> struct edge { int x1,y1,x2,y2,flag; }; void main() { int n,i,j,k,gd=DETECT,gm, x[10],y[10],ymax=0,ymin=480,yy,temp; struct edge ed[10],temped; float dx,dy,m[10],x_int[10],inter_x[10]; initgraph(&gd,&gm,"c:tcbgi"); cout<<"n Enter the number of vertices of the graph: "; cin>>n; cout<<"n Enter the co-ordinates of vertices: n"; for(i=0;i<n;i++) { cout<<"x"<<i; cin>>x[i]>>endl; cout<<"y"<<i; cin>>y[i]>>endl; if(y[i]>ymax) ymax=y[i]; if(y[i]<ymin) ymin=y[i]; ed[i].x1=x[i]; ed[i].y1=y[i]; } for(i=0;i<n-1;i++) //store the edge information { ed[i].x2=ed[i+1].x1; ed[i].y2=ed[i+1].y1; ed[i].flag=0; } ed[i].x2=ed[0].x1; ed[i].y2=ed[0].y1; ed[i].flag=0; for(i=0;i<n-1;i++) //check for y1>y2 if not then interchange it { 25
  • 26. Programming Laboratory (210251) if(ed[i].y1<ed[i].y2) { temp=ed[i].x1; ed[i].x1=ed[i].x2; ed[i].x2=temp; temp=ed[i].y1; ed[i].y1=ed[i].y2; ed[i].y2=temp; } } for(i=0;i<n;i++) //draw polygon { line(ed[i].x1,ed[i].y1,ed[i].x2,ed[i].y2); } for(i=0;i<n-1;i++) //storing the edges as y1,y2,x1 { for(j=0;j<n-1;j++) { if(ed[j].y1<ed[j+1].y1) { temped=ed[j]; ed[j]=ed[j+1]; ed[j+1]=temped; } if(ed[j].y1==ed[j+1].y1) { if(ed[j].y2<ed[j+1].y2) { temped=ed[j]; ed[j]=ed[j+1]; ed[j+1]=temped; } if(ed[j].y2==ed[j+1].y2) { if(ed[j].x1<ed[j+1].x1) { temped=ed[j]; ed[j]=ed[j+1]; ed[j+1]=temped; } } } } } 26
  • 27. Programming Laboratory (210251) for(i=0;i<n;i++) //calculate 1/slope { dx=ed[i].x2-ed[i].x1; dy=ed[i].y2-ed[i].y1; if(dy==0) m[i]=0; else m[i]=dx/dy; inter_x[i]=ed[i].x1; } yy=ymax; while(yy>ymin) //Mark active edges { for(i=0;i<n;i++) { if(yy>ed[i].y2 && yy<=ed[i].y1 && ed[i].y1!=ed[i].y2) ed[i].flag=1; else ed[i].flag=0; } j=0; for(i=0;i<n;i++) //Finding x intersections { if(ed[i].flag==1) { if(yy==ed[i].y1) { x_int[j]=ed[i].x1; j++; if(ed[i-1].y1==yy&&ed[i-1].y1<yy) { x_int[j]=ed[i].x1; j++; } if(ed[i+1].y1==yy&&ed[i+1].y1<yy) { x_int[j]=ed[i].x1; j++; } } else { x_int[j]=inter_x[i]+(-m[i]); inter_x[i]=x_int[j]; 27
  • 28. Programming Laboratory (210251) j++; } } } for(i=0;i<j;i++) //sorting the x intersections { for(k=0;k<j-1;k++) { if(x_int[k]>x_int[k+1]) { temp=x_int[k]; x_int[k]=x_int[k+1]; x_int[k+1]=temp; } } } for(i=0;i<j;i+=2) //Extracting x values to draw a line { line(x_int[i],yy,x_int[i+1],yy); } yy--; } delay(3000); getch(); } Output: 28
  • 29. Programming Laboratory (210251) Title: Write a Java program to draw a line with line style (Thick, Thin, Dotted). JAVA Code: import java.awt.*; import javax.swing.*; public class drawline extends JFrame{ public drawline(){ super("Lines"); setSize(400,400); setVisible(true); } Stroke[] linestyles=new Stroke[]{ new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL), new BasicStroke(25.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER), new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND),}; Stroke thindashed=new BasicStroke(2.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL,1.0f, new float[] {8.0f,3.0f,2.0f,3.0f},0.0f); final static float dash1[]={10.0f}; final static BasicStroke dashed =new BasicStroke(1.0f, BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f); final static float thick1[]={10.0f}; final static BasicStroke thickdash =new BasicStroke(10.0f, BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER, 10.0f, thick1, 0.0f); public void paint(Graphics g){ int xpoints[]={220,350,350,220}; int ypoints[]={220,220,320,320}; int npoints=4; int xpoints1[]={60,120,180}; int ypoints1[]={320,220,320}; int npoints1=3; Graphics2D g2d = (Graphics2D) g; super.paint(g); ((Graphics2D)g).setStroke(dashed); g.setColor(Color.black); g2d.drawLine(50,50,200,50); g2d.setColor(Color.black); g.drawString("Dotted Line", 210,55); ((Graphics2D)g).setStroke(linestyles[3]); g.setColor(Color.red); g2d.drawLine(50,170,200,170); g2d.setColor(Color.black); g.drawString("Thin Line", 210,175); 29
  • 30. Programming Laboratory (210251) } public static void main(String[] args){ Lines application = new Lines(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } Steps for running this program: 1. Compilation of Program C:Program FilesJavajdk1.7bin>javac drawline.java 2. Run the Program C:Program FilesJavajdk1.7bin>java drawline Output: 30
  • 31. Programming Laboratory (210251) Title: Use Maya to draw a Bouncing ball animation. Introduction: Maya 3D animation, modeling, simulation, rendering and compositing software offers a comprehensive creative feature set for 3D computer animation, modeling, simulation and rendering on a highly extensible production platform. Maya provides high-end character and effects toolsets along with increased productivity for modeling, texturing and shade creation tasks. 31
  • 32. Programming Laboratory (210251) C graphics using graphics.h functions or WinBGIM (Windows 7) can be used to draw different shapes, display text in different fonts, change colors and many more. Using functions of graphics.h in turbo C compiler you can make graphics programs, animations, projects and games. In a C/C++ Program first of all, we have to initialize the graphics drivers on the computer. This is done using the initgraph method provided in graphics.h library. Graphics mode Initialization: First of all we have to call the initgraph function that will intialize the graphics mode on the computer. Prototype of initigraph: void initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver); Initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode. Initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their defaults, then resets graph result to 0. *graphdriver Integer that specifies the graphics driver to be used. You can give graphdriver a value using a constant of the graphics_drivers enumeration type. *graphmode Integer that specifies the initial graphics mode (unless *graphdriver = DETECT). If *graphdriver = DETECT, initgraph sets *graphmode to the highest resolution available for the detected driver. You can give *graphmode a value using a constant of the graphics_modes enumeration type. *pathtodriver Specifies the directory path where initgraph looks for graphics drivers (*.BGI) first. 1. If they’re not there, initgraph looks in the current directory. 2. If pathtodriver is null, the driver files must be in the current directory. *graphdriver and *graphmode must be set to valid graphics_drivers and graphics_mode values or you’ll get unpredictable results. (The exception is graphdriver = DETECT.) After a call to initgraph, *graphdriver is set to the current graphics driver, and *graphmode is set to the current graphics mode. You can tell initgraph to use a particular graphics driver and mode, 32
  • 33. Programming Laboratory (210251) 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. Generally, initgraph loads a graphics driver by allocating memory for the driver (through _graphgetmem), then loading the appropriate .BGI file from disk. As an alternative to this dynamic loading scheme, you can link a graphics driver file directly into your executable program file. List of few functions from graphics.h file: Name of Function Circle Drawing circle Arc Drawing arc Screen getbkcolor, getcolor, setbkcolor, setcolor Pixel getpixel, getx, gety, putpixel Rectangle rectangle Polygon drawpoly, fillpoly, floodfill Line line, linerel, lineto Text print outtextxy getpixel(int x, int y); putpixel(int x,int y, int color); setbkcolor(BLUE); getbkcolor(void); setcolor(int color); getcolor(void); outtextxy function display text or string at a specified point(x,y) on the screen. void outtextxy(int x, int y, char *string); x, y are coordinates of the point and third argument contains the address of string to be displayed. line(int x1, int y1, int x2, int y2) linerel(int dx,int dy): draw a line relative distance. lineto(int x,int y): draw a line original point to x,y point. rectangle(left,top,right,bottom) circle(int x, int y, int radius) 33
  • 34. Programming Laboratory (210251) arc(int x,int y, int stangle, int endangle, int radius) drawpoly(int numpoints, int far *polypoints); setfillstyle(int pattern, int color); EMPTY_FILL: 0, SOLID_FILL: 1 fillpoly(int numpoints, int far *polypoints); fillpoly draws outline of polygon using current line style and color. floodfill(int x,int y int border); floodfill function is used to fill an enclosed area. Current fill pattern and fill color is used to fill the area.(x, y) is any point on the screen if (x,y) lies inside the area then inside will be filled otherwise outside will be filled, border specifies the color of boundary of area. To change fill pattern and fill color use setfillstyle. Code given below draws a circle and then fills it. Computer Graphics: Computer graphics remains one of the most existing and rapidly growing computer fields. Computer graphics may be defined as a pictorial representation or graphical representation of objects in a computer. Applications of computer graphics: There are many interesting applications of computer graphics. Three common applications are graphic user interface (GUI), computer-aided design (CAD), and computer games. Major components (hardware and software) are needed for computer graphics: Besides the basic computer, some special devices and software may be required especially for computer graphics. For hardware, a special high-resolution, color monitor is often demanded and some input tools, e.g. mouse and joy-sticker, and hard-copy devices, e.g. high-resolution color printer, may be required. For software, some special purpose utilities (device-dependent and device-independent) are needed for handling processing in computer graphics. Random/Raster Scan: Random scan is a method in which the display is made by the electronic beam, which is directed, only to the points or part of the screen where the picture is to be drawn. The Raster scan system is a scanning technique in which the electrons sweep from top to bottom and from left to right. The intensity is turned on or off to light and unlight the pixel. Refreshing of the screen: Refreshing of screen is done by keeping the phosphorus glowing to redraw the picture repeatedly. i.e. by quickly directing the electronic beam back to the same points. 34
  • 35. Programming Laboratory (210251) Aspect Ratio: The ratio of vertical points to the horizontal points necessary to produce length of lines in both directions of the screen is called Aspect Ratio. Usually the aspect ratio is ¾. Addressability: Addressability is the number of individual dots per inch (d.p.i.) that can be created. If the address of the current dot is (x, y) then the next dot will be (x + y), (x + y + 1) etc. Dot size: The diameter of a single dot on the devices output. Interdot distance: Interdot distance is the reciprocal of addressability. If the addressability is large, the interdot distance will be less. The interdot distance should be less to get smooth shapes. C++: Purpose of C++ programming was to add object orientation to the C programming language, which is in itself one of the most powerful programming languages. The core of the pure object-oriented programming is to create an object, in code, that has certain properties and methods. While designing C++ modules, we try to see whole world in the form of objects. There are a few principle concepts that form the foundation of object-oriented programming: 1. Object: This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object. 2. Class: We define a blueprint for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object. There are three types of data members: • Public • Private • Protected Syntax: class classname{ private: //by default data members are private public: protected: }; // end of the Class 35
  • 36. Programming Laboratory (210251) 3. Inheritance: One of the most useful aspects of object-oriented programming is code reusability. As the name suggests Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class. This is a very important concept of object-oriented programming since this feature helps to reduce the code size. When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class. A class can be derived from more than one classes, which means it can inherit data and functions from multiple base classes. To define a derived class, we use a class derivation list to specify the base class(es). A class derivation list names one or more base classes and has the form: class derived-class: access-specifier base-class Where access-specifier is one of public, protected, or private, and base-class is the name of a previously defined class. If the access-specifier is not used, then it is private by default. class shape // shape is base class { public: int length, width; }; class rectangle:public shape // rectangle is derived class { public: int get area() { int a; a=length*width; return a; } }; 4. Abstraction: Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details. For example, a database system hides certain details of how data is stored and created and maintained. Similar way, C++ classes provides 36
  • 37. Programming Laboratory (210251) different methods to the outside world without giving internal detail about those methods and data. 5. Encapsulation: Encapsulation is placing the data and the functions that work on that data in the same place. While working with procedural languages, it is not always clear which functions work on which variables but object-oriented programming provides you framework to place the data and the relevant functions together in the same object. 6. Overloading: The concept of overloading is also a branch of polymorphism. When the exiting operator or function is made to operate on new data type, it is said to be overloaded. When we call overloaded function or operator, the compiler determines the most appropriate definition to use by comparing the argument types you used to call the function or operator with the parameter types specified in the definitions. The process of selecting the most appropriate overloaded function or operator is called overload resolution class dispdata{ public: void disp(int i) {cout<<i;} void disp(float f) {cout<<f;} void disp(double b){cout<<b;} }; void main() { int a=5; float b=2.6; double c=1.98654; cout<<a<<endl<<b<<endl<<c; getch(); } 7. Polymorphism: The ability to use an operator or function in different ways in other words giving different meaning or functions to the operators or functions is called polymorphism. Poly refers too many. That is a single function or an operator functioning in many ways different upon the usage is called polymorphism. TIFF: TIFF is a computer file format for storing raster graphics images, popular among graphic artists, the publishing industry. The TIFF format is widely supported by image-manipulation applications, by publishing and page layout applications, and by scanning, faxing, word 37
  • 38. Programming Laboratory (210251) processing, optical character recognition and other applications. Adobe Systems, which acquired Aldus, now holds the copyright to the TIFF specification. GTK+: GTK+ (previously GIMP Toolkit, sometimes incorrectly referred to as the GNOME Toolkit) is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the Wayland and X11 windowing systems, along with Qt. The name GTK+ originates from GTK; the plus was added to distinguish an enhanced version. It was originally created for the GNU Image Manipulation Program (GIMP), a free software raster graphics editor. 38