Posts

Showing posts from October, 2013

Magic Square: Using c/c++ with graphics

Image
Hey guys, today I am going to post another interesting game, magic square. Its the game where you have to fill the boxes with numbers from 1 to total number of boxes such that sum of any row or column must be equal to other. Here's the link if you want to know how to solve it.                            http://www.wikihow.com/Solve-a-Magic-Square Here's the screen shot of the output. Here I have chosen 9x9  box, you can choose any one you like. With out further due let us see the codes. Note : Please save the program in .cpp format to run the program or else you can change the declaration portion to run in .c format. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program details: Magic square, Fill the empty boxes such that sum              of all the numbers in column or row will be equal.              Use mouse pointer and click left button to place              number in ascending order. */ #include<graphics.h> #include<stdio.h> #include<coni

Unlock Pattern: Using C/C++ and graphics

Image
Hey guys, its cool program which depicts android unlock pattern. Use mouse pointer to draw the pattern and then set the password. After password is set try to unlock the pattern. If you have drawn correct pattern you will be asked to set new pattern. Here's the screen shot of the output. here's the program, enjoy coding... /*     Programmer : Ashok Kumar Shrestha (ak007)     Program details : pgm to set the password and match it using mouse v2.0 */ #include<iostream.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<math.h> #include<process.h> union REGS i,o; struct SREGS s; initmouse() {     i.x.ax=0;     int86 (0x33,&i,&o);     return(o.x.ax); } showmouseptr() {     i.x.ax=1;     int86 (0x33,&i,&o);     return 0; } changecursor(int *shape) {     i.x.ax=9;     i.x.bx=0;     i.x.cx=0;     i.x.dx=(unsigned)shape;     segread(&s);     s.es=s.ds;     int86x (0x33,&i,&i,&s);     return 0; }

Generating Random circle: using c/c++ and graphics

Image
Hey guys, in this post I am writing very short graphics program. This program generates random circle of random size. You can modify the delay time to see the effect more clearly. Here's the screen shot of the output. Here's the program. Enjoy coding... /*      Programmer: Ashok Kumar Shrestha (ak007)     Program details: Generates the random circle */ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<stdlib.h> #include<dos.h> int main() {     int i,j,x=0,y=0;     int color=0;     int gd=DETECT, gm;     initgraph(&gd,&gm,"..\\bgi");     cleardevice();     setcolor(0);     randomize();     while(!kbhit())     {         delay(70);         color=15-random(1500)%15;         setcolor(color);         setfillstyle(1,color);         x=639-random(90000)%639;         y=460-random(90000)%460;         circle(x,y,110-random(1000)%100);         floodfill(x,y,color);     }     return 0; } //End of the program

Circular Pattern Using C/C++ and Graphics

Image
Hey guys, today I am going to show you how to generate simple circular pattern using c/c++ and graphics. Here's the screen shot of the out put. Here is the code. Enjoy coding... Note: If the program is generating error in c  then please save the file with .cpp extension. /*     Programmer : Ashok Kumar Shrestha (ak007)     Program details : Genetrates circular pattern */ #include<graphics.h> #include<stdio.h> #include<conio.h> #include<dos.h> void main()        //two moving balls {     int gd = DETECT, gm;        int r=20;     int x=400,y=300,x1,y1,x2=x-200,y2=y-200, x3=x2+250,y3=y2+250;     int dx,dy;     int a=x-100,b=y-150,a1,b1,dx1=3,dy1=4;     initgraph(&gd,&gm,"..\\BGI");         dx=dx1=5;     dy=dy1=5;     rectangle(x2-1,y2-1,x3+3,y3+4);     x=300,y=200;     a=320,b=160;     while(!kbhit())     {         setcolor(2);         circle(x,y,r);         x1=x+dx;         y1=y-dy;         setcolor(3);         circle(a,b,r);      

Knight's tour game : Using C/C++ and graphics

Image
Hey guys, this is the classic game many of you chess lovers may know this. It's very simple game, you have to move knight piece (horse) starting at any place but move such that it has to cover all 64 boxes in 64 moves without repeatation and valid move is only "L" shape move. This is the move of knight, unlike any other chess pieces, knight moves in strange way making "L" shape. In this program, just click on the box you want to keep your knight piece such that it should meet above conditions. Here's the screen shot of the output. Here's the code, enjoy coding... Note : If the program is generating error in c please save the file with .cpp extension /*     Programmer : Ashok Kumar Shrestha (ak007)     Program details : KNIGHT'S TOUR USING BGI GRAPHICS IN C/C++ */ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<stdio.h> #include<process.h> #include<math.h> void knig

Loading page and hexagonal pattern using c/c++ and graphics

Image
Hey guys, here is the simple code to illustrate the loading of the page. We have seen like million times when we open some page it takes time to load and in that time they show that they are loading by using blinking circles or bars filling up to 100% and so on. In this code I have demonstrated how we can use same technique. After the compiler is done loading the page just press any key and hexagonal pattern will be formed using graphics. Hope you guys like it. Here's the screen shot of the output.   Here's the code. Enjoy coding... Note: If the code is generating error in c then please save the file with .cpp extension. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program details: Loading page and Hexagonal pattern */ #include<stdio.h> #include<conio.h> #include<dos.h> #include<graphics.h> #include<stdlib.h> #include<math.h>   void loading(); void hexagon(int ,int,int,int color); void pattern();   void main(

