Skip to main content

Posts

Showing posts with the label GRAPHIC CODING

Balloon Shooting Games

Just to tell you  its a very hard program to make with out error # include "graphics.h" # include "conio.h" # include "stdio.h" # include "stdlib.h" # include "dos.h" #define ARROW_SIZE 7 #define BALLOON_SIZE 3 // Downloaded from www.indiaexam.in int flag_arrow=0,flag_balloon=1,count_arrow=6,count_balloon=10; void *balloon,*bow,*arrow,*burst; void *clear_balloon,*clear_burst; void draw_balloon(int ,int ); void draw_burst ( int x, int y ); void draw_bow(int x,int y); void draw_arrow(int x, int y); void shoot(int *x, int *y); int testkeys(); void fly(int *x, int *y); void start(); void main() { int gmode = DETECT, gdriver , area ; initgraph ( &gmode, &gdriver, "c:\tc\bgi\ " ) ; setbkcolor(1); start(); int maxx = getmaxx() ; int maxy = getmaxy() ; int p=400,q=300,m=100,n=100,x=m,y=n,key,score=0,finish=0,level=1,l_flag=1; char score1[5],ch,cnt_ball[5],char_level[2]; rectangle ( 0, 0, maxx...

Computer Graphics sample source codes

# include <graphics.h> # include <conio.h> # include <dos.h> # include <stdlib.h> void intro() {   clrscr();   int gd=DETECT,gm,i=0;   detectgraph(&gd,&gm);   initgraph(&gd,&gm,"c:\tc\bgi");   rectangle(0,5,630,400);   rectangle(10,15,620,390);       settextstyle(1,0,1);   outtextxy(245,238,"DESIGNER");  while(!kbhit())  {    setcolor(i);        settextstyle(2,0,0);   outtextxy(32,170,"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");   outtextxy(32,178,"* *");   outtextxy(32,186,"* *");   outtextxy(32,196,"* *"); outtextxy(32,205,"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");    setfillstyle(XHATCH_FILL,i++);    delay(200);    floodfill(2,9,15);    if(i>=15) ...

Program to change the background colors on the screen

#include <conio.h> #include <graphics.h> #include <stdlib.h> #include <stdio.h> void main (int) { int gdriver=DETECT,gmode,errorcode; //Requesting auto-detection. int midx,midy,x; //Initializing graphics and local variables. initgraph(&gdriver,&gmode,"d:\\bc3\\bgi"); //Reading result of initialization. errorcode=graphresult(); if(errorcode!=grOk) //An error occurred. { printf("Graphics error occurred : %s \n",grapherrormsg(errorcode)); printf("Press any key to stop : "); getch(); exit(1); //Terminate the program due to error. } /*Changing the background color. Note : Press enter to see the first screen as it is black and it may appear as if the program has stopped running.*/ for(x=0;x<=15;x++) { setbkcolor(x); getch(); } closegraph(); } This graphics program changes the background colors on the screen gradually from black to white using the 'setbkcolor' command. Posted By :- Cplus...

Program to plot pixels

#include <conio.h> #include <graphics.h> #include <stdlib.h> #include <stdio.h> void main (int) { int gdriver=DETECT,gmode,errorcode; //Requesting auto-detection. int midx,midy,x; //Initializing graphics and local variables. initgraph(&gdriver,&gmode,"d:\\bc3\\bgi"); //Reading result of initialization. errorcode=graphresult(); if(errorcode!=grOk) //An error occurred. { printf("Graphics error occurred : %s \n",grapherrormsg(errorcode)); printf("Press any key to stop : "); getch(); exit(1); //Terminate the program due to error. } for(x=40;x<120;x=x+10) { putpixel(x,200,14); //Plots 1 pixel at position(x,200) with YELLOW color(14) getch(); } } This graphics program plots eight yellow-colored pixels on the screen using the 'putpixel' command. Posted By :- Cplusplusprogramming

