Posts

Showing posts from 2013

Pie Chart: Using C/C++ and graphics

Image
Hey guys, its very simple illustration of pie chart but it is not exactly how it works. In next post I will post how to take input from user and then generate the pie chart and bar graph. Here is the screen shot of the output. Pie-chart using C/C++ and Graphics Here's the code, enjoy coding.. /*     Programmer : Ashok Kumar Shrestha (ak007)     Program details : Pie chart */ #include<stdio.h> #include<graphics.h> #include<conio.h> int main() {    int gd = DETECT, gm, midx, midy;    initgraph(&gd,&gm,"..\\bgi");    setcolor(11);    rectangle(0,40,639,450);    settextstyle(1,0,2);    midx = getmaxx()/2;    midy = getmaxy()/2;    setfillstyle(2,1);    pieslice(midx, midy, 0, 72, 100);    setfillstyle(3,2);    pieslice(midx, midy, 72, 225, 100);    setfillstyle(4,4);    pieslice(midx, midy, 225, 360, 100);    setcolor(14);    outtextxy(275,10,"Pie Chart");    outtextxy(midx-175, midy - 75, "41%");    outtextxy(midx+100

Bar Graph: Using C/C++ and Graphics

Image
Hey guys, today I am going to post simple illustration of bar graph. May be next post I will post how to simulate bar graph with user input. Here is the screen shot of the out put. Bar Graph using C/C++ and Graphics Here is the code, enjoy coding... /*     Progammer : Ashok Kumar Shrestha (ak007)     Program details: Bar Graph */ #include<stdio.h> #include <graphics.h> #include <conio.h> int main() {    int gd = DETECT, gm;    initgraph(&gd,&gm, "..\\bgi");    setfillstyle(1,1);    bar(0,10,639,450);    setcolor(11);    rectangle(0,10,639,450);    line(200,35,450,35);    settextstyle(2,0,7);    setcolor(15);    outtextxy(275,10,"Bar Graph");    line(100,420,100,60);    line(100,420,600,420);    setlinestyle(2,0,7);    outtextxy(95,35,"Y");    outtextxy(610,405,"X");    outtextxy(85,415,"0");    setfillstyle(2,1);    bar(150,100,200,419);    setfillstyle(3,4);    bar(225,150,275,419);    setfillstyle(4,2

Smiley Face : Using C/C++ and Graphics

Image
Hey guys, today I am going to post very simple  yet beautiful program. This program generates smiley face at random position with different colors. If you guys like only particular color then eliminate the code to change color in while loop. And also if you like to see bigger or smaller smiley face then change the radius value. Here is the screen output of the code. Here's the code, enjoy coding... /*       Programmer : Ashok Kumar Shrestha (ak007)      Program details : Smiley face using C/C++ and graphics */ #include<graphics.h> #include<conio.h> #include<stdlib.h> #include<dos.h> main() {    int gd = DETECT, gm;    int x,y,color=14,radius=30,count=0;    initgraph(&gd,&gm,"C:\\TC\\BGI");    while(!kbhit())    {    x=rand()%600+20;    y=rand()%600+20;    setfillstyle(1,color);    fillellipse(x,y,radius,radius);    setfillstyle(1,0);    fillellipse(x-radius/2.5,y-radius/2.5,radius/8,radius/4);    fillellipse(x+radius/2.5,y-radi

Piano : Using C/C++ and Graphics

Image
Hey guys, today I am going to post one awesome program which I have been working for a quiet long time. It's not complete yet though, I will try to complete it soon. It's mini piano which we can play using keyboard. Press the keys as shown in the keyboard layout in the out put screen to play piano. If you want to exit, press Esc key. Here's the screenshot of the output. Here's the code: Note: Please save the file in .cpp extension if it is showing error. Make sure your speaker works properly because this program generates different sound according to key pressed. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program Description: mini piano v 1.0 */ #include<stdio.h> #include<conio.h> #include<dos.h> #include<graphics.h> #include<process.h> getkey() {     union REGS i,o;     while(!kbhit());     i.h.ah=0;     int86(22,&i,&o);     return (o.h.ah); } void welcome() {     clrscr();     gotoxy(30,

