We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Cellular Automata: Wireworld
Page Index Toggle Pages: 1
Cellular Automata: Wireworld (Read 620 times)
Cellular Automata: Wireworld
Oct 14th, 2008, 8:04am
 
I hadn't seen anything on discourse about this so here is my take on Wireworld.

As the title says, Wireworld is a type of cellular automata. It resembles and can simulate some electronic (digital) circuits.

A little reference
http://en.wikipedia.org/wiki/Wireworld

A working applet can be found at
http://budgethighvoltage.googlepages.com/wireworld.html

Also, for anyone interested; the code. All you need to make your own is to save a bitmap with your four favorite colors for space, wire, electron head, and electron tail.
Quote:



//Wireworld
//My preferred colors
int SPACE=0, EH=color(0,255,255), ET=color(0,0,255), WIRE=color(255,255,0);

//Open Paint (or other graphics program) and draw in the colors you like
//int SPACE=color(255,255,255), EH=color(255,0,0), ET=color(0,255,0), WIRE=color(0);
//int SPACE=color(255,255,255), EH=color(0,255,0), ET=color(255,0,0), WIRE=color(0);


int w=512, h=512;

int addtype=0;

int[] imgout = new int[w*h];
int[] whatitwas = new int[w*h];

//boolean running=true;

PImage org = new PImage(w,h);

void setup() {
 size(w,h);
 
 org = loadImage("reference.bmp");//it's 512x512 if you haven't guessed
 
 arraycopy(org.pixels, imgout);
 arraycopy(imgout, whatitwas);
 
 
 frameRate(30);
}


void mouseReleased() {
 int i=0;
 i = mouseY * w + mouseX;
 imgout[i] = addtype;
}

void keyReleased() {
 if (keyCode == '1') {
   addtype = SPACE;
   
 } else if (keyCode == '2') {
   addtype = EH;
   
 } else if (keyCode == '3') {
   addtype = ET;
   
 } else if (keyCode == '4') {
   addtype = WIRE;
   
 }
}

void draw() {
 
 //if (running) {
   
   int i=0;
   
   for (int x=1; x<w-1; x++) {
     for (int y=1; y<h-1; y++) {
       
       i = y * w + x;
       
       if (whatitwas[i] == EH) {
         imgout[i] = ET;
         
       } else if (whatitwas[i] == ET) {
         imgout[i] = WIRE;
         
       } else if (whatitwas[i] == WIRE) {
         
         int electcount=0;

         //I am sure there is a more efficient way to do this but...
         
         if (whatitwas[y * w + (x + 1)] == EH) electcount++;
         if (whatitwas[(y + 1) * w + (x + 1)] == EH) electcount++;
         if (whatitwas[(y + 1) * w + x] == EH) electcount++;
         if (whatitwas[(y - 1) * w + (x + 1)] == EH) electcount++;
         if (whatitwas[(y - 1) * w + x] == EH) electcount++;
         if (whatitwas[(y - 1) * w + (x - 1)] == EH) electcount++;
         if (whatitwas[y * w + (x - 1)] == EH) electcount++;  
         if (whatitwas[(y + 1) * w + (x - 1)] == EH) electcount++;
               
         if ((electcount == 1) || (electcount == 2)) {
           imgout[i] = EH;
         }
           
       }
       
       
     }
   }
   
   if (mousePressed && (mouseButton == LEFT)) {
     
     i = mouseY * w + mouseX;
     imgout[i] = addtype;
   }
   
   
   arraycopy(imgout, whatitwas);
   
   loadPixels();
   
   arraycopy(imgout, pixels);
   
   updatePixels();
 
 //}
 
}



Page Index Toggle Pages: 1