from string import *
from PIL import Image
from numpy import *
from pylab import *
from math import *
arc = array([[270,332,31,61,194],[62,59,30,133,76]])
cl = array([[128,252,0],[230,230,250],[248,255,128],[128,183,255],[153,217,234]])
a = array([4,9,2,4,5])
def todegree(x,y):
an = y/math.sqrt(x*x+y*y)
ag = math.degrees(math.asin(an))
if x>0 and y>0:
return [ag]
if x<0 and y>0:
return [180-ag]
if x<0 and y<0:
return [180-ag]
if x > 0 and y < 0:
return [360+ag]
if x==0 and y>0:
return [90]
if x==0 and y<0:
return [270]
if x>0 and y==0:
return [0]
if x<0 and y==0:
return [180]
def ACOLOR(n):
xa = int(A[n].split(",")[0])
ya = int(A[n].split(",")[1])
for li in lists:
x = int(li.split(",")[0])
y = int(li.split(",")[1])
if (x-xa)*(x-xa)+(y-ya)*(y-ya) <= 6:
map.append(str(x)+","+str(y)+","+str(cl[0]))
lists.remove(str(x)+","+str(y))
A.append(str(x)+","+str(y))
def BCOLOR(n):
xa = int(B[n].split(",")[0])
ya = int(B[n].split(",")[1])
for li in lists:
x = int(li.split(",")[0])
y = int(li.split(",")[1])
if (x-xa)*(x-xa)+(y-ya)*(y-ya) <= 9:
map.append(str(x)+","+str(y)+","+str(cl[0]))
lists.remove(str(x)+","+str(y))
B.append(str(x)+","+str(y))
def CCOLOR(n):
xa = int(C[n].split(",")[0])
ya = int(C[n].split(",")[1])
for li in lists:
x = int(li.split(",")[0])
y = int(li.split(",")[1])
if (x-xa)*(x-xa)+(y-ya)*(y-ya) <= 9:
map.append(str(x)+","+str(y)+","+str(cl[0]))
lists.remove(str(x)+","+str(y))
C.append(str(x)+","+str(y))
def DCOLOR(n):
xa = int(D[n].split(",")[0])
ya = int(D[n].split(",")[1])
for li in lists:
x = int(li.split(",")[0])
y = int(li.split(",")[1])
if (x-xa)*(x-xa)+(y-ya)*(y-ya) <= 9:
map.append(str(x)+","+str(y)+","+str(cl[0]))
lists.remove(str(x)+","+str(y))
D.append(str(x)+","+str(y))
def ECOLOR(n):
xa = int(E[n].split(",")[0])
ya = int(E[n].split(",")[1])
for li in lists:
x = int(li.split(",")[0])
y = int(li.split(",")[1])
if (x-xa)*(x-xa)+(y-ya)*(y-ya) <= 9:
map.append(str(x)+","+str(y)+","+str(cl[0]))
lists.remove(str(x)+","+str(y))
E.append(str(x)+","+str(y))
arr = array(Image.open("D:\\JAVA\\JAVA 项目 1\\8-1.bmp"))
A = []
B = []
C = []
D = []
E = []
lists = []
map = []
black = []
m,n = arr.shape[0:2]
for x in range(m):
for y in range(n):
if all(arr[x][y] == [0,0,0]):
black.append(str(x)+","+str(y))
elif all(arr[x][y] == [204,204,204]):
lists.append(str(x)+","+str(y))
else:
map.append(str(x)+","+str(y)+","+str(arr[x][y]))
for b in black:
x = int(b.split(",")[0])
y = int(b.split(",")[1])
ag = todegree(x - 502,399 - y)
if arc[0][0]+arc[1][0] < 360 and ag >= arc[0][0] and ag <= arc[1][0]+arc[0][0]:
A.append(str(x)+","+str(y))
for b in black:
x = int(b.split(",")[0])
y = int(b.split(",")[1])
ag = todegree(x - 499,352 - y)
if arc[0][1]+arc[1][1] > 360 and (ag >= arc[0][1] or ag <= arc[1][1]+arc[0][1]-360):
B.append(str(x)+","+str(y))
for b in black:
x = int(b.split(",")[0])
y = int(b.split(",")[1])
ag = todegree(x - 499,352 - y)
if arc[0][2]+arc[1][2] < 360 and ag >= arc[0][2] and ag <= arc[1][2]+arc[0][2]:
C.append(str(x)+","+str(y))
if arc[0][2]+arc[1][2] > 360 and (ag >= arc[0][2] or ag <= arc[1][2]+arc[0][2]-360):
C.append(str(x)+","+str(y))
for b in black:
x = int(b.split(",")[0])
y = int(b.split(",")[1])
ag = todegree(x - 499,352 - y)
if arc[0][3]+arc[1][3] < 360 and ag >= arc[0][3] and ag <= arc[1][3]+arc[0][3]:
D.append(str(x)+","+str(y))
if arc[0][3]+arc[1][3] > 360 and (ag >= arc[0][3] or ag <= arc[1][3]+arc[0][3]-360):
D.append(str(x)+","+str(y))
for b in black:
x = int(b.split(",")[0])
y = int(b.split(",")[1])
ag = todegree(x - 499,352 - y)
if arc[0][4]+arc[1][4] < 360 and ag >= arc[0][4] and ag <= arc[1][4]+arc[0][4]:
E.append(str(x)+","+str(y))
if arc[0][4]+arc[1][4] > 360 and (ag >= arc[0][4] or ag <= arc[1][4]+arc[0][4]-360):
E.append(str(x)+","+str(y))
counta = len(A);
countb = len(B);
countc = len(C);
countd = len(D);
counte = len(E);
count = []
n = 0
for i in range(5):
count.append(len(lists) * a[i] / 24 + 50)
while 1 > 0 :
print(len(lists))
if len(lists) > 10:
for i in range(a[0]):
if len(A) - counta < count[0]:
ACOLOR((n*a[0]+i)%len(A));
for i in range(a[1]):
if len(B) - countb < count[1]:
BCOLOR((n*a[1]+i)%len(B));
for i in range(a[2]):
if len(C) - countc < count[2]:
CCOLOR((n*a[2]+i)%len(C));
for i in range(a[3]):
if len(D) - countd < count[3]:
DCOLOR((n*a[3]+i)%len(D));
for i in range(a[4]):
if len(E) - counte < count[4]:
ECOLOR((n*a[4]+i)%len(E));
else:
n = n+1
break
print(map)
print(len(map))