Yin - Yang : Using C and grahics

Image
Hey guys, here's the simple program to demonstrate Yin-Yang. Many of you might have seen the symbol but not have known the name. Here's the pic of the Yin- Yang. Yin - Yang can be thought of as the complementary forces balancing each other in a harmonious way. Yang is the white part with the black dot on it and Yin is the black part with the white dot in it. As mentioned in the figure, they can be veiwed as any complementary things such as negative-positive, light-dark, love-hate, sun-moon and so on. If we closely each part is complementary of other. So, some say for every living soul, male and female complement each other but as a whole they complete each other. If you want to know about the Yin-Yang then here is the link:        http://en.wikipedia.org/wiki/Yin_and_yang OK, without further due let us see the code. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program Details: Creates Yin - Yang and rotates in anticlockwise */ #include <graphics.h> #inc

Analogue Clock clockwise: Using C and Graphics

Image
Here's the analogue clock that runs clock wise direction. Hope you guys like it. Here's the screen shot of the output. Let's us see the code. The code is very much similar to the previous program that I have posted i.e. analogue clock which rotates in anti clockwise direction. Enjoy coding... /*     Programmer: Ashok Kumar Shrestha ak(007)     Program details: analog clock clockwise v1.0 3 april 2013 */ #include<stdio.h> #include<conio.h> #include<dos.h> #include<graphics.h> struct arccoordstype arcinfo,arcinfom,arcinfoh,arcinfod; void main() {     int gd=DETECT,gm;     initgraph(&gd,&gm,"c:\\tc\\bgi");     int x=getmaxx()/2,y=getmaxy()/2;     char sstr[40],estr[40]; ////////////////outer circles//////////////////////////////     setcolor(15);     circle(x,y,200);     circle(x,y,215); //////////////////numberes in clock////////////////////////     settextstyle(1,0,4);     for(int i=12;i>=1;i--)     {       setcolor(0);   

Analogue Clock - Anti _clockwise : Using C and graphics

Image
Hey guys, here's the cool program to generate the analogue clock which rotates in anti clock wise direction. Today's world has been totally digitized but still we prefer some things to be non digitalis ed. The analogue clock is a classic instrument back then and is still classic. Do you guys know that the word clock is derived from Celtic word Clagan and Clocca which means "Bell"? These sound cool right. Clock has been an important invention for mankind for keeping track of time. If you guys want to know more about the clocks then here is the link : http://en.wikipedia.org/wiki/Clock . OK without further delay let us go to our program. Here is the screen shot of the out put of the program. Enjoy coding.... /*     Programmer: Ashok Kumar Shrestha (ak007)     Program details: Analog clock anticlockwise v1.0 3 april 2013 */ #include<stdio.h> #include<conio.h> #include<dos.h> #include<graphics.h> struct arccoordstype arcinfo,arcinfom,arc

3D balls using c and graphics

Image
Hey guys, here is the simple graphics program. I have created three balls and given them random motion. When the balls hit the walls it is bounced back. Here is the screen shot of the output. Hope you guys like it. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program Details: 3d balls moving randaomly inside the              rectanglular box     Language: C and graphics */ #include<graphics.h> #include<stdio.h> #include<conio.h> #include<dos.h> void main()        //3 moving balls {     int gd = DETECT, gm;     initgraph(&gd,&gm,"..\\BGI");     int r=20;     int x1,y1,x2=150,y2=80, x3=500,y3=400;     int x=x3-25,y=y3-25;     int dx,dy;     int a[2],b[2],a1[2],b1[2],dx1[2],dy1[2];     a[1]=(x3+x2)/2,b[1]=(y3+y2)/2,dx1[1]=3,dy1[1]=4;     a[0]=x2+(x3-x2)/3,b[0]=y2+40,dx1[0]=3,dy1[0]=4;     dx=3;     dy=4;     rectangle(x2-2,y2-3,x3+5,y3+5);     delay(100);     while(!kbhit())    //while any key is not hit its true     {         x1=x+dx

15 SQUARE GAME using c with graphics

Image
Hey guys, this program is simple classic 15 square game. I have coded this using c and included graphics. Use the arrow keys to move the boxes. Here the aim is to arrange those 15 boxes in correct order before the time limit. Hope you guys like it... ////15 square game using c and graphics. #include<iostream.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<stdlib.h> #include<stdio.h> #include<time.h> void main(); getkey() {     union REGS i,o;     while(!kbhit());     i.h.ah=0;     int86(22,&i,&o);     return (o.h.ah); } int check(int mat[4][4],int n) {     int i,j;     if(mat[3][3]==0)    mat[3][3]=16;     for(i=0;i<n;i++)         for(j=0;j<n;j++)             if(mat[i][j]!=i*4+j+1)                 return 0;     return 1; } void win() {     gotoxy(28,5);     cout<<"Congrats! You have won....";     gotoxy(27,24);     cout<<"Do you want to try