CYCLIC.C
Path: unixg.ubc.ca!news.mic.ucla.edu!library.ucla.edu!europa.eng.gtefsd.com!newsxfer.itd.umich.edu!gatech!nntp.msstate.edu!paladin.american.edu!auvm!NS.PA!rperez
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
Newsgroups: bit.listserv.frac-l
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
content-length: 4440
Message-ID: 
Date: Sun, 23 Oct 1994 23:17:56 -0500
Sender: "\"FRACTAL\" discussion list" 
From: Ramiro Perez 
Subject: cyclic.c
Lines: 244
 
// Cyclic Spaces
// by Ramiro Perez (rperez@ns.pa)
//
// This Automata begins with a random configuration in the screen
// and then after a few (approx. 20) iterations, spiral patterns
// take form.
//
// This cellular automata requires two video pages, so don't run
// it in video modes that not support (640x350x16) page flipping.
 
 
 
#include 
#include 
#include 
#include 
 
void hex1();
void hex2();
void rombus();
void maze1();
void maze2();
int i1,j1,sw,i,j;
int k,k1;
int sw1,sw2,t,a,b;
 
void main()
{
int op;
int gr,gm;
int pal[15] = {0,45,5,33,1,9,11,19,26,22,54,38,36,32,4};
 
randomize();
gr=EGA;
gm=EGAHI;
do {
clrscr();
printf("Cyclic Cellular Spaces\n");
printf("By Ramiro Perez (rperez@ns.pa)\n");
printf("\nSelect one:\n");
printf("1-> Hexagonal Space 1\n");
printf("2-> Hexagonal Space 2\n");
printf("3-> Romboidal Space\n");
printf("4-> Maze Space 1\n");
printf("5-> Maze Space 2\n");
printf("Any other number quits the program\n");
printf("\n->");
scanf("%d",&op);
if (op>=1 && op<=5) {
initgraph(&gr,&gm,"C:\\tc\\BGI");
cleardevice();
for (i=0;i<=15;i++) setpalette(i,pal[i]);
for (i=0;i<=640;i=i+2) for (j=0;j<=350;j=j+2) {
setcolor(random(12)+1);
rectangle(i,j,i+1,j+1);
}
k1=1;
sw=0;
a=1;
b=0;
sw=0;
switch (op) {
case 1: hex1() ;break;
case 2: hex2() ;break;
case 3: rombus();break;
case 4: maze1();break;
case 5: maze2();break;
}
}
 
}
while (op>=1 && op<=5);
}
 
 
void hex1(){
do {
setvisualpage(b);
setactivepage(a);
cleardevice();
setactivepage(b);
for (i1=1; i1<=640; i1=i1+2)
{
if (sw==0) sw=1;
else
sw=0;
for (j=1; j<=350; j=j+2)
{
j1=j+sw;
k=getpixel(i1,j1);
k1=(k % 12)+1;
sw1=0;
if ((getpixel(i1,j1-2)==k1) || (getpixel(i1-2,j1-1)==k1) ||
 (getpixel(i1+2,j1-1)==k1)) sw1=1;
if ((getpixel(i1-2,j1+1)==k1) || (getpixel(i1+2,j1+1)==k1) ||
 (getpixel(i1,j1+2)==k1)) sw1=1;
if (sw1==1) k=k1;
sw1=0;
setactivepage(a);
setcolor(k);
rectangle(i1,j1,i1+1,j1+1);
setactivepage(b);
}
}
t=a;
a=b;
b=t;
}
while (!kbhit());
getch();
closegraph();
}
 