Putimage function in c

putimage function outputs a bit image onto the screen. Declaration:- void putimage(int left, int top, void *ptr, int op); putimage puts the bit image previously saved with getimage back onto the screen, with the upper left corner of the image placed at (left, top). ptr points to the area in memory where the source image is stored. The op argument specifies a operator that controls how the color for each destination pixel on screen is computed, based on pixel already on screen and the corresponding source pixel in memory. c smiling face animation This animation using c draws a smiling face which appears at random position on screen. See output below the code, it will help you in understanding the code easily. C programming code #include<graphics.h> #include<conio.h> #include<stdlib.h>   main() { int gd = DETECT, gm, area, temp1, temp2, left = 25, top = 75; void *p;   initgraph(&gd,&gm,"C:\\TC\\BGI");   setcolor(YELLOW)...

Imagesize function in c

imagesize function returns the number of bytes required to store a bitimage. This function is used when we are using getimage. Declaration:- unsigned int imagesize(int left, int top, int right, int bottom); C programming code for imagesize #include <graphics.h> #include <conio.h> main() {    int gd = DETECT, gm, bytes;    char array[100];    initgraph(&gd, &gm, "C:\\TC\\BGI");    circle(200, 200, 50);    line(150, 200, 250, 200);    line(200, 150, 200, 250);    bytes = imagesize(150, 150, 250, 250);    sprintf(array, "Number of bytes required to store required area = %d", bytes);    outtextxy(10, 280, array);    getch();    closegraph();    return 0; } OUTPUT Posted By :- Cplusplusprogramming

Ellipse function in c

Declarations of ellipse function :- void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius); Ellipse is used to draw an ellipse (x,y) are coordinates of center of the ellipse, stangle is the starting angle, end angle is the ending angle, and fifth and sixth parameters specifies the X and Y radius of the ellipse. To draw a complete ellipse strangles and end angle should be 0 and 360 respectively. C programming code for ellipse #include<graphics.h> #include<conio.h> main() {    int gd = DETECT, gm;    initgraph(&gd, &gm, "C:\\TC\\BGI");    ellipse(100, 100, 0, 360, 50, 25);    getch();    closegraph();    return 0; } OUTPUT Posted By :- Cplusplusprogramming

Floodfill function

Declaration :- void 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. C programming code #include<graphics.h> #include<conio.h> main() {    int gd = DETECT, gm;    initgraph(&gd, &gm, "C:\\TC\\BGI");    setcolor(RED);    circle(100,100,50);    floodfill(100,100,RED);    getch();    closegraph();    return 0; } In the above program a circle is drawn in RED color. Point (100,100) lies inside the circle as it is the center of circle, third argument to floodfill is RED which is color of boundary o...

C++ Computer Graphics sample source codes

Moving ball screensaver, in which two balls are bounchback from the wall of the console. */ #include"graphics.h" #include"dos.h" #include"conio.h" #include"stdlib.h" #define DELAY 1 #define SOUND 3500 void state(int x,int y,int mode); int i; void *ptr1[4],*ptr2[4]; /* 3d Ball */ char ball[20][20]= { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,12,12,12,12,12,12,12,12,0,0,0,0,0,0}, {0,0,0,0,12,12,12,12,12,12,12,12,12,12,12,12,0,0}, {0,0,0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0,0,0}, {0,0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0,0}, {0,0,12,12,12,12,12,15,15,12,12,12,12,12,12,12,12,12,0,0}, {0,12,12,12,12,12,15,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,12,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,15,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,15,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,15,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12...

C++ Computer Graphics sample source codes

