I have to tell you a story of my own, and it is real.
When I was little boy, I have persuaded my parents to buy a ‘expensive’ (at that time at least) famicom (with keyboard). I lied to them that I used that for study programming but in fact, I spent most of the time in playing 8-bit NES games :).
However, my parents one day asked me to show them the programs I ‘ve made… I had to come up with any idea (any programming tasks) and demonstrated to them the programming skills, well in BASIC (most famicoms come up with the BASIC programming language).
I programmed a flying rocket at that time with the first generation of BASIC (the one that makes you to put the line number before each statement and use goto to jump to different statements).
Many years later, I’ve lost already the original BASIC program but here is the simple alternative to do it in C/C++.
First, download [here] (windows platform) or [here] (ubuntu platform) for this simple animation application made using G++ complier (v.4.6)
The idea is simple: go to the bottom of the console (print a couple of empty lines would do it, DO NOT USE gotoxy(), which is not platform independent); then print the ASCII pattern of the rocket (google for it); and print empty line each time to make rocket fly upward (adjust the speed by changing the time interval for next print). This is based on the scrolling in console. So be sure to print lots of lines at the beginning, which will make sure the current cursor is at the bottom of the console. Everytime a new empty line is printed, the console will scroll up a line for the current screen content, which makes it look like the rocket is flying up! A bit tricky, isn’t it? but it works perfectly!
Here is how it shows on Windows console.
And on Ubuntu (or *nix), you can edit the source in your favourite editor (vim, vi etc)
and compile it using g++ -o rocket rocket.c
Launch it!
Try it now! Here is the complete C/C++ source code for this simple rocket!:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | /* Author: http://HelloACM.com http://CodingForSpeed.com */ #include <stdio.h> #include <unistd.h> // for usleep function const char rocket[] = " _\n\ /^\\\n\ |-|\n\ | |\n\ |N|\n\ |A|\n\ |S|\n\ |A|\n\ /| |\\\n\ / | | \\\n\ | | | |\n\ `-\"\"\"-`\n\ "; int main() { for (int i = 0; i < 50; i ++) printf("\n"); // jump to bottom of console printf("%s", rocket); int j = 300000; for (int i = 0; i < 50; i ++) { usleep(j); // move faster and faster, j = (int)(j * 0.9); // so sleep less each time printf("\n"); // move rocket a line upward } printf("Visit http://HelloACM.com !\n"); return 0; } |
/* Author: http://HelloACM.com http://CodingForSpeed.com */ #include <stdio.h> #include <unistd.h> // for usleep function const char rocket[] = " _\n\ /^\\\n\ |-|\n\ | |\n\ |N|\n\ |A|\n\ |S|\n\ |A|\n\ /| |\\\n\ / | | \\\n\ | | | |\n\ `-\"\"\"-`\n\ "; int main() { for (int i = 0; i < 50; i ++) printf("\n"); // jump to bottom of console printf("%s", rocket); int j = 300000; for (int i = 0; i < 50; i ++) { usleep(j); // move faster and faster, j = (int)(j * 0.9); // so sleep less each time printf("\n"); // move rocket a line upward } printf("Visit http://HelloACM.com !\n"); return 0; }
We use \ to split the string literal into multi-line.
Update: My son just has his version of launching the rocket in Python: The Simple Console Rocket Animation in Python
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: The Matrix Printing Animation in C++
Next Post: Simple C++ Starfield Animation Based on Codepage 437
Bottom to top may vary the y position from bottom to top value coordinate, and left to rigth you must vary the x coordinate from lefr to rigth value. This is the fact i think. I hope it help you.
Its not working getting errors:
line 2: Unable to open include file ‘UNISTD.H’
line 21: Declaration terminated incorrectly
line 21: Declaration syntax error
line 21: Declaration syntax error
line 23: ) expected
line 25: Declaration terminated incorrectly
line 25: Declaration syntax error
line 25: Declaration syntax error
line 32: Declaration terminated incorrectly
line 33: Unexpected }
which C/C++ compiler (and which OS) are you using?
same problem here
thank you for help me..
but i want more c coding for rocket and i have to move it from bottom to top or left to right if possible than please help me more this is my computer graphic project. and i have some idea but i can’t go through it because of time limit. try to help me fast as possible…
thank you respected sir/madam.
Yes, it would be much more complex animation from left to right or right to left