Wolfram Rnd 1D cellular automata - 640x480 vga - with random rules

Dependencies:   fastlib mbed vga640x480g

Revision:
0:ba3520f6dbce
diff -r 000000000000 -r ba3520f6dbce main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 04 13:07:21 2012 +0000
@@ -0,0 +1,66 @@
+#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);
+        }
+      }
+}
\ No newline at end of file