Added header.
2 Description: Circular cellular growth rules.
3 Author: Eugen Sawin <sawine@me73.com>
10 def iterate(self, oldgrid):
11 grid = copy.deepcopy(oldgrid)
12 for x in xrange(oldgrid.minx - 1, oldgrid.maxx + 2):
13 for y in xrange(oldgrid.miny - 1, oldgrid.maxy + 2):
14 #print x, y, self.neighbours(oldgrid, x, y)
15 n = self.neighbours(oldgrid, (x, y))
20 def neighbours(self, grid, (testx, testy)):
22 #print "testing ", testx, testy
23 for x in range(testx - 1, testx + 2):
24 for y in range(testy - 1, testy + 2):
25 if (x, y) in grid.cells:
32 def iterate(self, oldgrid):
33 grid = copy.deepcopy(oldgrid)
34 for x in xrange(oldgrid.minx - 1, oldgrid.maxx + 2):
35 for y in xrange(oldgrid.miny, oldgrid.maxy + 2):
36 #print "testing ", x, y,
37 if (x+1, y) in oldgrid.cells or (x, y-1) in oldgrid.cells:
44 class PotentialGrowth(object):
47 self.potential = 4 # values 4-8 are viable
49 def iterate(self, oldgrid):
52 for i in range(2, self.potential+1):
53 if i in oldgrid.valuemap:
54 value_pos[i] = copy.deepcopy(oldgrid.valuemap[i])
55 for value, cells in value_pos.iteritems():
57 new_pos, new_value = self.grow(grid, pos)
58 grid.set(new_pos, new_value)
59 grid.set(pos, value - 1)
62 def grow(self, grid, (x, y)):
63 n1 = [(x-1, y), (x, y+1), (x+1, y), (x, y-1)]
64 n2 = [(x+1, y+1), (x+1, y-1), (x-1, y-1), (x-1, y+1)]
68 neighbours = random.choice(random.choice((c0, c1, c2)))
69 neighbours = [n for n in neighbours if n not in grid.cells]
71 pos = random.choice(neighbours)
72 value = self.potential
75 value = grid.cells[pos]