Berkas:Byl loop animation.gif

Byl_loop_animation.gif(300 × 300 piksel, ukuran berkas: 866 KB, tipe MIME: image/gif, melingkar, 250 frame, 25 d)

Berkas ini berasal dari Wikimedia Commons dan mungkin digunakan oleh proyek-proyek lain. Deskripsi dari halaman deskripsinya ditunjukkan di bawah ini.

Ringkasan

Deskripsi
English: Byl's loop: animation example
Tanggal
Sumber Karya sendiri
Pembuat 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;
}

Lisensi

Saya, pemilik hak cipta dari karya ini, dengan ini menerbitkan berkas ini di bawah ketentuan berikut:
w:id:Creative Commons
atribusi berbagi serupa
Berkas ini dilisensikan di bawah lisensi Creative Commons Atribusi-Berbagi Serupa 4.0 Internasional.
Anda diizinkan:
  • untuk berbagi – untuk menyalin, mendistribusikan dan memindahkan karya ini
  • untuk menggubah – untuk mengadaptasi karya ini
Berdasarkan ketentuan berikut:
  • atribusi – Anda harus mencantumkan atribusi yang sesuai, memberikan pranala ke lisensi, dan memberi tahu bila ada perubahan. Anda dapat melakukannya melalui cara yang Anda inginkan, namun tidak menyatakan bahwa pemberi lisensi mendukung Anda atau penggunaan Anda.
  • berbagi serupa – Apabila Anda menggubah, mengubah, atau membuat turunan dari materi ini, Anda harus menyebarluaskan kontribusi Anda di bawah lisensi yang sama seperti lisensi pada materi asli.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

menggambarkan

4 Agustus 2017

image/gif

checksum Inggris

c2d415385a849db7583278adc75931f761b50619

886.877 Bita

25,000000000000085 detik

300 piksel

300 piksel

Riwayat berkas

Klik pada tanggal/waktu untuk melihat berkas ini pada saat tersebut.

Tanggal/WaktuMiniaturDimensiPenggunaKomentar
terkini4 Agustus 2017 14.08Miniatur versi sejak 4 Agustus 2017 14.08300 × 300 (866 KB)RocchiniUser created page with UploadWizard

Halaman berikut menggunakan berkas ini:

Penggunaan berkas global

Wiki lain berikut menggunakan berkas ini:

Metadata