-
Notifications
You must be signed in to change notification settings - Fork 0
/
TileGen.py
162 lines (148 loc) · 5.16 KB
/
TileGen.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import cv2 as cv
import numpy as np
from MinTuringSpec import *
Manual = True
if Manual:
if "size" in vars():
W=size
H=size
else:
W=20
H=20
path = 'C:/Users/georg/source/repos/WangComputation/Images/'
def my_line(img, start, end,thick=1):
thickness = thick
line_type = 8
cv.line(img,
start,
end,
(255,128,128),
thickness,
line_type)
def triangle_fill(image,pos,colour):
if (pos == 1):
triangle = np.array([[0,0],[0,H],[W/2,H/2]])
elif (pos == 2):
triangle = np.array([[0,H],[W,H],[W/2,H/2]])
elif (pos == 3):
triangle = np.array([[W,H],[W,0],[W/2,H/2]])
elif (pos == 4):
triangle = np.array([[W,0],[0,0],[W/2,H/2]])
cv.fillPoly(image,np.int32([triangle]),color=colour)
def TileGen(spec):
image_arr = []
for i,row in enumerate(spec):
image = np.zeros((W,H,3),dtype=np.uint8)
image[:][:][:] = 255;
index = 0
for column in row:
index+=1
if column!=0:
triangle_fill(image,index,column)
## TOGGLE COMMENT ON THESE LINES TO GET A GRID INTERFACE
#my_line(image,(0,0),(W,H))
#my_line(image,(0,H),(W,0))
#my_line(image,(0,0),(0,H))
#my_line(image,(0,H),(W,H))
#my_line(image,(W,H),(W,0))
#my_line(image,(W,0),(0,0))
##########################################################
image_arr.append(image)
return image_arr;
## OLD STYLE SPEC CALLS - DEPRECATED, USE TURING MACHINES INSTEAD ##
#spec = [(NOP,NOP,NOP,NOP), #ADDITION
# (GREY,NOP,NOP,NOP),
# (NOP,NOP,NOP,GREY),
# (GREY,RED,NOP,GREY),
# (GREY,CYAN,NOP,RED),
# (GREY,NOP,YELLOW,CYAN),
# (YELLOW,CYAN,NOP,NOP),
# (NOP,NOP,YELLOW,CYAN),
# (YELLOW,NOP,ORANGE,GREEN),
# (NOP,GREEN,NOP,GREEN),
# (NOP,GREEN,NOP,GREY),
# (ORANGE,NOP,ORANGE,NOP),
# (ORANGE,NOP,BLUE,GREEN),
# (BLUE,NOP,NOP,MAGENTA),
# (NOP,MAGENTA,BLUE,NOP),
# (NOP,MAGENTA,NOP,GREY),
# (BLUE,BLUE,BLUE,BLUE)]
#spec = [(NOP,NOP,NOP,NOP), #FIB
# (GREY,NOP,NOP,NOP),
# (NOP,NOP,NOP,GREY),
# (GREY,YELLOW,GREEN,GREY),
# (GREEN,RED,CYAN,GREY),
# (CYAN,BLUE,CYAN,GREY),
# (CYAN,NOP,CYAN,GREY),
# (GREY,BEIGE,ORANGE,YELLOW),
# (MAGENTA,RED,LIME,RED),
# (LIME,RED,NOP,BLUE),
# (LIME,NOP,NOP,GREEN),
# (NOP,GREEN,LIME,NOP),
# (GREY,NOP,PINK,BEIGE),
# (PINK,BEIGE,NOP,NOP),
# (PINK,BEIGE,MAGENTA,RED),
# (MAGENTA,NOP,MAGENTA,NOP),
# (ORANGE,RED,LIME,RED),
# (NOP,NOP,PINK,BEIGE),
# (NOP,RED,NOP,RED),
# (BLUE,BLUE,BLUE,BLUE)]
#spec = [(DGREY,GREY,RED,DGREY), #n-bit turing counter
# (RED,MAGENTA,ORANGE,DGREY),
# (ORANGE,GREY,PINK,DGREY),
# (PINK,GREY,CYAN,DGREY),
# (DGREY,DGREY,NAVY,GREY),
# (NAVY,DGREY,BLUE,MAGENTA),
# (BLUE,DGREY,BLUE,GREY),
# (DGREY,DGREY,ORANGE,GREY),
# (ORANGE,DGREY,NAVY,GREY),
# (RED,GREY,RED,DGREY),
# (DGREY,GREY,ORANGE,DGREY), #start1,10
# (RED,GREY,RED,DGREY),
# (BLUE,MAGENTA,NAVY,DGREY),
# (NAVY,GREY,CYAN,DGREY),
# (CYAN,BEIGE,RED,DGREY),
# (DGREY,DGREY,RED,GREY), #start2,15
# (RED,DGREY,RED,GREY),
# (ORANGE,DGREY,RED,MAGENTA),
# (RED,DGREY,PINK,BEIGE),
# (PINK,DGREY,BLUE,MAGENTA),
# (DGREY,GREY,BLUE,GREY),#start3,20
# (DGREY,GREY,RED,GREY), #start4,21
# (RED,GREY,RED,GREY),
# (BLUE,GREY,BLUE,GREY),
# (RED,GREY,PINK,BEIGE),
# (BLUE,GREY,CYAN,BEIGE),
# (RED,MAGENTA,ORANGE,GREY),
# (BLUE,MAGENTA,NAVY,GREY),
# (ORANGE,GREY,RED,MAGENTA),
# (NAVY,GREY,BLUE,MAGENTA),
# (CYAN,BEIGE,RED,GREY),
# (PINK,GREY,BLUE,MAGENTA),
# (BLUE,DGREY,CYAN,BEIGE),
# (CYAN,DGREY,WHITE,GREY),
# (PINK,PINK,PINK,PINK)]
###################################################################
if __name__=='__main__':
image_arr = TileGen(spec)
index=0
f = open("image_specs.txt", "w")
for im in image_arr:
cv.imshow("Tile",im)
cv.waitKey(0)
cv.imwrite(path+"image"+str(index)+".jpg",im)
f.write(str(spec[index]))
f.write("\n")
index+=1
f.close()
cv.destroyAllWindows()
else:
image_arr = TileGen(spec)
index=0
f = open("image_specs.txt", "w")
for im in image_arr:
cv.imwrite(path+"image"+str(index)+".jpg",im)
f.write(str(spec[index]))
f.write("\n")
index+=1
f.close()