Click here to Skip to main content
11,922,363 members (38,215 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked

Fun with the Console, Animating the American Flag (Visual C++ 6.0)

, 5 Jun 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Have some fun with the console, animate the American flag
Please maximize the console window to rectify any overdraw when running the EXE.


This is one of those projects you did just because you thought it would be fun to do and you had some spare time left. Well, let's animate some flags, shall we...

First we create a new project and class, let's name our class CFunWithConsole and put some variables and functions in it.

The project files are:

CManCFunWithConsole_main.cpp The main file
CFunWithConsole.cpp The class definition and method body file
CFunWithConsole.h The class declaration file
CTextMode.h The Console textmode graphics class

The CFunWithConsole Class

Ok, our class CFunWithConsole will inherit some graphics function methods like draw lines, boxes and circles from the class CTextMode so we need to include this syntax:

CMandelzoom::CMandelzoom( int i) : CTextMode()

Now after the inheritance the function methods in CTextMode.h have become "one" with the function methods in our class CMandelzoom. We can now treat those methods as if they were native to CFunWithConsole. Now we can draw lines, boxes and circles.
We have also placed variables we want to be initialized at start up in the constructor so that when our class is being instantiated, those variables get initialized.

The Class Header File CFunWithConsole.h

And now the application itself. We choose not to define and embody our member functions in the header file, we will just put the prototypes in CFunWithConsole.h.

#ifndef CFunWithConsole_H
#define CFunWithConsole_H

#include "CTextMode.h"

class CFunWithConsole: public  CTextMode

		int shiftX[9];
		int shiftY[8];
		int addX[9];
		int addY[8];

		CFunWithConsole( int i);
		void animateFlag(void);
		void VersionInfo(void);


#endif CFunWithConsole_H

The Class Definition File CFunWithConsole.cpp

In CFunWithConsole.cpp, we will define and embody our member functions with function calls, syntaxes and statements. Our class CFunWithConsole inherits function methods from the class CTextMode so we need to include this syntax:

CFunWithConsole::CFunWithConsole( int i) : CTextMode() 

The Constructor

We have placed function calls we want to be initialized at start up in the constructor so that when our class is being instantiated, those function methods get called and executed. We have also placed a while(true) loop that never exits, so that our flag will animate indefinitely.

// CFunWithConsole.cpp

CFunWithConsole::CFunWithConsole( int i) :  CTextMode()   
{       //variables to be initialized
	shiftX[0]=50;shiftX[1]=51;shiftX[2]=52;shiftX[3]=52; //curved alignment for flag




	 while(true)          //eternity loop

The animateFlag() Method

The method animateFlag() animates the flag by simply shifting a block of bytes back and forth. The bytes that are being moved have been aligned in a curved fashion in the constructor prior to this function call. The blocks have also received a color scheme which is the same color scheme as the flag.

void CFunWithConsole::animateFlag(void)
	  for (int ii=0;ii<9;ii++)
		  if (shiftX[ii]<50 || shiftX[ii]>52) addX[ii]=-addX[ii];

           txtLine(50,5,50 ,22,15);     //draw flag pole

	   txtLine(1,22,78,22,10);      //draw green grass






The Main File

Finally the file CFunWithConsole_main.cpp is where we create an instance for our class and run our application.

#include "CFunWithConsole.h"

int main()
  CFunWithConsole *animateFlag = new CFunWithConsole(1);

  return 0;

The Console's color codes are as follows:

Black 0
Blue 1
Green 2
Cyan 3
Red 4
Magenta 5
Yellow 6
White 7
Gray 8
LightBlue 9
LightGreen 10
LightCyan 11
LightRed 12
LightMagenta 13
LightYellow 14
BrightWhite 15

Thanks for reading.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 3 Pin
Harrison H9-Nov-10 10:42
memberHarrison H9-Nov-10 10:42 
If the article generator stuff is true, the vote goes down.

However, I do think you showed some cool console stuff. Though, just from a design perspective, there are things I would have done differently. For instance, even though it gets the job done and does what it's supposed to, it's highly unorthodox to have an infinite loop inside of a constructor. And even though the OS will cleanup your memory for you, the only way you can get the program to run is by newing the flag variable, then you just lose control of the app.
GeneralMy vote of 1 Pin
Niklas Lindquist7-Jun-10 7:51
memberNiklas Lindquist7-Jun-10 7:51 
GeneralMy vote of 1 Pin
xliqz4-Jun-10 6:20
memberxliqz4-Jun-10 6:20 
GeneralMy vote of 1 Pin
eds2-Jun-10 9:45
membereds2-Jun-10 9:45 
GeneralMy vote of 1 Pin
DAKL2-Jun-10 2:06
memberDAKL2-Jun-10 2:06 
GeneralMy vote of 1 Pin
narfzort1-Jun-10 16:23
membernarfzort1-Jun-10 16:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151120.1 | Last Updated 6 Jun 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid