Path: unixg.ubc.ca!vanbc.wimsey.com!cyber2.cyberstore.ca!math.ohio-state.edu!darwin.sura.net!nntp.msstate.edu!olivea!sgigate.sgi.com!sgiblab!swrinde!elroy.jpl.nasa.gov!usc!howland.reston.ans.net!paladin.american.edu!auvm!C53000.PETROBRAS.ANRJ.BR!BJ06 Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU Newsgroups: bit.listserv.frac-l Return-Path: <@AUVM.AMERICAN.EDU,@VTBIT.CC.VT.EDU:FRAC-L@GITVM1.BITNET> X-Envelope-to: FRAC-L@GITVM1.BITNET X-VMS-To: @FRACTAL References: ANSP network HEPnet SPAN Bitnet Internet gateway Message-ID: <20C0F76120000770@fpsp.fapesp.br> Date: Mon, 24 Jan 1994 09:06:00 BDB Sender: "\"FRACTAL\" discussion list" Comments: @FPSP.FAPESP.BR - @FPSP.HEPNET - @BRFAPESP.BITNET - .BR gateway From: BJ06@C53000.PETROBRAS.ANRJ.BR Subject: NEWAUTO.CPP (C++ 3.1 source code with ASCII characters) Lines: 340 Rio de Janeiro, Mon. 01/24/94 FRAC-Lers: This is a new version of the Cellular Automats. Contains ASCII characters which may not be displayed at your terminals (prefer the UUENCODEd version posted earlier). Regards, Fausto. Fausto A. A. Barbuto, BJ06@C53000.PETROBRAS.ANRJ.BR Rio de Janeiro, RJ, Federal Republic of Brazil FAX (55)(21)5986796 /5986441 - Phone (55)(21)5986706 -----"Friends come and go; enemies accumulate"----- ---Program NEWAUTO.CPP---Begin---CUT HERE--------------- // //+-----------------------------------------------------------+ //+ Program Cellular_Automata v. 1.3 (Pyramidal style) + //+ By Ramiro Perez {RPEREZ@UTPVM1.BITNET}, (Panama) + //+ and Fausto A. A. Barbuto {BJ06@C53000.PETROBRAS.ANRJ.BR}, + //+ (Brazil). + //+ C++ 3.1 programme's creator: Fausto A. A. Barbuto, 1994. + //+ After a TURBO BASIC program by Ramiro Perez, 1994 + //+ OBS: Contains ASCII characters. + //+-----------------------------------------------------------+ // #include #include #include #include #include void Create_Cellular(int, int, int [53][53]); int Rulegenerator(int,int,int,int,int,int[13]); void main() { int i, j, k, u, t, a[53][53], b[53][53], c[53][53], poly[18]; int ipal[15] = {45,5,33,1,9,11,19,26,22,54,38,36,32,4,8}; int nx, ny, a1, b1, irand1, irand2, option, n, w, s, cc, e; int wires[13] = {0,2,3,4,5,6,7,8,9,10,11,12,0}; float c_1 = 1.154700538, r; float p1 = 0.587785252, p2 = 0.809016994, p3 = 0.363271264; float p4 = 1.118033989; int graphdriver=DETECT, graphmode; clrscr(); printf("\n ÅÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎΈ"); printf("\n × Cellular Automata of four sides ×"); printf("\n × By Ramiro Perez & Fausto Barbuto, 1994 ×"); printf("\n × States = 12 ×"); printf("\n × Select a initial pattern: ×"); printf("\n × ×"); printf("\n × 1 - CIRCLE 2 - SQUARE ×"); printf("\n × 3 - TRIANGLE 4 - HEXAGON ×"); printf("\n × 5 - PENTAGON 6 - ELLIPSE ×"); printf("\n × 7 - RECTANGLE 8 - STAR ×"); printf("\n × <1 or >8 - CIRCLE (default) ×"); printf("\n ¯––––––––––––––––––––––––––––––––––––––––Þ"); printf("\n ×(Press any key & wait to stop execution)×"); printf("\n ®ÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎΔ"); printf("\n\n Option = ? "); scanf("%d",&option); clrscr(); t = 210; u = 70; initgraph(&graphdriver, &graphmode, "c:\\borlandc\\bgi"); cleardevice(); // // Initialization of vectors a[][], b[][], c[][]. // Inicializa o dos vetores a[][], b[][], c[][]. // for (i=0;i<=52;i++) { for (j=0;j<=52;j++) { a[i][j] = 0; b[i][j] = 0; c[i][j] = 0; } } for (i=0;i<=14;i++) { setpalette(i,ipal[i]); } setbkcolor(3); k = 0; // // The initial pattern is defined here // O padr o inicial definido aqui. // switch(option) { case 1: /* Circle, Cárculo */ for (i=12;i>=1;i--) { k++; setcolor(k); circle(26,26,i); setfillstyle(SOLID_FILL,k); floodfill(26,26,k); } break; case 2: /* Square, Quadrado */ for (i=12;i>=1;i--) { k++; setcolor(k); rectangle (26-i, 26+i, 26+i, 26-i); } break; case 3: /* Triangle, Tri ngulo */ for (i=12;i>=1;i--) { k++; setcolor(k); poly[0] = 26-i; poly[1] = poly[0]; poly[2] = 26+i; poly[3] = poly[0]; poly[4] = 26; poly[5] = poly[2]; poly[6] = poly[0]; poly[7] = poly[1]; drawpoly(4,poly); setfillstyle(SOLID_FILL,k); } break; case 4: /* Hexagon, Hex¦gono */ for (i=12;i>=1;i--) { k++; setcolor(k); r = c_1*i; poly[0] = 26; poly[1] = poly[0] - r; poly[2] = poly[0] + i; poly[3] = poly[0] - 0.5*r; poly[4] = poly[0] + i; poly[5] = poly[0] + 0.5*r; poly[6] = poly[0]; poly[7] = poly[0] + r; poly[8] = poly[0] - i; poly[9] = poly[5]; poly[10] = poly[8]; poly[11] = poly[3]; poly[12] = poly[0]; poly[13] = poly[1]; drawpoly(7,poly); setfillstyle(SOLID_FILL,k); } break; case 5: /* Pentagon, Pent¦gono */ for (i=12;i>=1;i--) { k++; setcolor(k); poly[0] = 26 - p1*i; poly[1] = 26 - p2*i; poly[2] = 26 + p1*i; poly[3] = poly[1]; poly[4] = 26 + (p1 + p3)*i; poly[5] = 26 + (p4 - p2)*i; poly[6] = 26; poly[7] = poly[6] + i; poly[8] = poly[0] - p3*i; poly[9] = poly[5]; poly[10] = poly[0]; poly[11] = poly[1]; drawpoly(6,poly); setfillstyle(SOLID_FILL,k); } break; case 6: /* Ellipse, Elipse */ for (i=12;i>=1;i--) { k++; setcolor(k); fillellipse(26,26,i,0.5*i); setfillstyle(SOLID_FILL,k); } break; case 7: /* Rectangle, Ret ngulo */ for (i=12;i>=1;i--) { k++; setcolor(k); rectangle (26-1.4*i, 26+i, 26+1.4*i, 26-i); } break; case 8: /* 4-points Star, Estrela de quatro pontas */ for (i=12;i>=1;i--) { k++; setcolor(k); poly[0] = 26; poly[1] = poly[0] - i; poly[2] = poly[0] + 0.25*i; poly[3] = poly[0] - 0.25*i; poly[4] = poly[0] + i; poly[5] = poly[0]; poly[6] = poly[2]; poly[7] = poly[6]; poly[8] = poly[0]; poly[9] = poly[4]; poly[10] = poly[3]; poly[11] = poly[2]; poly[12] = poly[0] - i; poly[13] = poly[0]; poly[14] = poly[3]; poly[15] = poly[14]; poly[16] = poly[0]; poly[17] = poly[1]; drawpoly(9,poly); setfillstyle(SOLID_FILL,k); } break; default: /* Circle , Circulo */ for (i=12;i>=1;i--) { k++; setcolor(k); circle(26,26,i); setfillstyle(SOLID_FILL,k); floodfill(26,26,k); } break; } for (nx=0;nx<=52;nx++) { for (ny=0;ny<=52;ny++) { k = getpixel(nx,ny); a[nx][ny] = k; c[nx][ny] = k; } } Create_Cellular(t,u,c); // 1st call of Create_Cellular // 1â chamada da Create_Cellular do { irand1 = (int)(rand()/32767.0); irand2 = (int)(rand()/32767.0); a[irand1+1][irand2+1] = 1; for (i=1;i<=51;i++) { for (j=1;j<=51;j++) { e = a[i-1][j]; w = a[i+1][j]; n = a[i][j-1]; s = a[i][j+1]; cc = a[i][j]; b[i][j] = Rulegenerator(n,s,e,w,cc,wires); c[i][j] = b[i][j]; } } Create_Cellular(t,u,c); // 2nd call of Create_Cellular // 2â chamada da Create_Cellular for (i=1;i<=51;i++) { for (j=1;j<=51;j++) { e = b[i-1][j]; w = b[i+1][j]; n = b[i][j-1]; s = b[i][j+1]; cc = b[i][j]; a[i][j] = Rulegenerator(n,s,e,w,cc,wires); c[i][j] = a[i][j]; } } Create_Cellular(t,u,c); // 3rd call of Create_Cellular // 3â chamada da Create_Cellular } while (!kbhit()); // // Sound effects and clean-up. // Efeitos sonoros e limpeza da tela. // sound(740); delay(600); sound(370); delay(300); nosound(); closegraph(); } void Create_Cellular(int t, int u, int c[53][53]) { int i, k, nx, nx1, nx2, ny, ny1, ny2, cx, cy, kcolorx, kcolory; setcolor(4); for (nx=0;nx<=51;nx++) { for (ny=0;ny<=51;ny++) { k = c[nx][ny]; nx1 = 4*nx; ny1 = 4*ny; if (k !=0) { for (i=1;i<=k;i++) { nx2 = nx1 - i + t; ny2 = ny1 - i + u; setcolor(14); line (nx2, ny2+3, nx2+3, ny2+3); setcolor(13); line (nx2+3, ny2, nx2+3, ny2+3); } setcolor(k); cx = nx1-k+t+1; cy = ny1-k+u+1; rectangle (nx1-k+t, ny1-k+u, nx1+3-k+t, ny1+3-k+u); kcolorx = getpixel(nx1-k+t,ny1-k+u); setfillstyle(SOLID_FILL,k); floodfill(cx,cy,kcolorx); } else { setcolor(1); cx = nx1+t+1; cy = ny1+u+1; rectangle (nx1+t, ny1+u, nx1+3+t, ny1+3+u); kcolorx = getpixel(nx1-k+t,ny1-k+u); setfillstyle(SOLID_FILL,1); floodfill(cx,cy,kcolorx); } } } return; } int Rulegenerator(int n, int s, int e, int w, int cc, int wires[13]) { int ca[13], rule; ca[n] = ca[n] + 1; ca[s] = ca[s] + 1; ca[w] = ca[w] + 1; ca[e] = ca[e] + 1; ca[n] = ca[n] + 1; rule = wires[cc]; if (cc == 0) { if (ca[1] > 0) rule = 1; } return rule; } ---Program NEWAUTO.CPP---End---CUT HERE---------------