Write A Program of 3d Bar

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 37

/* Write a program of 3d bar */

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
bar3d(100,100,200,200,20,1);
getch();
closegraph();
}
**************Output************

/* Write a program of Bresenhams line */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int x1,y1,x2,y2,dx,dy,dp,i,x,y;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
printf("enter the value of x1,y1:");
scanf("%d%d",&x1,&y1);
printf("enter the value of x2,y2:");
scanf("%d%d",&x2,&x2);
dx=abs(x2-x1);
dy=abs(y2-y1);
dp=2*(dy-dx);
x=x1;
y=y1;
for(i=0;i<=dx;i++)
{
delay(100);
putpixel(x,y,GREEN);
if(dp<=0)
{
x++;
dp=dp+2*dy;
}
else
{
x++;
y++;
dp=dp+2*dx-2*dy;
}
}
getch();
closegraph();
}

*************Output***************

/* Write a program of Set Fill Style */


#include<stdio.h>
#include<conio.h>

#include<graphics.h>
void main()
{
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver, &gmode, "..//bgi");
setfillstyle(XHATCH_FILL,RED);
circle(100,100,50);
floodfill(100,100,WHITE);
getch();
closegraph();
}
*************************output*********************

/* Write a program of Circle Mid Point */


#include<stdio.h>
#include<conio.h>

#include<graphics.h>
#include<math.h>
#include<stdlib.h>
voidcirclepoint(int,int, int,int);
voidcirmid(int,int,int);
void main()
{
intx,y,r;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver, &gmode, "..//bgi");
printf("enter the value of x,y:");
scanf("%d%d",&x,&y);
printf("enter the value of radius:");
scanf("%d",&r);
cirmid(x,y,r);
getch();
closegraph();
}
voidcirmid(intxc,intyc,int r)
{
int x=0;
int y=r;
int p=1-r;
circlepoint(xc,yc,x,y);
while(x<y)
{
x++;
if(p<0)
p=p+2*x+1;
else
{
y--;
p=p+2*(x-y)+1;
}
circlepoint(xc,yc,x,y);
}
}
voidcirclepoint(int xc, intyc, int x, int y)
{
delay(10);
putpixel(xc+x, yc+y,RED);
putpixel(xc-x, yc+y,RED);

putpixel(xc+x, yc-y,RED);
putpixel(xc-x, yc-y,RED);
putpixel(xc+y, yc+x,RED);
putpixel(xc-y, yc+x,RED);
putpixel(xc+y, yc-x,RED);
putpixel(xc-y, yc-x,RED);
}

*********************output**********************

/* Write a program of Color Square*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>
voidcirclepoint(int,int, int,int);
voidcirmid(int,int,int);

void main()
{
intx,y,r;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver, &gmode, "..//bgi");
printf("enter the value of x,y:");
scanf("%d%d",&x,&y);
printf("enter the value of radius:");
scanf("%d",&r);
cirmid(x,y,r);
getch();
closegraph();
}
voidcirmid(intxc,intyc,int r)
{
int x=0;
int y=r;
int p=1-r;
circlepoint(xc,yc,x,y);
while(x<y)
{
x++;
if(p<0)
p=p+2*x+1;
else
{
y--;
p=p+2*(x-y)+1;
}
circlepoint(xc,yc,x,y);
}
}
voidcirclepoint(int xc, intyc, int x, int y)
{
delay(10);
putpixel(xc+x, yc+y,RED);
putpixel(xc-x, yc+y,RED);
putpixel(xc+x, yc-y,RED);
putpixel(xc-x, yc-y,RED);
putpixel(xc+y, yc+x,RED);
putpixel(xc-y, yc+x,RED);
putpixel(xc+y, yc-x,RED);

putpixel(xc-y, yc-x,RED);
}

*****************output**********************

/*Write a program of DDA Line*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int x1,y1,x2,y2,dx,dy,step,xinc,yinc,k,x,y;

intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
printf("enter the value of x1,y1:");
scanf("%d%d",&x1,&y1);
printf("enter the value of x2,y2:");
scanf("%d%d",&x2,&x2);
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,GREEN);
for(k=0;k<step;k++)
{
x=x+xinc;
y=y+yinc;
putpixel(x,y,GREEN);
}
getch();
closegraph();
}

*********************Output***********************

/*Write a program to draw a Fish*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void main()
{
intgd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"..//bgi");
setcolor(6);
ellipse(200,200,0,360,50,30);
line(250,200,280,170);
line(280,170,280,230);
line(280,230,250,200);
circle(160,190,3);
getch();
closegraph();
}

****************Output*********************

/* Write a program to draw a Flag*/


