-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
49 lines (39 loc) · 1.43 KB
/
Copy pathexamples.py
File metadata and controls
49 lines (39 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from rplife.grid import LifeGrid
from rplife.patterns import Pattern
from rplife.views import CursesView
from pprint import pprint
"""RPLife basic examples.
These are RPLife examples. The script imports some rplife modules, like: the grid and pattern. It creates named
instances of pattern. Then, it creates a LifeGrid object using the desired instance which it then prints out
in different states from initialization and so on.
The first example is the blinker pattern. With this pattern if you evolve the grid an even number of times, the
grid produces the same set of live cells that were used as the initial seed for the game. This is because the
Blinker pattern is an oscillator pattern that evolves like this: the Blinker pattern displays three horizontal
alive cells in one generation and three vertical alive cells in the next generation.
"""
blinker = Pattern.get_pattern("Blinker")
grid = LifeGrid(blinker)
print(grid)
grid.evolve()
print(grid)
grid.evolve()
print(grid)
# It is at initial state
print(grid.as_string((0, 0, 5, 5)))
grid.evolve()
print(grid.as_string((0, 0, 5, 5)))
grid.evolve()
print(grid.as_string((0, 0, 5, 5)))
# Get all RPLife prints
pprint(Pattern.get_all_patterns())
#RP Life with curses
# ...
from time import sleep
sleep(5)
pattern = "Glider Gun"
pause = 10
print(f"Launching curses '{pattern}' pattern in {pause} seconds...")
sleep(pause)
# ...
CursesView(Pattern.get_pattern(pattern), gen=100).show()
print(f"Done.")