void hex2(){
do {
setvisualpage(b);
setactivepage(a);
cleardevice();
setactivepage(b);
for (i1=1; i1<=640; i1=i1+2)
{
sw=0;
for (j1=1; j1<=350; j1=j1+2)
{
if (sw==0) sw=1;
else
sw=0;
k=getpixel(i1,j1);
k1=(k % 12)+1;
sw1=0;
if ((getpixel(i1,j1-2)==k1) || (getpixel(i1,j1+2)==k1)) sw1=1;
if ((getpixel(i1-2,j1)==k1) || (getpixel(i1+2,j1)==k1)) sw1=1;
if (((getpixel(i1+2,j1+2)==k1) || (getpixel(i1-2,j1-2)==k1)) && sw==0) sw1=1;
if (((getpixel(i1-2,j1+2)==k1) || (getpixel(i1+2,j1-2)==k1)) && sw==1) sw1=1;
if (sw1==1) k=k1;
sw1=0;
setactivepage(a);
setcolor(k);
rectangle(i1,j1,i1+1,j1+1);
setactivepage(b);
}
}
t=a;
a=b;
b=t;
}
while (!kbhit());
getch();
closegraph();
}
 
void rombus(){
do {
setvisualpage(b);
setactivepage(a);
cleardevice();
setactivepage(b);
for (i1=1; i1<=640; i1=i1+2) for (j1=1; j1<=350; j1=j1+2)
{
k=getpixel(i1,j1);
k1=(k % 12)+1;
sw1=0;
if ((getpixel(i1,j1-2)==k1) || (getpixel(i1,j1+2)==k1)) sw1=1;
if ((getpixel(i1-2,j1)==k1) || (getpixel(i1+2,j1)==k1)) sw1=1;
if (sw1==1) k=k1;
sw1=0;
setactivepage(a);
setcolor(k);
rectangle(i1,j1,i1+1,j1+1);
setactivepage(b);
}
t=a;
a=b;
b=t;
}
while (!kbhit());
getch();
closegraph();
}
 
void maze1(){
do {
setvisualpage(b);
setactivepage(a);
cleardevice();
setactivepage(b);
sw=0;
for (i1=1; i1<=640; i1=i1+2) for (j1=1; j1<=350; j1=j1+2)
{
if (sw==0) sw=1;
else
sw=0;
k=getpixel(i1,j1);
k1=(k % 12)+1;
sw1=0;
if ((getpixel(i1,j1-2)==k1) || (getpixel(i1,j1+2)==k1)) sw1=1;
if ((getpixel(i1-2,j1)==k1) || (getpixel(i1+2,j1)==k1)) sw1=1;
if (((getpixel(i1+2,j1+2)==k1) || (getpixel(i1-2,j1-2)==k1)) && sw==0) sw1=1;
if (((getpixel(i1-2,j1+2)==k1) || (getpixel(i1+2,j1-2)==k1)) && sw==1) sw1=1;
if (sw1==1) k=k1;
sw1=0;
setactivepage(a);
setcolor(k);
rectangle(i1,j1,i1+1,j1+1);
setactivepage(b);
}
t=a;
a=b;
b=t;
}
while (!kbhit());
getch();
closegraph();
}
 
void maze2(){
do {
setvisualpage(b);
setactivepage(a);
cleardevice();
setactivepage(b);
for (i1=1; i1<=640; i1=i1+2) for (j1=1; j1<=350; j1=j1+2)
{
k=getpixel(i1,j1);
k1=(k % 12)+1;
sw1=0;
if ((getpixel(i1-2,j1)==k1) || (getpixel(i1+2,j1)==k1)) sw1=1;
if ((getpixel(i1,j1+2)==k1) || (getpixel(i1,j1-2)==k1)) sw1=1;
if ((getpixel(i1-2,j1+2)==k1) || (getpixel(i1+2,j1+2)==k1)) sw1=1;
if ((getpixel(i1-2,j1-2)==k1) || (getpixel(i1+2,j1-2)==k1)) sw1=1;
if (sw1==1) k=k1;
sw1=0;
setactivepage(a);
setcolor(k);
rectangle(i1,j1,i1+1,j1+1);
setactivepage(b);
}
t=a;
a=b;
b=t;
}
while (!kbhit());
getch();
closegraph();
}