Hello to all, This is my first script, I mean the first that I'm trying to do on my own. Its a very simple Cellular Automata thing, the idea is that the initial list A_List is rewritten based on some rules, in this case Wolfram's rule 30. You can modify the list length and its initial state, you can also set the number of iterations.
What I would like is to see how it can be improved. The basic functionality is done, I just want to listen some advise from experts like you : ) For example how can I improve the way in which the rules are written? Would you use the same method that I have chosen? And what about the if and else that are right after the two loops? they are there because if not when the loop gets to the last number an exception arises. Thanks a lot Carlos Here is the code: Note: Right now maya is not needed to run the code. #My first try at Cellular Automata #A very basic script that lets you play with Wolfram's rule 30 #if you wish to see the results in maya, you will need CGKit and Maya #from maya.api import * #from maya.mel import * import time #This is the initial state. You can put as many integers as you wish A_List = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] A_Len = len(A_List) print 'A_List: ',A_List print 'A_Len: ', A_Len B_List = [] S = A_Len print S #This is the number of iterations. for r in range (50): for i in range (S): #if i < S-1: a = A_List[i-1] b = A_List[i] c = A_List[i+1] else: a = A_List[i-1] b = A_List[i] c = A_List[0] if a == 1 and b == 1 and c == 1: X = 0 elif a == 1 and b == 1 and c == 0: X = 0 elif a == 1 and b == 0 and c == 1: X = 0 elif a == 1 and b == 0 and c == 0: X = 1 elif a == 0 and b == 1 and c == 1: X = 1 elif a == 0 and b == 1 and c == 0: X = 1 elif a == 0 and b == 0 and c == 1: X = 1 elif a == 0 and b == 0 and c == 0: X = 0 #print i,a,b,c,X #if X == 1: #print r,i,X #polyCube() #move(r=(i,r,0)) B_List.append(X) print 'B_List: ',B_List A_List = B_List B_List = [] _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor