How to slow down animation

Message thread · created 1993-11-10 · last edited 2026-11-23 · Item Language: English
Topics: ASCII art
Source: asciiart.eu
Newsgroup: alt.ascii-art

November 1993, alt.ascii-art: a reader asks how to slow down the animations, because with ‘cat’ they go too fast to see. Within three hours two readers post their own slowcat.c: Achille Hui (Stanford), ‘slowcat 1000 < your_anim_file’, at most 1000 characters per second; and Dave Hines (Daresbury Lab), ‘slowcat [-r rate]’, tested on a SunOS SPARCstation. Both take the rate in characters per second and wait with the system clock (select, gettimeofday), not with a counting loop. The earliest known players, three months before alt.ascii-art.animation, and the earliest use of the name slowcat that we have found.

Quoted in the article:

  • c4-lam-cat-fast: Bernard Lam, 1993-11-10 (post)
  • c4-hui-slowcat: Achille Hui, the Day Dreamer, 1993-11-10 (post)
  • c4-hines-slowcat: Dave Hines, 1993-11-10 (post)
  • c4-hines-same-problem: Dave Hines, 1993-11-10 (post)

alt.ascii-art · 3 posts · 1993-11-10 11:23:40 UTC – 1993-11-10 14:07:14 UTC

Bernard Lam <blb...@cantor.math.uwaterloo.ca> ·
asciiart.eu · c4-lam-cat-fast · ↑ tree
	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

Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f996b,ac750d31c700498f,start
X-Google-Attributes: gidf996b,public
X-Google-ArrivalTime: 1993-11-10 03:44:39 PST
Newsgroups: alt.ascii-art
Path: gmd.de!xlink.net!howland.reston.ans.net!spool.mu.edu!torn!watserv2.uwaterloo.ca!undergrad.math.uwaterloo.ca!cantor.math.uwaterloo.ca!blblam
From: blb...@cantor.math.uwaterloo.ca (Bernard Lam)
Subject: How to slow down animation
Message-ID: <CG9...@undergrad.math.uwaterloo.ca>
Sender: new...@undergrad.math.uwaterloo.ca
Organization: University of Waterloo
Date: Wed, 10 Nov 1993 11:23:40 GMT
Lines: 12

↑ tree

Achille Hui, the Day Dreamer <eil...@drizzle.StanFord.EDU> ·
↳ Bernard Lam ~ · asciiart.eu · c4-hui-slowcat · ↑ tree
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
                                               "

Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f996b,ac750d31c700498f
X-Google-Attributes: gidf996b,public
X-Google-ArrivalTime: 1993-11-10 04:31:01 PST
Newsgroups: alt.ascii-art
Path: gmd.de!xlink.net!howland.reston.ans.net!agate!headwall.Stanford.EDU!nntp.Stanford.EDU!eil...@drizzle.Stanford.EDU
From: eil...@drizzle.StanFord.EDU ( Achille Hui, the Day Dreamer )
Subject: Re: How to slow down animation
Message-ID: <eil...@drizzle.Stanford.EDU>
Sender: new...@leland.Stanford.EDU (Mr News)
X-Transfer-Agent: nntp.stanford.edu (NNTP)
Organization: Dept. of Physics, Stanford University.
Date: 10 Nov 93 12:03:31 GMT
Lines: 117

↑ tree

Dave Hines <v...@gserv1.dl.ac.uk> ·
↳ Bernard Lam · asciiart.eu · c4-hines-slowcat · c4-hines-same-problem · ↑ tree
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

Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f996b,ac750d31c700498f
X-Google-Attributes: gidf996b,public
X-Google-ArrivalTime: 1993-11-10 06:16:09 PST
Path: gmd.de!xlink.net!howland.reston.ans.net!agate!doc.ic.ac.uk!daresbury!vj
From: v...@gserv1.dl.ac.uk (Dave Hines)
Newsgroups: alt.ascii-art
Subject: slowcat.c: How to slow down animation
Date: 10 Nov 1993 14:07:14 GMT
Organization: SERC Daresbury Laboratory, Warrington, UK
Lines: 139
Message-ID: <VJ....@dlsi.dl.ac.uk>
References: <CG9...@undergrad.math.uwaterloo.ca>
Reply-To: D.H...@daresbury.ac.uk
NNTP-Posting-Host: dlsi.dl.ac.uk
In-reply-to: blb...@cantor.math.uwaterloo.ca's message of Wed, 10 Nov 1993 11:23:40 GMT

↑ tree

Source: asciiart.eu

The messages, and the works they contain, belong to their authors and are published here as an archive. If you are one of them and want a correction or a removal, write to me.

Available documentssizedownload
t248d40df06.json (json)mail-usenet-thread 0.6archived copy, not distributed36K–

Browse the Archive →