Tuesday, 24 February 2015

Graphics Programming in C++

/* rectangle, outtextxy, setbkcolor */

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

void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,” “);
clrscr();
line(200,0,0,200);
line(300,100,100,300);
line(100,300,0,200);
line(300,100,200,0);
outtextxy(125,150,”AYYAPPAN”);
setbkcolor(13);
getch();
closegraph();
}

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,n;
initgraph(&gd,&gm,” “);
clrscr();
n=0;
while(n<=15)
{
outtextxy(200,200,”Enter a number(0-15)”);
cin>>n;
setbkcolor(n);
}
getch();
}

/*settextstyle(int font,int direction, int size);

font = 0 to 11
direction = 0 or 1; HORIZ_DIR or VERT */
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,” “);
clrscr();
settextstyle(4,0,5);
outtextxy(200,200,”AYYAPPAN”);
getch();
}

/* setfillstyle(style,color);
Styles    {“EMPTY_FILL”,
                     “SOLID_FILL”,
                     “LINE_FILL”,
                     “LTSLASH_FILL”,
                     “SLASH_FILL”,
                     “BKSLASH_FILL”,
                     “LTBKSLASH_FILL”,
                     “HATCH_FILL”,
                     “XHATCH_FILL”,
                     “INTERLEAVE_FILL”,
                     “WIDE_DOT_FILL”,
                     “CLOSE_DOT_FILL”,
                     “USER_FILL”}; */

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,” “);
clrscr();
arc(200,200,0,90,50);
setfillstyle(6,5);
pieslice(200,200,0,180,50);
                             360,100     
getch();
}

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

void main()
{
int gd=DETECT,gm,n,x;
char ch;
initgraph(&gd,&gm,” “);
clrscr();
n=0;
x=30;
while(ch!=’x’)
{
if(n>=15)
n=0;
setcolor(n);
circle(270,220,x);
ch=getch();
n=n+1;
x=x+10;   (or)     x=x-5;
}
getch();
}

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
int main(void)
{
int gdriver=DETECT,gmode,errorcode;
int midx,midy,i;
initgraph(&gdriver,&gmode,” “);
clrscr();
bar3d(200,200,100,100,10,1);
getch();
}

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x1=100,x2=200,y1=200,y2=200;
initgraph(&gd,&gm,” “);
clrscr();
line(x1,y1,x2,y2);
line(x1,y1,x1+50,y1-100);
line(200,200,150,100);
getch();

}

No comments:

Post a Comment