C++ gurus and learners, we program ourselves :P all work is CC licensed

Showing posts with label special effect. Show all posts
Showing posts with label special effect. Show all posts

Tuesday, November 19

Easy Colouring

As promissed here is bit easy technique for those colour commands;
Hope you guys understand it :
Theme here is to use funcitons to determin command stuff i.e. how much easy would it be if you only have to type 

color(r); //red colour

here is the function that will help you to use colours easily
______________________________________________________________________

  1. HANDLE Output=GetStdHandle(STD_OUTPUT_HANDLE);
  2. void colour(int x)
  3. {SetTextAttribute(Output,x);}
______________________________________________________________________
here if you remember colour codes integers just use them as follows:

colour(10);      //green


and if you want to make it runing upon character values you can place switch in it

  1. HANDLE Output=GetStdHandle(STD_OUTPUT_HANDLE);
  2. void colour(char ch)
  3. {
  4. int x;
  5. switch (ch)
  6. {
  7. case 'r':  x=12; break;                       //red
  8. case 'b': x=9;   break;                        //blue
  9. case 'g': x=10; break;                        //green
  10. case 'a': x=11; break;                        //aqua
  11. case 'v': x=13; break;                         //voilet
  12. case 'y': x=14; break;                         //yellow
  13. case 'w: x=15; break;                         //white
  14. }
  15.  SetTextAttribute(Output,x);
  16. }

now you can call it as this;
colour('r');                    //red colour
end of post;




Sunday, November 17

Loading bar in C++

Since we are high on special effects these days, so below is the code to make a loading bar in C++.

#include iostream.h
#include conio.h
#include windows.h
#include dos.h

void main()
{
 system("color 0a");
 cout<<"\n\n\n\t\t\t\tPlease wait while loading\n\n";
 char a=177, b=219;
 cout<<"\t\t\t\t";
 for (int i=0;i<=15;i++)
 cout<<a;
 cout<<"\r";
 cout<<"\t\t\t\t";
 for (int i=0;i<=15;i++)
 {
  cout<<b;
  for (int j=0;j<=1e8;j++); //You can also use sleep function instead of for loop
 }

 clrscr();
 cout<<"\n\n\n\t\t\tHELLO WORLD\n\n\t\t\tShashka made by Ivan :P";

 getch();
}

Output is :