#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main()
{
intgdriver=DETECT,gmode;
clrscr();
initgraph(&gdriver,&gmode,"..//bgi");
setcolor(5);
line(20,50,20,180);
line(20,50,100,50);
line(20,70,100,70);
line(20,90,100,90);
line(20,110,100,110);
line(100,50,100,110);
circle(60,80,10);
line(52,80,68,80);
line(60,72,60,88);
setfillstyle(SOLID_FILL,22);
floodfill(21,51,5);
setfillstyle(SOLID_FILL,7);
floodfill(21,75,5);
setfillstyle(SOLID_FILL,2);
floodfill(21,95,5);
setfillstyle(SOLID_FILL,7);
floodfill(81,75,5);
setfillstyle(SOLID_FILL,7);
getch();
closegraph();
}

***********************Output**********************

/* Write a program of Hut*/


#include<stdio.h>

#include<conio.h>
#include<graphics.h>
void main()
{
intgd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"..//bgi");
setcolor(6);
rectangle(50,180,150,300);
rectangle(150,180,320,300);
line(100,100,150,180);
line(100,100,270,100);
line(270,100,320,180);
line(100,100,50,180);
getch();
closegraph();
}

*********************Output********************

/* Write a program of kite*/


#include<stdio.h>
#include<conio.h>

#include<graphics.h>
void main()
{
inta,b,gd=DETECT,gm,i;
initgraph(&gd,&gm,"..//bgi");
line(100,100,50,180);
line(100,100,150,180);
line(50,180,100,250);
line(150,180,100,250);
line(100,100,100,250);
line(50,180,150,180);
line(100,250,70,300);
line(100,250,130,300);
line(70,300,130,300);
line(100,300,120,320);
line(120,320,80,340);
line(80,340,120,360);
line(120,360,80,380);
getch();
closegraph();
}

*****************Output************************

/* Write a program of text position */


#include<stdio.h>

#include<conio.h>
#include<graphics.h>
void main()
{
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver, &gmode, "..//bgi");
outtext("to display text at correct position");
outtextxy(100,100,"menu");
getch();
closegraph();
}

*******************Output**********************

