-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern.py
More file actions
91 lines (55 loc) · 2.08 KB
/
pattern.py
File metadata and controls
91 lines (55 loc) · 2.08 KB
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
82
83
84
import numpy as np
import matplotlib.pyplot as plt
import sys
class Checker:
def __init__(self, resolution, tile_size):
self.resolution = resolution
self.tile_size = tile_size
self.output = 0
def draw(self):
if self.resolution %(self.tile_size*2) != 0:
sys.exit()
else:
factor = self.resolution // (2 * self.tile_size)
row = np.concatenate((np.zeros((self.tile_size, self.tile_size)),
np.ones((self.tile_size, self.tile_size))), axis=1)
block = np.concatenate((row, np.flip(row, axis=1)), axis=0)
self.output = np.tile(block, (factor, factor))
print(row)
return self.output.copy()
def show(self):
plt.axis('off')
plt.imshow(self.output,cmap ='grey')
plt.show()
class Circle:
def __init__(self,resolution,radius,position):
self.resolution= resolution
self.radius=radius
self.position=position
self.output= 0
def draw(self):
self.output = np.zeros((self.resolution, self.resolution))
x,y = np.meshgrid(np.arange(self.resolution), np.arange(self.resolution))
inside_circle = np.sqrt((x - self.position[0]) ** 2 + (y - self.position[1]) ** 2)
self.output[inside_circle <= self.radius] = 1
return self.output.copy()
def show(self):
plt.axis('off')
plt.imshow(self.output,cmap='grey')
plt.show()
class Spectrum:
def __init__(self,resolution):
self.resolution=resolution
self.output=0
def draw(self):
pattern = np.zeros([self.resolution,self.resolution,3])
pattern[:,:,0]=np.linspace(0,1,self.resolution)
pattern[:,:,1]=np.linspace(0,1,self.resolution).reshape(self.resolution,1)
pattern[:,:,2]=np.linspace(1,0,self.resolution)
self.output=pattern
print(self.output)
return self.output.copy()
def show(self):
plt.axis('off')
plt.imshow(self.output)
plt.show()