Architectural pattern: Using C/C++ and graphics

Image
Hey guys its very simple but beautiful architectural pattern using C/C++ with graphics.  I don't know its name, if you guys know then please leave a comment below. Here's the screen shot of the output. Now, let us see the codes. Here by changing the value of the n we can create different pattern. For this program I have choosen value as 15 but do try with other values also. Here's the code. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program Details: Generates Awesome Circular pattern 3.1 */ #include<graphics.h> #include<conio.h> #include<dos.h> #include<stdio.h> main() {    int gd = DETECT, gm, x, y, color, angle = 0,i,j;        char sstr[20];    int pat[2][200]={0};    int n=15;    struct arccoordstype a, b;    initgraph(&gd, &gm, "..\\BGI");    delay(200); for(i=0;i<n;i++)    {     setcolor(11);     arc(getmaxx()/2,getmaxy()/2,i*360/n,(i+1)*360/n,225);     getarccoords(&a);     pat[0][i]=a.xstart;     p

Loading..: Using C and graphics

Image
Hey guys, today I am posting a simple program which illustrate loading any videos or files. You might have seen this in while watching videos online. Well, here's the screen shot of the output. Let us see the codes now, hope you guys like it.. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program Details: Generates Circular pattern2.1  for loading */ #include<graphics.h> #include<conio.h> #include<dos.h> main() {    int gd = DETECT, gm, x, y, color, angle = 0;    struct arccoordstype a, b;    initgraph(&gd, &gm, "..\\BGI");    delay(200);    setcolor(11);    settextstyle(1,0,4);    outtextxy(260,380,"Loading...");    while(!kbhit())    {       setcolor(BLACK);       arc(getmaxx()/2,getmaxy()/2,angle,angle+2,100);       setcolor(8);       getarccoords(&a);       setfillstyle(SOLID_FILL,8);       circle(a.xstart,a.ystart,15);       floodfill(a.xstart,a.ystart,8);       setcolor(BLACK);       arc(getmaxx()/2,getmaxy()/2,(

Circular Pattern2: Using C and graphics

Image
Hey guys, today I am going to post very simple yet beautiful graphics program written in c. This program is derived from previous program that I have posted to draw circular pattern, you can say its the alternate form. Here's the screen shot of the output. This pattern revolves in 360 degree, which is similar to buffering circle you may find in youtube or other video streamer. In next post I will be writting how to design simple graphics program for buffering circle. Without further delay let us see the program.. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program Details: Generates Circular pattern2 */ #include<graphics.h> #include<conio.h> #include<dos.h> main() {    int gd = DETECT, gm, x, y, color, angle = 0;    struct arccoordstype a, b;    initgraph(&gd, &gm, "..\\BGI");    delay(200);    while(!kbhit())    {       setcolor(BLACK);       arc(getmaxx()/2,getmaxy()/2,angle,angle+2,100);       setcolor(RED);       getarccoord

Concurrent circular patterns: Using C and graphics

Image
Hey guys its very easy and small program to generate concurrent circular patterns. Here's the screen shot of the out put. Let us see the code, hope you guys like it.. /*     Programmer: Ashok Kumar Shrestha (ak007)     Program details: Generates concurrent circles by using circles. */ #include<graphics.h> #include<conio.h> #include<dos.h> main() {    int gd = DETECT, gm, x, y, color, angle = 0;    struct arccoordstype a, b;    initgraph(&gd, &gm, "..\\BGI");    delay(200);    while(angle<=360)    {       setcolor(BLACK);       arc(getmaxx()/2,getmaxy()/2,angle,angle+2,100);       setcolor(4);       getarccoords(&a);       circle(a.xstart,a.ystart,25);       setcolor(BLACK);       arc(getmaxx()/2,getmaxy()/2,angle,angle+2,150);       getarccoords(&a);       setcolor(2);       circle(a.xstart,a.ystart,25);       setcolor(BLACK);       arc(getmaxx()/2,getmaxy()/2,angle,angle+2,200);       getarccoords(&a);       setcolor(3);  

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