here's a little one i wrote last month... it's pretty basic. If you want to make your own animation, use the header file for reference
/*
ascii animated video program
To create an AAV, simply create a text file with the following format
3 <--- height of current frame
000 \
000 |---content of frame (doesn't matter how wide, as long as it's the same hight as specified
000 /
1 <--- how long the frame lasts in seconds (can be a decimal value, e.g 0.04 is 1/25th of a second
just keep on adding sections like this to build it up frame by frame
enjoy!
(copyright 2007 dominic rudkin, distriputed under the lesser GPL)
*/
#include <iostream>
#include <stdio.h>
#include <time.h>
#include<cstdlib>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
void wait ( double seconds )
{
clock_t endwait;
endwait = clock () + static_cast<long int>(seconds * CLOCKS_PER_SEC) ;
while (clock() < endwait) {}
}
int main()
{
string line,filename;
int height;
double frame;
cout << "Enter filename: ";
cin >> filename;
ifstream file(filename.c_str());
if(!file)
{
cerr << "Error opening file " << filename <<endl;
return EXIT_FAILURE;
}
vector<std::string> contents_of_file;
while(getline(file, line))
{
contents_of_file.push_back(line);
height = static_cast<int>(strtod(line.c_str(), NULL));
while (height > 0)
{
system("cls"); // Use this if you're on windows
//system("clear"); comment out above and uncomment this if you're running linux/unix
getline(file, line);
contents_of_file.push_back(line);
cout << line << endl;
height = height-1;
}
getline(file, line);
contents_of_file.push_back(line);
frame = strtod(line.c_str(), NULL);
wait (frame);
}
}
You know, you could just print ^L to the screen to clear it.
improved it for cpu useage and loopability.
/*
ascii animated video program
To create an AAV, simply create a text file with the following format
3 <--- height of current frame
000 \
000 |---content of frame (doesn't matter how wide, as long as it's the same hight as specified
000 /
1 <--- how long the frame lasts in seconds (can be a decimal value, e.g 0.04 is 1/25th of a second
just keep on adding sections like this to build it up frame by frame
enjoy!
(thanks for the insults and better code from the /prog/ assholes)
(copyright 2007 dominic rudkin)
*/
#include <iostream>
#include <stdio.h>
#include <time.h>
#include<cstdlib>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <windows.h>
#define WINDOWS
using namespace std;
void clear()
{
#ifdef WINDOWS
system("cls");
#endif
#ifdef LINUX
system("clear");
#endif
}
void wait ( double seconds )
{
clock_t endwait;
endwait = clock () + static_cast<long int>(seconds * CLOCKS_PER_SEC) ;
}
int main()
{
string line,filename;
int height,loop;
double frame;
cout << "Enter filename: ";
cin >> filename;
cout << endl << "loop file? (1=yes, 0=no): ";
cin >> loop;
ifstream file(filename.c_str());
if(!file)
{
cerr << "Error opening file " << filename <<endl;
return EXIT_FAILURE;
}
vector<std::string> contents_of_file;
do
{
ifstream file(filename.c_str());
while(getline(file, line))
{
contents_of_file.push_back(line);
height = static_cast<int>(strtod(line.c_str(), NULL));
while (height > 0)
{
getline(file, line);
contents_of_file.push_back(line);
cout << line << endl;
--height;
}
getline(file, line);
contents_of_file.push_back(line);
frame = strtod(line.c_str(), NULL);
contents_of_file.clear();
Sleep(static_cast<int>(frame*1000));
clear();
}
}while (loop==1);
return 0;
}
> static_cast<long int>(seconds * CLOCKS_PER_SEC) ;
Real people write code like this? Damn.
>>4
How else would one write code?
correct me if i'm wrong (i'm not a c++ programmer), but as far as i can surmise from the internets, this static_cast business is basically just a normal c (cast) but whinges with an error when the conversion is unsafe, instead of just a warning.
> system("cls");
Real people write code like this? Damn.
>>6
That's what -Werror is for.