diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-02-27 22:03:52 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-27 22:03:52 -0500 |
| commit | 568c04e6afa8016062f685b2198c0209f62827f4 (patch) | |
| tree | d07b76119f715add462983b335797adf64b61249 /examples/conwaylife.py | |
| parent | 6a2379fd0bfe10017d8abc5c36ef1d470c0d9b27 (diff) | |
| parent | ea633117d01d94e8d56ed94344e4b3e46b4eef03 (diff) | |
Merge pull request #650 from tannewt/merge_2x3.0.0-alpha.2
Merge in commits from 2.x branch.
Diffstat (limited to 'examples/conwaylife.py')
| -rw-r--r-- | examples/conwaylife.py | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/examples/conwaylife.py b/examples/conwaylife.py deleted file mode 100644 index 323f42e85..000000000 --- a/examples/conwaylife.py +++ /dev/null @@ -1,46 +0,0 @@ -#import essential libraries -import pyb - -lcd = pyb.LCD('x') -lcd.light(1) - -# do 1 iteration of Conway's Game of Life -def conway_step(): - for x in range(128): # loop over x coordinates - for y in range(32): # loop over y coordinates - # count number of neighbours - num_neighbours = (lcd.get(x - 1, y - 1) + - lcd.get(x, y - 1) + - lcd.get(x + 1, y - 1) + - lcd.get(x - 1, y) + - lcd.get(x + 1, y) + - lcd.get(x + 1, y + 1) + - lcd.get(x, y + 1) + - lcd.get(x - 1, y + 1)) - - # check if the centre cell is alive or not - self = lcd.get(x, y) - - # apply the rules of life - if self and not (2 <= num_neighbours <= 3): - lcd.pixel(x, y, 0) # not enough, or too many neighbours: cell dies - elif not self and num_neighbours == 3: - lcd.pixel(x, y, 1) # exactly 3 neighbours around an empty cell: cell is born - -# randomise the start -def conway_rand(): - lcd.fill(0) # clear the LCD - for x in range(128): # loop over x coordinates - for y in range(32): # loop over y coordinates - lcd.pixel(x, y, pyb.rng() & 1) # set the pixel randomly - -# loop for a certain number of frames, doing iterations of Conway's Game of Life -def conway_go(num_frames): - for i in range(num_frames): - conway_step() # do 1 iteration - lcd.show() # update the LCD - pyb.delay(50) - -# testing -conway_rand() -conway_go(100) |
