ascii art video (8)

1 Name: #!/usr/bin/anonymous : 2007-03-30 12:58 ID:i/U9NfhD

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);
}
}

2 Name: #!/usr/bin/anonymous : 2007-03-31 02:19 ID:Heaven

>>1

You know, you could just print ^L to the screen to clear it.

3 Name: #!/usr/bin/anonymous : 2007-03-31 04:05 ID:i/U9NfhD

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;
}

4 Name: #!/usr/bin/anonymous : 2007-04-01 21:40 ID:Heaven

> static_cast<long int>(seconds * CLOCKS_PER_SEC) ;

Real people write code like this? Damn.

5 Name: #!/usr/bin/anonymous : 2007-04-05 22:14 ID:Heaven

>>4
How else would one write code?

6 Name: #!/usr/bin/anonymous : 2007-04-07 01:46 ID:Heaven

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.

7 Name: #!/usr/bin/anonymous : 2007-04-07 04:17 ID:Heaven

> system("cls");

Real people write code like this? Damn.

8 Name: #!/usr/bin/anonymous : 2007-04-20 16:35 ID:Heaven

>>6
That's what -Werror is for.

This thread has been closed. You cannot post in this thread any longer.