Original Usenet thread from alt.ascii-art.animation, started 9 Feb 1994.
Slow down the animation
alt.ascii-art.animation
· 5 messages · 9 Feb 1994 - 1 Mar 1994
Most of the animation with goes by too quickly for me
to read text and such. Is there a way to cat the file
slowly?
--
-------
gRaPpLe: v) To struggle, grasp, restrain or tackle. gRa...@nEtCoM.CoM
Haywierd, Ca USA
In article <gra...@netcom.com> gra...@netcom.com (gRaPpLe) writes:
Newsgroups: alt.ascii-art.animation
From: gra...@netcom.com (gRaPpLe)
Organization: The Corner Of B & Kelly
Date: Wed, 9 Feb 1994 09:58:25 GMT
Most of the animation with goes by too quickly for me
to read text and such. Is there a way to cat the file
slowly?
I wrote a quick hack called scat that does does this. It does
character by character I/O with a delay function called between
characters. In fact, the call to usleep() in delay() is currently
commented out because it was slow enough just forcing things to be
character by character.
Rick
- - - - - - - - - - - - - - - - Cut here - - - - - - - - - - - - - - -
/* -*- Mode: C -*- */
/*
* scat - intentionally slow version of cat
*
* This code has been put in the public domain by the author.
*
*/
static const char RCS_Id [] =
"$Id: scat.c,v 1.3 1993/12/13 15:13:48 rfb Exp $";
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
static char* program_name = NULL;
static void delay (void);
int main (int, char**);
static void process_file (const char* file);
static void process_stream (FILE* stream);
static void
delay (void)
{
/* usleep (1000); */
}
int
main (int argument_count,
char** argument_vector)
{
int argument_index;
int do_input = 1;
program_name = argument_vector [0];
for (argument_index = 1; argument_index < argument_count; ++argument_index)
{
char* argument = argument_vector [argument_index];
if (argument [0] == '-')
{
fprintf (stderr, "\n%s: Unrecognized option: %s\n", program_name,
argument);
exit (1);
}
else
{
process_file (argument);
do_input = 0;
}
}
if (do_input) process_stream (stdin);
return 0;
}
void
process_file (const char* file)
{
FILE* stream;
if ((stream = fopen (file, "r")) == NULL)
{
fprintf (stderr, "\nCannot read %s\n", file);
exit (1);
}
process_stream (stream);
}
void
process_stream (FILE* stream)
{
while (! feof (stream))
{
int character = getc (stream);
if (character == EOF)
{
fclose (stream);
return;
}
fflush (stream);
delay ();
putc (character, stdout);
}
}
- - - - - - - - - - - - - - - - Cut here - - - - - - - - - - - - - - -
--
Rick Busdiecker <rf...@lehman.com> and <rf...@cmu.edu>
Lehman Brothers
388 Greenwich Street ``A great many people think they are thinking when
New York, NY 10013 they are merely rearranging their prejudices.''
(212) 464-4750 - William James
Well, on a Sun SPARC II, it didn't seem to slow things down
at all. But using usleep() was TOO slow. I found inserting
a dummy loop did just fine.
==============================================================
Tom R. Loden MIT Lincoln Lab Marry a job.
Lexington, MA 02173 Buy a wife and kids.
617-981-3249 Have a house together.
In <199...@ll.mit.edu>, lod...@ll.mit.edu (Tom R. Loden *8^0) writes: > Well, on a Sun SPARC II, it didn't seem to slow things down > at all. But using usleep() was TOO slow. I found inserting > a dummy loop did just fine. ( it did slow it down on mine... but on other points:...) problem with dummy loops is they're much less processor efficient. also, you CAN change the argument to usleep()... the argument is in microseconds (and will be some arbitrary amount more than what you specify, depending on system load, overhead for the call, etc.). (what i did was to add something like this in the code:... /* delay between charachters, in microseconds */ #define DELAY 1000 ...and change the "1000" argument to usleep() to "DELAY") unfortunately, on the system i'm currently on, i don't have usleep, or it's in a library other than what i'm compiling with, or something, but there are a few other things that i would suggest to make the program more efficient (which you'll then slow back down, to make it be just as you want it) first, you might want to get rid of the fflush(), and optionally replace it with a call to put you in cbreak mode. (not sure off hand how to do this on most platforms when you're not acting on stdin as your stream... though i suppose you could close stdin and re-open it as the other file, and then just call cbreak() ;-) also, change your primary loop do something more like this: while ( (c=getc(stream))!=EOF ) { delay (); putc (c, stdout); } fclose (stream); (the old version, which i'd have to post this to go back to, at the moment, was SOMETHING like: while( feof(stream) != EOF ) { int c=getc(stream); if(c==EOF) { fclose(stream); return; } fflush(stream); putc(c,stdout); } ... much more overhead, more calls, etc., slowing the program down tremendously.) there may be other things you can do too, but i'm not thinking of much more, at the moment... cheers. david lindes lin...@asd.sgi.com P.S. PLEASE NOTE: the intent of this message is not to cut down anyone's code!!! the intent is to provide some suggestions that may help more people have a more versitile "scat" program. i hope it helps. P.P.S. #include <std_disclaimer.h>
lin...@training.asd.sgi.com (David Lindes) writes: >unfortunately, on the system i'm currently on, i don't have usleep, >or it's in a library other than what i'm compiling with, or >something, [...] If you're interested, you can roll your own usleep() using select(): #include <errno.h> #include <sys/types.h> #include <sys/time.h> void my_usleep(usec) int usec; { struct timeval timeout; timeout.tv_sec = usec / 1000000; timeout.tv_usec = usec % 1000000; while ((select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &timeout) < 0) && (errno == EINTR)); } Hope this helps. --Raja
Related ASCII art in the Gallery
Explore these categories from our collection of 11,000+ artworks:
Make your own ASCII art
Turn images, text or 3D into ASCII, or draw your own – right in your browser.
About this thread.
These messages were posted publicly to the newsgroup
alt.ascii-art.animation
in 1994 and are mirrored here unchanged as part of the Historic Archives – only email addresses are masked.
The artwork and text belong to their original authors: if you copy a piece, keep the artist's initials or signature intact and credit them where you can.
Are you one of the authors? Contact us to get your posts attributed, connected to your artist profile, or removed.
Report this message
Help us keep the archive clean and accurate. Reports are reviewed by a person – nothing is changed automatically.