TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Jay Collins
from: Vitus Jensen
date: 1994-12-22 00:29:20
subject: 2dlife.c

Moin Jay,

08.12.94 19:51, you wrote a message to All:

 JC> /*
 JC> ** A quick "life" (2-d cellular automaton) implementation done in 
 JC> Turbo C 2.0 ** on the spur-of-the-moment by Jonathan Guthrie 
 JC> 9/20/1992 and donated to the ** public domain.
 JC> **----------------------------------------------------------
 JC> -------------- ** these are the orginal comments. I ported it 
 JC> to OS/2 using Watcom C++ ** 9.5. I changed it to use the VIO 
 JC> stuff (since that's about all I know..) ** OS/2 port by Jay 
 JC> Collins of FIDO: 1:275/158
 JC> */



 JC> #define     ROWS        23
 JC> #define     COLS        80
 JC> #define     GENERATIONS 10

 JC> int civ1[ROWS][COLS], civ2[ROWS][COLS];

 JC> void initialize(void)
 JC> {
 JC>       int i, j;

 JC>       randomize();
 JC>       for (i = 0; i < ROWS; ++i)
 JC>       {
 JC>             for (j = 0; j < COLS; ++j)
 JC>             {
 JC>                   civ1[i][j] = random(2);
 JC>                   VioSetCurPos(i+1, j+1,0);
 JC>                   putch(civ1[i][j] ? '*' : ' ');
 JC>             }
 JC>       }
 JC> }

Don't display every single character using two API/Library calls! Much
faster if using something like this:

void DisplayGeneration(int cell[ROWS][COLS])
{
    int i, j;
    char  line[COLS];

    for( i=0; i < ROWS; ++i )
        {
        for( j=0; j < COLS; ++j )
            line[j] = (cell[i][j] ? '*' : ' ');

        VioWrtCharStr( line, COLS, i+1, 1, 0 );
        }
    return;
}



Bye,
	Vitus

--- Sqed/32 0.97/r00228
* Origin: Really a Point of BetaBox, Walheim (2:2474/100.20)
SEEN-BY: 12/2442 620/243 624/50 632/348 640/820 690/660 711/409 410 413 430
SEEN-BY: 711/807 808 809 934 942 949 712/353 515 713/888 800/1
@PATH: 2474/100 0 2476/2 2480/76 24/24 396/1 3615/50 229/2 12/2442 711/409
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.