Wolfram Rnd 1D cellular automata - 640x480 vga - with random rules
Dependencies: fastlib mbed vga640x480g
main.cpp
- Committer:
- JLS
- Date:
- 2012-03-04
- Revision:
- 0:ba3520f6dbce
File content as of revision 0:ba3520f6dbce:
#include "mbed.h" #include "vga640x480g.h" void DisplayState(int s[],int len, int row); int main() { init_vga(); vga_cls(); while(1) { int iteration = 479; int lenght = 639; int row = 0; int state[lenght]; int newstate[lenght]; int i,j,k; int rules[8] = {rand()%2,rand()%2,rand()%2,rand()%2,rand()%2,rand()%2,rand()%2,rand()%2}; wait (0.5); vga_cls(); for (i=0;i<lenght;i++) state[i]= int (rand()%2); for (i=0;i<iteration;i++) { for (j=0;j<lenght;j++) newstate[j] = 0; for (j=0;j<lenght;j++) { k = 4*state[(j-1+lenght)%lenght] + 2*state[j] + state[(j+1)%lenght]; newstate[j] = rules[k]; } for (j=0;j<lenght;j++) state[j] = newstate[j]; DisplayState(state,lenght,row); row = row + 1; if (row == 480) row = 0; } } } void DisplayState(int s[],int len, int row) { int i; for (i=0;i<len;i++) { if (s[i] == 1){ vga_plot(i,row,WHITE); } else{ vga_plot(i,row,BLACK); } } }