INNER CODE UNIT · Python
_custom_rule
ljvmiranda921/sprites-as-a-service · backend/sprites/sprites.py:99
def _custom_rule(
X: np.ndarray, n_extinct: int = 3, n_survive: int = 3
) -> np.ndarray:
"""Custom Conway's Rule"""
n = convolve2d(X, np.ones((3, 3)), mode="same", boundary="fill") - X
reproduction_rule = (X == 0) & (n <= n_extinct)
stasis_rule = (X == 1) & ((n == 2) | (n == n_survive))
return reproduction_rule | stasis_rule
def _color(seeds: Tuple[int, int, int] = None) -> str:
"""Returns a random hex code"""
hex_values = []
for i in range(3):
if seeds:
random.seed(seeds[i])
h = random.randint(0, 255)
hex_values.append(h)