/* Write a program to Draw Pixel*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>

#include<stdlib.h>
#include<math.h>
void main()
{
intx,y;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
printf("enter the value of x:");
scanf("%d",&x);
printf("enter the value of y:");
scanf("%d",&y);
putpixel(x,y,1);
getch();
closegraph();
}

*******************Output*******************

/* Write a program of scaling*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int x1,y1,x2,y2,x3,y3,x4,y4,sx,sy;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
printf("enter the value of x1,y1:");
scanf("%d%d",&x1,&y1);
printf("enter the value of x2,y2:");
scanf("%d%d",&x2,&y2);
printf("enter the scaling size:");
scanf("%d%d",&sx,&sy);
rectangle(x1,y1,x2,y2);
getch();
x3=x1/sx;
y3=y1/sy;
x4=x2/sx;
y4=y2/sy;
rectangle(x3,y3,x4,y4);
getch();
closegraph();
}

*******************Output*************************

/* Write a program of Sector*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void main()
{
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver, &gmode, "..//bgi");
sector(100,100,0,135,25,35);
getch();
closegraph();

*********************Output********************

/* Write a program of Square*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>

dline(int,int,int,int);
void main()
{
int x1,y1,x2,y2;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
printf("enter the value of x1,y1:");
scanf("%d%d",&x1,&y1);
printf("enter the value of x2,y2:");
scanf("%d%d",&x2,&x2);
dline(x1,y1,x2,y1);
dline(x2,y1,x2,y2);
dline(x2,y2,x1,y2);
dline(x1,y2,x1,y1);
getch();
closegraph();
}
dline(int x1,int y1, int x2, int y2)
{
intdx,dy,step,xinc,yinc,x,y,k;
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,GREEN);
for(k=0;k<step;k++)
{
x=x+xinc;
y=y+yinc;
putpixel(x,y,GREEN);
}
return 0;
}

********************output****************

/* Write a program of Transformation*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
void main()
{

int x1,y1,x2,y2,x3,y3,x4,y4,tx,ty;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
printf("enter the value of x1,y1:");
scanf("%d%d",&x1,&y1);
printf("enter the value of x2,y2:");
scanf("%d%d",&x2,&y2);
printf("enter the scaling size:");
scanf("%d%d",&tx,&ty);
rectangle(x1,y1,x2,y2);
getch();
x3=x1+tx;
y3=y1+ty;
x4=x2+tx;
y4=y2+ty;
rectangle(x3,y3,x4,y4);
getch();
closegraph();
}

********************Output********************

/* Write a program of triangle*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>

#include<stdlib.h>
#include<math.h>
dline(int,int,int,int);
void main()
{
int x1,y1,x2,y2,x3,y3;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
printf("enter the value of x1,y1:");
scanf("%d%d",&x1,&y1);
printf("enter the value of x2,y2:");
scanf("%d%d",&x2,&y2);
printf("enter the value of x3,y3:");
scanf("%d%d",&x3,&y3);
dline(x1,y1,x2,y2);
dline(x1,y1,x3,y3);
dline(x2,y2,x3,y3);
getch();
closegraph();
}
dline(int x1,int y1, int x2, int y2)
{
intdx,dy,step,xinc,yinc,x,y,k;
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,GREEN);
for(k=0;k<step;k++)
{
x=x+xinc;
y=y+yinc;
delay(10);
putpixel(x,y,GREEN);
}
}

***************Output****************

/* Write a program of text style */


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int x=25,y=25,font=0;

intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver, &gmode, "..//bgi");
for(font=0;font<=10;font++)
{
settextstyle(font,HORIZ_DIR,1);
outtextxy(x,y,"text with different fonts");
y=y+25;
}
getch();
closegraph();
}

***********************OUTPUT********************

/* Write a program of Rectangle Flood Fill */


#include<graphics.h>
#include<stdio.h>
#include<conio.h>

#include<stdlib.h>
#include<math.h>
dline(int,int,int,int);
void floodfill4(intx,inty,intfillcolor,intoldcolor);
void main()
{
int x1,y1,x2,y2;
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..\\bgi");
printf("enter the value of x1,y1");
scanf("%d%d",&x1,&y1);
printf("enter the value of x2,y2");
scanf("%d%d",&x2,&y2);
dline(x1,y1,x2,y1);
dline(x2,y1,x2,y2);
dline(x2,y2,x1,y2);
dline(x1,y2,x1,y1);
getch();
floodfill4((x1+x2)/2,(y1+y2)/2,12,0);
getch();
closegraph();
}
dline(int x1,int y1,int x2,int y2)
{
intdx,dy,step,xinc,yinc,x,y,k;
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,RED);
for(k=0;k<step;k++)
{
x=x+xinc;
y=y+yinc;

delay(10);
putpixel(x,y,RED);
}
}
void floodfill4(intx,inty,intfillcolor,intoldcolor)
{
if(getpixel(x,y)==oldcolor)
{
//setcolor(fillcolor);
putpixel(x,y,fillcolor);
floodfill4(x+1,y,fillcolor,oldcolor);
floodfill4(x-1,y,fillcolor,oldcolor);
floodfill4(x,y+1,fillcolor,oldcolor);
floodfill4(x,y-1,fillcolor,oldcolor);
}
}

*****************Output**********************

/* Write a program of 2D Bar*/


#include<graphics.h>

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
intgdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"..//bgi");
bar(100,100,200,200);
getch();
closegraph();
}

*****************************Output*****************
****

You might also like