Settings

The page will reload to apply your changes.
Theme

ASCII Art Font

ASCII Art Menu

Original Usenet thread from alt.ascii-art, started 10 Nov 1993.
 _   _                     _        _             _     _           
| | | |___  ___ _ __   ___| |_     / \   _ __ ___| |__ (_)_   _____ 
| | | / __|/ _ \ '_ \ / _ \ __|   / _ \ | '__/ __| '_ \| \ \ / / _ \
| |_| \__ \  __/ | | |  __/ |_   / ___ \| | | (__| | | | |\ V /  __/
 \___/|___/\___|_| |_|\___|\__| /_/   \_\_|  \___|_| |_|_| \_/ \___|
How to slow down animation

How to slow down animation

alt.ascii-art · 3 messages · 10 Nov 1993 - 10 Nov 1993
	I'm just wondering how to slow down the animated files.  When I view
the files using the 'cat' command in UNIX, it goes so fast that I can't see it.




Bernard Lam
blb...@undergrad.math.uwaterloo.ca

blb...@cantor.math.uwaterloo.ca (Bernard Lam) writes: 

>
>	I'm just wondering how to slow down the animated files.  When I view
>the files using the 'cat' command in UNIX, it goes so fast that I can't s...
>
Following is a simple C-program I used to slow the display down, it is pretty
BSDism and I hope it will work for you. Let's say you compile this program
into an executable called slowcat, then you can try

	slowcat 1000 < your_anim_file

This will try to display at most 1000 characters per second. Notice this
program will try to perform some buffering to minimize its load. If you
are desperate for single char I/O, you may also try the dd command,

	dd if=your_anim_file bs=1

