File:Byl loop animation.gif
Page contents not supported in other languages.
Tools
Actions
General
In other projects
Appearance
Byl_loop_animation.gif (300 × 300 pixels, file size: 866 KB, MIME type: image/gif, looped, 250 frames, 25 s)
This is a file from the Wikimedia Commons. Information from its description page there is shown below. Commons is a freely licensed media file repository. You can help. |
Contents
Summary
DescriptionByl loop animation.gif |
English: Byl's loop: animation example |
Date | |
Source | Own work |
Author | Claudio Rocchini |
Some notes
I used GIMP for gif creation.
I used the Byl's original paper (Self-Reproduction in small cellular automata), but the table II seems to miss the rule: 31523 -> 1.
Source Code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <memory.h>
#include <algorithm>
/* (C)2017 Claudio Rocchini */
/* From:
John Byl (1989), "Self-Reproduction in Small Cellular Automata", Physica D, 34: 295–299,
doi:10.1016/0167-2789(89)90242-X
*/
struct by_rule2 { const char * i; const char o; };
const by_rule2 by_rule2s[]= {
{ "00003", '1' }, { "00012", '2' }, { "00013", '1' }, { "00015", '2' }, { "00025", '5' },
{ "00031", '5' }, { "00032", '3' }, { "00042", '2' }, { "0****", '0' },
{ "10000", '0' }, { "10001", '0' }, { "10003", '3' }, { "10004", '0' }, { "10033", '0' },
{ "10043", '1' }, { "10321", '3' }, { "11253", '1' }, { "12453", '3' }, { "1****", '4' },
{ "20000", '0' }, { "20015", '5' }, { "20022", '0' }, { "20202", '0' }, { "20215", '5' },
{ "20235", '3' }, { "20252", '5' }, { "2****", '2' },
{ "30001", '0' }, { "30003", '0' }, { "30011", '0' }, { "30012", '1' }, { "30121", '1' },
{ "30123", '1' }, { "31122", '1' }, { "31123", '1' }, { "31215", '1' }, { "31223", '1' },
{ "31233", '1' }, { "31235", '5' }, { "31432", '1' }, { "31452", '5' },
{ "31523", '1' }, /* Note: this rule is missing in the original paper (?) */
{ "3****", '3' },
{ "40003", '5' }, { "40043", '4' }, { "40212", '4' }, { "50222", '0' }, { "40232", '4' },
{ "40242", '4' }, { "40252", '0' }, { "40325", '5' }, { "4****", '3' },
{ "50022", '5' }, { "50032", '5' }, { "50212", '4' }, { "50322", '0' }, { "5****", '2' },
{ "*****", 'x' } /* Special end rule marker */
};
static const char byl_init2[4][4] = { /* Initial configuration */
{ '0','2','5','0' },
{ '2','3','4','2' },
{ '2','3','1','2' },
{ '0','2','2','0' },
};
void byl_loop() {
const int N = 50; /* Grid size */
char mat[N][N]; char ma2[N][N];
int i, j;
for (i = 0; i < N; ++i) for (j = 0; j < N; ++j) mat[i][j] = '0';
for (i = 0; i < 4; ++i) for (j = 0; j < 4; ++j) mat[i+(N-4)/2][j+ (N - 4) / 2] = byl_init2[i][j];
const int SS = 6; /* Magnify factor */
unsigned char * img = new unsigned char[SS*N*SS*N * 3];
const uint8_t colors[8][3] = { /* The palette */
{0,0,0}, {255,0,0}, {0,224,0}, {0,0,255},
{255,255,0}, {255,0,255}, {32,32,32}, {255,255,255}
};
for (int s = 0; s < 250; ++s) {
memset(img, 32, SS*N*SS*N * 3); /* Generate the image */
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
const unsigned char * c = colors[mat[N - 1 - i][j] - '0'];
for(int y=0; y<SS-1; ++y) for(int x=0; x<SS-1; ++x)
memcpy(img + 3*(x+j*SS+(SS*N)*(y+i*SS)), c, 3);
}
}
char name[256]; sprintf(name, "byl%03d.ppm", s);
FILE * f2 = fopen(name, "wb");
fprintf(f2, "P6\n%d %d\n255\n", N*SS, N*SS); fwrite(img, 1, SS*N*SS*N * 3, f2);
fclose(f2);
for (i = 0; i < N; ++i) for (j = 0; j < N; ++j) {
char se[5];
se[0] = mat[i][j];
se[1] = i == 0 ? '0' : mat[i-1][j];
se[2] = j == N - 1 ? '0' : mat[i][j + 1];
se[3] = i == N - 1 ? '0' : mat[i+1][j];
se[4] = j == 0 ? '0' : mat[i][j - 1];
const by_rule2 * k = 0;
for (k = by_rule2s; ; ++k) {
if (k->i[0] != '*' && k->i[0] != se[0]) continue; /* bad rule header */
char t[4]; /* The rule match also for circula shifs ... */
memcpy(t, k->i + 1, 4);
bool found = false;
for(int q=0; q<4; ++q) {
int l; for (l = 0; l < 4; ++l) if (t[l] != '*' && t[l] != se[l + 1]) break;
if (l == 4) { found = true; break; }
char t1 = t[0]; t[0] = t[1]; t[1] = t[2]; t[2] = t[3]; t[3] = t1;
}
if (found) break;
}
ma2[i][j] = k->o;
}
for (i = 0; i < N; ++i) for (j = 0; j < N; ++j) mat[i][j] = ma2[i][j]; /* Swith the matrix */
}
delete[] img;
}
int main() {
byl_loop();
return 0;
}
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Items portrayed in this file
depicts
some value
4 August 2017
image/gif
c2d415385a849db7583278adc75931f761b50619
886,877 byte
25.000000000000085 second
300 pixel
300 pixel
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 14:08, 4 August 2017 | 300 × 300 (866 KB) | Rocchini | User created page with UploadWizard |
File usage
The following 2 pages use this file:
Global file usage
The following other wikis use this file:
- Usage on fa.wikipedia.org
- Usage on id.wikipedia.org
Metadata
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
If the file has been modified from its original state, some details may not fully reflect the modified file.
GIF file comment | Created with GIMP |
---|
Retrieved from "https://en.wikipedia.org/wiki/File:Byl_loop_animation.gif"