#time:2022/3/23 10:04
#author:yigeshuaige
#
import cv2
import numpy as np
import time
import random
import autopy
VOID=0
WRITE=1
BLUE=2
RED=3
GREEN=4
ORANGE=5
YELLOW=6
class CLASS_BLOCK:
def __init__(self,position_t,color_data_t,type):
self.position=position_t
self.type = type
self.color=color_data_t
def print_class(self):
print(self.type, self.position, self.color)
def rotate(self,dir):
if dir ==1:
self.color = [self.color[1],self.color[0],self.color[2]]
self.position=[-self.position[1],self.position[0],self.position[2]]
def draw_rectangle(x,y,color):
if color=='VOID':
cv2.rectangle(img, (x, y), (x+50, y+50), (0, 0, 0), -1)
elif color=='WRITE':
cv2.rectangle(img, (x, y), (x + 50, y + 50), (255, 255, 255), -1)
elif color=='BLUE':
cv2.rectangle(img, (x, y), (x + 50, y + 50), (255, 0, 0), -1)
elif color=='RED':
cv2.rectangle(img, (x, y), (x + 50, y + 50), (0, 0, 255), -1)
elif color=='GREEN':
cv2.rectangle(img, (x, y), (x + 50, y + 50), (0, 255, 0), -1)
elif color=='ORANGE':
cv2.rectangle(img, (x, y), (x + 50, y + 50), (0,165, 255), -1)
elif color=='YELLOW':
cv2.rectangle(img, (x, y), (x + 50, y + 50), (0, 255, 255), -1)
else:
cv2.rectangle(img, (x, y), (x + 50, y + 50), (100, 100, 100), -1)
def draw_show9(x,y,list_t):
for i in range(0,3):
for k in range(0,3):
draw_rectangle(x+k*50, y+i*50, list_t[i*3+k])
def draw_1(data):
list_t=[]
##白色,底层
for k in range(0, 3):
for i in range(0, 3):
list_t.append(data[i][k][0][2])
draw_show9(100+150, 100+150+10, list_t)
##黄色
list_t = []
for k in range(2,-1,-1):
for i in range(0, 3):
list_t.append(data[i][k][2][2])
draw_show9(100+150, 100+450+30, list_t)
##蓝色
list_t = []
for k in range(2, -1, -1):
for i in range(0, 3):
list_t.append(data[i][0][k][1])
draw_show9(100+150, 100, list_t)
##绿green色
list_t = []
for k in range(0, 3):
for i in range(0, 3):
list_t.append(data[i][2][k][1])
draw_show9(100+150, 100+300+20, list_t)
##红色
list_t = []
for k in range(0, 3):
for i in range(0, 3):
list_t.append(data[2][k][i][0])
draw_show9(100+300+10, 100+150+10, list_t)
##橙色
list_t = []
for k in range(0, 3):
for i in range(2,-1,-1):
list_t.append(data[0][k][i][0])
draw_show9(90, 100+150+10, list_t)
cube = [[],[],[]]
def reset_cube():
for i in range(0, 3):
c = []
for k in range(0, 3):
b = []
for p in range(0, 3):
a = [0, 0, 0]
if i == 1:
a[0] = 'VOID'
elif i == 2:
a[0] = 'RED'
else:
a[0] = 'ORANGE'
if k == 1:
a[1] = 'VOID'
elif k == 2:
a[1] = 'GREEN'
else:
a[1] = 'BLUE'
if p == 1:
a[2] = 'VOID'
elif p == 2:
a[2] = 'YELLOW'
else:
a[2] = 'WRITE'
b.append(a)
c.append(b)
cube[i]=c
# print(cube[0])
# print('**************************************************************************')
# for i in range(0,len(cube)):
# print(i,end=' ')
# cube[i].print_class()
# draw_show9(100,100,CUBE[0])
# cube[1].color=[7,7,7]
def xuanzhuan(dir_type):
if dir_type >= 9 and dir_type <= 12:
if dir_type == 9 or dir_type == 10:
z = 0
if dir_type == 11 or dir_type == 12:
z = 2
x=-1
y=-1
k=0
temp = cube[x+1][y+1][z]
for i in range(0,3):
if(dir_type==9or dir_type==12):
cube[x + 1][y + 1][z] = [cube[-y + 1][x + 1][z][1], cube[-y + 1][x + 1][z][0],
cube[-y + 1][x + 1][z][2]]
temp_num=x
x = -y
y = temp_num
else:
cube[x + 1][y + 1][z] = [cube[y + 1][-x + 1][z][1], cube[y + 1][-x + 1][z][0],
cube[y + 1][-x + 1][z][2]]
temp_num = x
x = y
y = -temp_num
cube[x + 1][y + 1][z]=[temp[1],temp[0],temp[2]]
x = -1
y = 0
temp = cube[x + 1][y + 1][z]
for i in range(0, 3):
if (dir_type == 9 or dir_type == 12):
cube[x + 1][y + 1][z] = [cube[-y + 1][x + 1][z][1], cube[-y + 1][x + 1][z][0],
cube[-y + 1][x + 1][z][2]]
temp_num = x
x = -y
y = temp_num
else:
cube[x + 1][y + 1][z] = [cube[y + 1][-x + 1][z][1], cube[y + 1][-x + 1][z][0],
cube[y + 1][-x + 1][z][2]]
temp_num = x
x = y
y = -temp_num
cube[x + 1][y + 1][z] = [temp[1], temp[0], temp[2]]
if dir_type>=5 and dir_type<=8:
if dir_type==5 or dir_type==6:
z=0
if dir_type==7 or dir_type==8:
z=2
x=-1
y=-1
k=0
temp = cube[x+1][z][y+1]
for i in range(0,3):
if(dir_type==6or dir_type==7):
cube[x + 1][z][y + 1] = [cube[-y + 1][z][x + 1][2], cube[-y + 1][z][x + 1][1],
cube[-y + 1][z][x + 1][0]]
temp_num=x
x = -y
y = temp_num
else:
cube[x + 1][z] [y + 1]= [cube[y + 1][z][-x + 1][2], cube[y + 1][z][-x + 1][1],
cube[y + 1][z][-x + 1][0]]
temp_num = x
x = y
y = -temp_num
cube[x + 1][z][y + 1]=[temp[2],temp[1],temp[0]]
x = -1
y = 0
temp = cube[x + 1][z][y + 1]
for i in range(0, 3):
if (dir_type == 6 or dir_type == 7):
cube[x + 1][z][y + 1] = [cube[-y + 1][z][x + 1][2], cube[-y + 1][z][x + 1][1],
cube[-y + 1][z][x + 1][0]]
temp_num = x
x = -y
y = temp_num
else:
cube[x + 1][z][y + 1] = [cube[y + 1][z][-x + 1][2], cube[y + 1][z][-x + 1][1],
cube[y + 1][z][-x + 1][0]]
temp_num = x
x = y
y = -temp_num
cube[x + 1][z] [y + 1]= [temp[2], temp[1], temp[0]]
if dir_type>=1 and dir_type<=4:
if dir_type==1 or dir_type==2:
z=0
if dir_type==4 or dir_type==3:
z=2
x=-1
y=-1
k=0
temp = cube[z][x+1][y+1]
for i in range(0,3):
if(dir_type==1or dir_type==4):
cube[z][x + 1][y + 1] = [cube[z][-y + 1][x + 1][0], cube[z][-y + 1][x + 1][2],
cube[z][-y + 1][x + 1][1]]
temp_num=x
x = -y
y = temp_num
else:
cube[z][x + 1] [y + 1]= [cube[z][y + 1][-x + 1][0], cube[z][y + 1][-x + 1][2],
cube[z][y + 1][-x + 1][1]]
temp_num = x
x = y
y = -temp_num
cube[z][x + 1][y + 1]=[temp[0],temp[2],temp[1]]
x = -1
y = 0
temp = cube[z][x + 1][y + 1]
for i in range(0, 3):
if (dir_type == 1 or dir_type == 4):
cube[z][x + 1][y + 1] = [cube[z][-y + 1][x + 1][0], cube[z][-y + 1][x + 1][2],
cube[z][-y + 1][x + 1][1]]
temp_num = x
x = -y
y = temp_num
else:
cube[z][x + 1][y + 1] = [cube[z][y + 1][-x + 1][0], cube[z][y + 1][-x + 1][2],
cube[z][y + 1][-x + 1][1]]
temp_num = x
x = y
y = -temp_num
cube[z][x + 1] [y + 1]= [temp[0], temp[2], temp[1]]
reset_cube()
count=0
cc=0
img=np.zeros((800,800,3),np.uint8)
def show_img():
draw_1(cube)
cv2.namedWindow("picture", 0);
cv2.moveWindow("picture", -1000, 500)
cv2.imshow("picture", img)
time.sleep(0.1)
cv2.waitKey(0)
while 1:
count+=1
xuanzhuan(1)
show_img()
# reset_cube()
#
# xuanzhuan(1)
# xuanzhuan(5)
# xuanzhuan(3)
# xuanzhuan(9)
#
# # xuanzhuan(3)
# zidian=[]
# zidian.append(random.randint(1, 12))
# for i in range(1,100):
# zidian.append(random.randint(1, 12))
# if(zidian[i-1]%2==0):
# while zidian[i]==zidian[i-1]-1:
# zidian[i]=random.randint(1, 12)
# if (zidian[i - 1] % 2 == 1):
# while zidian[i] == zidian[i-1]+1:
# zidian[i] = random.randint(1, 12)
# if count%1000==0:
# print(count)
# # print(count,zidian)
# for i in zidian:
# xuanzhuan(i)
# # draw_1(cube)
# # cv2.namedWindow("picture", 0);
# # cv2.moveWindow("picture", -1000, 500)
# # cv2.imshow("picture", img)
# # time.sleep(0.1)
# # cv2.waitKey(0)
# cc=0
# for k in range(0, 3):
# for p in range(0, 3):
#
# if cube[p][k][2][2] == 'YELLOW' and cube[p][k][0][2] == 'WRITE' :
# if cube[0][p][k][0]=='ORANGE' and cube[2][p][k][0]=='RED':
# if cube[p][2][k][1]=='GREEN' and cube[p][0][k][1]=='BLUE':
# cc += 1
# if cc == 9:
# print(count, '找到了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
# print(zidian)
# time.sleep(10)
cv2.destroyAllWindows()
# cc=0
# count+=1
# if(count%4==1):
# xuanzhuan(1)
# elif count%4==2:
# xuanzhuan(7)
# elif count%4==3:
# xuanzhuan(3)
# elif count%4==0:
# xuanzhuan(5)
# for k in range(0,3):
# for p in range(0, 3):
# if cube[p][k][2][2]=='YELLOW' and cube[p][k][0][2]=='WRITE' :
# cc+=1
# # print(count,cc)
# if cc==9 :
# print(count,'找到了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
# time.sleep(2)