Alexandre B A Villares 2019-09-20 22:56:04 -03:00
rodzic df6eb3b5b4
commit dc00a90497
29 zmienionych plików z 136 dodań i 18 usunięć

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 5.8 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 5.8 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 5.7 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 5.5 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 5.0 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.9 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.9 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.7 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.5 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.5 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.4 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.9 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.6 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.6 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.5 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.5 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.7 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.8 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 3.2 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.6 KiB

Wyświetl plik

@ -2,21 +2,12 @@ cell_size = 10
from random import choice
clr = 255
# ngbs_list = ((-1, 0), ( 1, 0),
# (-1, -1), ( 0, -1),
# ( 1, -1), (-1, 1),
# ( 0, 1), ( 0, 0))
# ngbs_list = ((-1, 0), ( 0, 1),
# (-1, -1), ( 0, -1),
# ( 1, -1), (-1, 1),
# ( 0, 1), ( 1, 1))
ngbs_list = ((-2, 0), ( 2, 0),
NEIGHBOURS = ((-2, 0), ( 2, 0),
(-1, -1), ( 0, -2),
( 1, -1), (-1, 1),
( 0, 2), ( 1, 1))
def rule(s, v):
if v < 2 or v > 3:
return 0
@ -36,10 +27,12 @@ def setup():
grid = empty_grid()
next_grid = empty_grid()
noStroke()
println("Press 'space' to start/stop")
println("'e' to clear all cells")
println("'r' to randomize grid")
def draw():
# background(0)
background(0)
for i in range(cols):
x = i * cell_size
for j in range(rows):
@ -53,9 +46,7 @@ def draw():
if current_state:
# circle(x, y, cell_size * 2) # overlapping circles
fill((clr+ next_grid[i][j]*128)%255, 255, current_state * 255)
else:
fill(0, 100)
square(x, y, cell_size)
square(x, y, cell_size)
if play:
@ -63,7 +54,7 @@ def draw():
def calc_ngbs_alive(i, j):
alive = 0
for iv, jv in ngbs_list:
for iv, jv in NEIGHBOURS:
alive += grid[(i + iv) % cols][(j + jv) % rows]
return alive
@ -94,7 +85,9 @@ def keyPressed():
if key == " ":
global play
play = not play
if key == "s":
saveFrame("#####.png")
def mouseReleased():
invert_on_mouse()

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 12 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 12 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 12 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 12 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 7.9 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 12 KiB

Wyświetl plik

@ -0,0 +1,107 @@
cell_size = 10
from random import choice
clr = 255
NEIGHBOURS = ((-2, 0), ( 2, 0),
(-1, -1), ( 0, -2),
( 1, -1), (-1, 1),
( 0, 2), ( 1, 1))
def rule(s, v):
if v < 2 or v > 3:
return 0
elif v == 3:
return 1
else:
return s
play = False
def setup():
global grid, next_grid, rows, cols
size(755, 500)
colorMode(HSB)
rows = height / cell_size
cols = width / cell_size
grid = empty_grid()
next_grid = empty_grid()
noStroke()
def draw():
# background(0)
for i in range(cols):
x = i * cell_size
for j in range(rows):
y = j * cell_size
current_state = grid[i][j]
# fill(clr, 255, current_state * 255, 100) # translucent
ngbs_alive = calc_ngbs_alive(i, j)
result = rule(current_state, ngbs_alive)
next_grid[i][j] = result
if current_state:
# circle(x, y, cell_size * 2) # overlapping circles
fill((clr+ next_grid[i][j]*128)%255, 255, current_state * 255)
else:
fill(0, 10)
square(x, y, cell_size)
if play:
step()
def calc_ngbs_alive(i, j):
alive = 0
for iv, jv in NEIGHBOURS:
alive += grid[(i + iv) % cols][(j + jv) % rows]
return alive
def empty_grid():
grid = []
for _ in range(cols):
grid.append([0] * rows)
return grid
def randomize_grid():
global clr
clr = random(255)
for i in range(cols):
for j in range(rows):
grid[i][j] = choice((0, 1))
def step():
global grid, next_grid
grid = next_grid
next_grid = empty_grid()
def keyPressed():
global grid
if key == "e":
grid = empty_grid()
if key == "r":
randomize_grid()
if key == " ":
global play
play = not play
if key == "s":
saveFrame("#####.png")
def mouseReleased():
invert_on_mouse()
def mouseDragged():
invert_on_mouse()
def invert_on_mouse():
for i in range(cols):
x = i * cell_size
for j in range(rows):
y = j * cell_size
current_state = grid[i][j]
if mouse_over(x, y):
grid[i][j] = (1, 0)[current_state]
def mouse_over(x, y):
return x < mouseX < x + cell_size and y < mouseY < y + cell_size

Wyświetl plik

@ -18,6 +18,24 @@ You may also support my artistic work, open teaching resources and research with
## 2019
---
![sketch_190920a](2019/sketch_190920a/sketch_190920a.png)
[sketch_190920a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190920a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Some accumulation…
---
![sketch_190919a](2019/sketch_190919a/sketch_190919a.png)
[sketch_190919a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190919a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
Modified neighbours form Conway!
---
![sketch_190918a](2019/sketch_190918a/sketch_190918a.gif)