-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
31 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,56 @@ | ||
import numpy as np | ||
|
||
cols = 100 | ||
filas = 100 | ||
matrix = np.zeros((100, 100), dtype=int) #[[0] * cols for _ in range(filas)] | ||
# to implement and idea stolen from Carlos @vamoss | ||
c_matrix = np.zeros((100, 100), dtype=int) | ||
|
||
geracao = 0 | ||
regras_legais = [ # Algumas regras de que gostamos | ||
[1, 0, 1, 1, 1, 1, 1, 0], # Regra 125 | ||
[1, 0, 0, 1, 0, 1, 0, 1], # Regra 169 | ||
[0, 1, 1, 1, 1, 0, 0, 0], # Regra 30 | ||
[0, 1, 1, 1, 0, 1, 1, 0], # Regra 110 | ||
rows = 100 | ||
matrix = np.zeros((100, 100), dtype=int) | ||
c_matrix = np.zeros((100, 100), dtype=int) # to implement and idea stolen from Carlos @vamoss | ||
gen = 0 | ||
nice_rules = [ # Some rules we like | ||
[1, 0, 1, 1, 1, 1, 1, 0], # rule 125 | ||
[1, 0, 0, 1, 0, 1, 0, 1], # rule 169 | ||
[0, 1, 1, 1, 1, 0, 0, 0], # rule 30 | ||
[0, 1, 1, 1, 0, 1, 1, 0], # rule 110 | ||
] | ||
ruleset = regras_legais[3] | ||
|
||
ruleset = nice_rules[2] | ||
|
||
def setup(): | ||
size(800, 800) | ||
no_smooth() | ||
no_stroke() | ||
|
||
matrix[cols // 2][0] = 1 # Começa com "1" no meio da 1ª linha | ||
matrix[cols // 2, 0] = 1 # Começa com "1" no meio da 1ª linha | ||
frame_rate(10) | ||
|
||
|
||
|
||
def draw(): | ||
background(200) | ||
scale(8) | ||
offset = geracao % filas | ||
offset = gen % rows | ||
for i in range(cols): | ||
for j in range(filas): | ||
for j in range(rows): | ||
y = j - offset | ||
if y <= 0: | ||
y = filas + y | ||
if matrix[i][j] == 1: # Se a célula i, está viva/ativa/1 | ||
stroke(c_matrix[i][j])# stroke(c_matrix[i][j]) | ||
y = rows + y | ||
if matrix[i, j] == 1: # Se a célula i, está viva/ativa/1 | ||
stroke(c_matrix[i, j])# stroke(c_matrix[i, j]) | ||
else: | ||
stroke(200) | ||
point(i, y - 1) | ||
|
||
nova_geracao() | ||
new_gen() | ||
|
||
def nova_geracao(): | ||
global geracao | ||
def new_gen(): | ||
global gen | ||
for i in range(cols): | ||
esq = matrix[(i + cols - 1) % cols][geracao % filas] | ||
centro = matrix[i][geracao % filas] | ||
dir = matrix[(i + 1) % cols][geracao % filas] | ||
result = ruleset[esq * 4 + centro * 2 + dir * 1] | ||
cor = color(55 + esq * 100, 55 + centro * 100, 55 + dir * 100) | ||
matrix[i][(geracao + 1) % filas] = result | ||
c_matrix[i][(geracao + 1) % filas] = cor | ||
geracao += 1 | ||
left = matrix[(i + cols - 1) % cols, gen % rows] | ||
centre = matrix[i, gen % rows] | ||
right = matrix[(i + 1) % cols, gen % rows] | ||
result = ruleset[left * 4 + centre * 2 + right * 1] | ||
cor = color(55 + left * 100, 55 + centre * 100, 55 + right * 100) | ||
matrix[i, (gen + 1) % rows] = result | ||
c_matrix[i, (gen + 1) % rows] = cor | ||
gen += 1 | ||
|
||
|
||
def key_pressed(): | ||
save_frame('####.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters