-
Notifications
You must be signed in to change notification settings - Fork 9
/
ImageNeurons.py
41 lines (34 loc) · 1.03 KB
/
ImageNeurons.py
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
import queue
import numpy as np
import matplotlib.pyplot as plt
max_x = 30
max_y = 30
image_neurons = np.zeros((max_x, max_y))
directions = [[0, 1], [1, 0],
[0, -1], [-1, 0],
[1, 1], [-1, -1],
[-1, 1], [1, -1],
]
old_images=[]
def fire_neuron(col, row):
old_images.append(image_neurons)
visited = np.zeros((max_x, max_y))
q = queue.Queue()
value = max(col, row, max_x - col, max_y - row)
q.put([col, row, value])
while not q.empty():
current = q.get()
x = current[0]
y = current[1]
value = current[2]
image_neurons[x][y] = value
for direction in directions:
new_x = x + direction[0]
new_y = y + direction[1]
if 0 <= new_x < max_x and 0 <= new_y < max_y and not visited[new_x][new_y]:
q.put([new_x, new_y, value - 1])
visited[new_x][new_y] = 1
fire_neuron(20, 15)
plt.imshow(image_neurons,cmap='gray', interpolation='none')
plt.show()
print(old_images)