----slowcat.c-------------------------------------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
void
nap(unsigned int ms){
    if(ms > 0){
	struct timeval tm;
	tm.tv_sec  = ms/1000000;
	tm.tv_usec = ms%1000000;
	select(0,0,0,0,&tm);
    }
}
int
main(int argc,char *argv[]){
    char buf[1024], *p, *q, *r;
    int  len, delay = 500;
    argc--; argv++;
    if(argc-- > 0)
	if((len = atoi(*argv++))>0)
	    delay = 1000000/len;
    for(len=1024; (len==1024) && ((len = fread(buf,1,1024,stdin)) > 0);)
	for(p = buf, q = p + len, r = p; p != q; p = r){
	    for(r++;r != q;r++)
		if((*r == '\n') || (*r == '\r') || ((r - p) > 128))
		    break;
	    fwrite(p,r-p,1,stderr);
	    nap(delay * (r-p));
	}
}
-------------------------------------achille (eil...@drizzle.stanford.edu)
ObAscii:    
    
    
    "
     "o         ooo$oo
       "$$    o$$$$$$$$o
          "$$$$$$$"   $$o
           o$$$$$$o$oo$$$
           $$$$"  ""$$$$$ooooo
          o$$$      o$$$""$"$$$$o$ooo
         o$$$"    o$$$$"       " "$$$$$$$$o$
         o$$$   oo$$$$"         oooo$$$$$$$$$o
         $$$   o$$$$$   oooo$$$$$$$$$$$$""""
          $$"o$$$$$$$$$$$$$$$$$$""""
          $$$$$$$$$$$$$$$"""
           $$$$$$""""
           $$"
            $$    oo
             "o $$$$$$$$oo
              $$$$$"""""""$ o
              $$$""         $o
              $$$           "$o
              "$"          o$$$
               $$         "$$$$
               "$"          """
                  $ o
                   " $$oooo oooo$ooo$$$$o$$$$$$$$ooo
                 ooo$$$$$$$$$$$$$$$$$$$$"$$$""$$""$"o
                  $$$$$$$$$$$$"$"$$$$ooo            $$o
                    "  "" """$$ooo """"$$$$$o$$oo$$$$$$o
                                ""o      """""$$"$$$$""
                                 "$$
                                  $$
                       ooo$ooo$$$$$$$
                     $$$$$$$$$$$$$"""
                     "$$"" "
                      $$
                        $oo o
                          "$$$ooo
                        o$$$$$$$$$$$$$oo     $$$o
                        $$$$""""$""$"$$$      $$$o
                        o$$                     ""
                          "o
                            $ooo                o   o   o
                              "$$$ooooooo$ooo$$$$$$$$$$$$$$oo
                             oooo$$$$$$$$$$$$$$$$"""$""""""""$o
                            $$$$$$$$$"""""$"$$$oooo         oo$oo
                            $$$"" "         " """$$$$$$$$$$$$$$$$
                            "$"                     " """$""$"""
                              $
                               "$$$ooo o  ooo oooo$o$o$$o$o$$ooo
                                  "$$$$$$$$$$$$$$$$$$$"$$$"$$$"$$ o
                               o$$$$$$$$$$$"$$$$$$"o             $oo
                               $$$$""""        """$"$$$$$o$ooo$$$$$$
                                $$                   """""$$$$$$$$""
                                ""o
                                   $$oo ooo o
                                    o$$$$$$$$$ooo
                                   o$$$$$""" """oo
                                   $$$$"        o$$
                                  "$$$ ""$oo ooo$$$
                                   "$o    ""$$$$$$$"
                                    $$        " "
                                     o"
                                       "$o$o
                                          "$$$oo
                                               "

In article <CG9...@undergrad.math.uwaterloo.ca> Bernard Lam wrote:

>   I'm just wondering how to slow down the animated files.  When I view the
> files using the 'cat' command in UNIX, it goes so fast that I can't see it.

Since this group started I had the same problem. Here is a little filter
I knocked together to solve the problem, and lets you specify the output
rate. I've only tested it on a Sun sparcstation, under SunOS 4.1.3. It's
not pretty, but it works here!

Happy viewing !
		Dave.

-------------------------------- Cut here --------------------------------
/* slowcat.c */
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>

/*
 * Cat files, but delay the characters. Useful for ASCII animations
 * when the line (eg xterm) is too fast. The output rate is in units
 * of characters per second, and defaults to 1000.
 *
 * Usage: slowcat [-r rate] [file...]
 */

extern int getopt();			/* Decodes option args. */
extern char *optarg;			/* Required by getopt() */
extern int optind, opterr;		/* Required by getopt() */

long interval;				/* To wait between characters */

#define DEFAULT_RATE	1000		/* Characters per second */
#define M		1000000L	/* us (tv_usec units) per second */

main(int argc, char **argv)
{
    int rate = DEFAULT_RATE;
    register int c;

    while ((c = getopt(argc, argv, "r:")) != -1)
    {
	switch (c)
	{
	case 'r':			/* Rate, chars per second */
	    if ((rate = atoi(optarg)) < 10)
		rate = 10;
	    break;

	case '?':
	default:
	    fputs("Usage: slowcat [-r rate] [file...]\n", stderr);
	    exit(1);
	}
    }

    interval = M / rate;

    if (optind < argc)
    {
	for ( ; optind < argc;  ++optind)
	{
	    FILE *fp;

	    if (fp = fopen(argv[optind], "r"))
	    {
		scat(fp);
		fclose(fp);
	    }
	    else
		perror(argv[optind]);
	}
    }
    else
	scat(stdin);
}

scat(FILE *fp)
{
    long uwait;			/* Wait time in microseconds */
    struct timeval time;	/* long tv_sec, tv_usec; Secs & microsecs */
    struct timeval next_due;
    register char c = getc(fp);	/* Do first getc before gettimeofday so	a */
				/*  delayed first read doesn't matter.	  */
				/* Delayed data can come from pipes like: */
				/*	zcat animation.Z | slowcat	  */

    if (gettimeofday(&next_due, NULL))	/* Keep next char due time here */
    {
	perror("gettimeofday() failed");
	exit(1);
    }

    time.tv_sec = 0;		/* Initialise to force gettimeofday */

    while (c != EOF)
    {
	if ((time.tv_sec < next_due.tv_sec) || /* Don't bother to get */
	    ((time.tv_sec == next_due.tv_sec) && /* time & wait when */
	     (time.tv_usec < next_due.tv_usec))) /* output is due */
	{
	    if (gettimeofday(&time, NULL)) /* Current time */
	    {
		perror("gettimeofday() failed");
		exit(1);
	    }
	    /*
	     * Calculate the number of microseconds to wait until the next
	     * character is due. This can be negative if the char is late.
	     */
	    if ((uwait = (next_due.tv_sec - time.tv_sec) * M +
		 next_due.tv_usec - time.tv_usec) > 0)
	    {
		fflush(stdout);		/* We have to wait anyway... */
		time.tv_sec = 0;
		time.tv_usec = uwait;
		
		if (select(0, NULL, NULL, NULL, &time) < 0)
		{
		    perror("select failed");
		    exit(1);
		}
	    }
	}

	putchar(c);
	if ((next_due.tv_usec += interval) >= M)
	{
	    next_due.tv_usec -= M;
	    ++next_due.tv_sec;
	}
	c = getc(fp);
    }
}
--
Snail:	David Hines,  Daresbury Lab,	UUCP:	D.Hines@daresbury
	Warrington,  WA4 4AD,  U.K.	JANET:	D.H...@uk.ac.daresbury
	('phone:  +44 925 603357)	Other:	D.H...@daresbury.ac.uk

About this thread. These messages were posted publicly to the newsgroup alt.ascii-art in 1993 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.

Help classify this post