-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.py
81 lines (72 loc) · 1.6 KB
/
layer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import numpy as np
from scipy.misc import toimage
# this creates a 2D layer to be used in the space class
class layer:
def __init__(self, size):
self.s=size
self.s1=size+1
self.s2=(size/2)+1
self.s4=size/4
self.shape=np.array((self.s1,self.s1))
self.space=np.zeros((self.s1,self.s1))
def insert(self,x,y,value):
self.space[x,y]=value
def mirror8(self,x,y,value):
## this considers 4 lines of symmetry
## (x,y)&(y,x) mirrors across y=x
## (x,y)&(x2,y) mirrors left to right
## (x,y)&(x,y2) mirrors top to bottom
## (x,y)&(x2,y2) mirrors across x+y=max
if value==0:
return
x2=self.s-x
y2=self.s-y
self.space[x,y]=value
self.space[y,x]=value
self.space[x,y2]=value
self.space[y2,x]=value
self.space[x2,y]=value
self.space[y,x2]=value
self.space[x2,y2]=value
self.space[y2,x2]=value
def mirror4(self,x,y,value):
if value==0:
return
# this just considers mirror in vertical and horizontal
x2=self.s-x
y2=self.s-y
self.space[x,y]=value
self.space[x,y2]=value
self.space[x2,y]=value
self.space[x2,y2]=value
def mirror2(self,x,y,value):
# mirrors only in x
if value==0:
return
x2=self.s-x
self.space[x,y]=value
self.space[x2,y]=value
def show(self):
toimage(self.space).show()
def getmax(self):
maximum=0.0
i=0
while i<=self.s1:
j=0
while j<-self.s1:
if self.space[i,j]>maximum:
maximum=self.space[i,j]
j+=1
i+=1
return maximum
def getmin (self):
minimum=0.0
i=0
while i<=self.s1:
j=0
while j<-self.s1:
if self.space[i,j]<minimum:
minimum=self.space[i,j]
j+=1
i+=1
return minimum