Progress bar #include<graphics.h> #include<conio.h> #include<alloc.h> #include<dos.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c:\tc ");   //put your directory where egavga.bgi is void   *buffer; unsigned int size; setbkcolor(BLUE); line(230,330,370,330); line(230,350,370,350); line(226,335,226,345); line(226,335,230,330); line(226,345,230,350); line(374,335,374,345); line(374,335,370,330); line(374,345,370,350); outtextxy(275,365,"Loading");  //put you text here int x=232,y=336,x1=236,y1=344; for(int i=1;i<5;i++) { setfillstyle(1,RED); bar(x,y,x1,y1); x=x1+2; x1=x1+6; } size=imagesize(232,336,256,344); buffer=malloc(size); getimage(232,336,256,344,buffer); x=232; int m=0; while(!kbhit()) { putimage(x,336,buffer,XOR_PUT); x=x+2; if(x>=350) { m++; x=232; if(m==5)                         // m is no of times bar moves re...

C++ Computer Graphics sample source codes

Pari man walk and jump #include<iostream.h> #include<conio.h> #include<dos.h> #include<stdio.h> #include<graphics.h> #include<math.h> #include<string.h> #include<time.h> float main(void)  {   int*p1,*p2,*p;   clock_t start,end;   time_t t,t1;   int z=0,z1=0;   int gdriver = DETECT, gmode, errorcode;   initgraph(&gdriver, &gmode, "");   int r=0;   int ch,x=10,y=350;   int poly[100],poly1[100],variable1;   setcolor(14);   ellipse(100,105,180,0,10,15);   ellipse(93,125,320,50,3,7);   ellipse(105,125,130,270,3,7);   ellipse(110,112,250,90,3,2);   line(93,128,108,133);   putpixel(100,120,4);   poly[0]=105;   poly[1]=105;   poly[2]=103;   poly[3]=108;   poly[4]=101;   poly[5]=109;   poly[6]=101;   poly[7]=111;   poly[8]=100;   poly[9]=108;   poly[10]=98; ...

Bar function in c

Declaration :- void bar(int left, int top, int right, int bottom); Bar function is used to draw a 2-dimensional, rectangular filled in bar . Coordinates of left top and right bottom corner are required to draw the bar. Left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner. Current fill pattern and fill color is used to fill the bar. To change fill pattern and fill color use setfillstyle. #include <graphics.h> #include <conio.h> main() {    int gd = DETECT, gm;    initgraph(&gd, &gm, "C:\\TC\\BGI");    bar(300, 300, 400, 400);    getch();    closegraph();    return 0; } OUTPUT:- Posted By:- Cplusplusprogramming

Arc function in c

Declaration :- void arc(int x, int y, int stangle, int endangle, int radius); arc function is used to draw an arc with center (x,y) and stangle specifies starting angle, endangle specifies the end angle and last parameter specifies the radius of the arc. arc function can also be used to draw a circle but for that starting angle and end angle should be 0 and 360 respectively. #include<graphics.h> #include<conio.h> main() {    int gd = DETECT, gm;    initgraph(&gd, &gm, "C:\\TC\\BGI");    arc(100, 100, 0, 135, 50);    getch();    closegraph();    return 0; } OUTPUT Posted By :- Cplusplusprogramming

How is Graphic used

First of all we have to call the initgraph function that will intialize the graphics mode on the computer. initigraph have the following prototype.  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 graphresult 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. *...

Moving Car C++ Program

#include <graphics.h> #include <dos.h> int main() {    int i, j = 0, gd = DETECT, gm;    initgraph(&gd,&gm,"C:\\TC\\BGI");    settextstyle(DEFAULT_FONT,HORIZ_DIR,2);    outtextxy(25,240,"Press any key to view the moving car");    getch();    for( i = 0 ; i <= 420 ; i = i + 10, j++ )    {       rectangle(50+i,275,150+i,400);       rectangle(150+i,350,200+i,400);       circle(75+i,410,10);       circle(175+i,410,10);       setcolor(j);       delay(100);       if( i == 420 )          break;       if ( j == 15 )          j = 2;       cleardevice(); // clear screen    }    getch();    closegraph();    return 0; } Posted By :-  Cpluspluspr...