Smiley Face : Using C/C++ and Graphics

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-radius/2.5,radius/8,radius/4);

   setcolor(0);
   //ellipse(x,y,205,335,radius/5*4,radius/2.5+2);
   ellipse(x,y,205,335,radius/5*4,radius/2.5+3);
   ellipse(x,y,205,335,radius/5*4,radius/2.5+4);
   delay(100);
   count++;
   color=(color+1)%15+1;
   if(count==80)
   {
   count=0;
   cleardevice();
   }
   }
   getch();
   closegraph();
   return 0;
}
//End of the program

Comments

Post a Comment

Popular posts from this blog

Wizard Quiz: Privacy Policy

Sorting Hat: Privacy Policy

mTranslator