Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import pyscreenshot as ps
- import numpy as np
- import time
- img_path='./'
- #img_path='/var/www/html/imgs/'
- playerNames=['rocapp','kevin1','blink','kevin0']
- topThresh=200
- botThresh=50
- yy=712
- xx=[447,479,511,543]
- Civ={'r':{'crd':[743,361],'clr':(201, 13, 7)},
- 'd':{'crd':[470,10], 'clr':(0, 0, 0)},
- 'w':{'crd':[643,743],'clr':(235, 237, 177)} }
- def isCiv(pxl):
- for k in Civ.keys():
- p0=Civ[k]['crd'][0]
- p1=Civ[k]['crd'][1]
- c=Civ[k]['clr']
- clr = pxl[ p0,p1 ]
- if clr[0]==c[0] and clr[1]==c[1] and clr[2]==c[2]:
- return(True)
- else:
- return(False)
- def saveSwatch(clr,pname):
- swch = Image.new('RGB',(18,18),clr)
- swch.save(img_path+pname+'.jpg')
- def whoseTurn(plyr):
- turn=[0]*4
- for p in range(len(plyr)):
- if plyr[p] < topThresh and plyr[p] > botThresh:
- turn[p]=1
- if np.sum(turn)==1:
- for p in range(len(plyr)):
- if turn[p]==1:
- saveSwatch('green',playerNames[p])
- else:
- saveSwatch('red',playerNames[p])
- else:
- for p in range(len(plyr)):
- saveSwatch('yellow',playerNames[p])
- ln=100
- zz = np.zeros((4,ln))
- # initialize zz with real data; takes a minute,
- # but doesn't check if civ is fullscreen <lazy>
- for j in range(ln):
- img = ps.grab()
- #img = Image.open("turn.png")
- pxl = img.load()
- time.sleep(0.25)
- zz=np.roll(zz,1)
- for x in range(len(xx)):
- zz[x,0]=pxl[ xx[x] , yy ][-1]
- plyr=np.array([0,0,0,0])
- while(True):
- for dt in range(10): # only updates jpgs every 10 steps
- img = ps.grab()
- #img = Image.open("turn.png")
- pxl = img.load()
- time.sleep(0.25)
- if isCiv(pxl):
- # if Civ isn't fullscreen, don't update player turns
- zz=np.roll(zz,1)
- for x in range(len(xx)):
- zz[x,0]=pxl[ xx[x] , yy ][-1]
- plyr[x]=np.mean(zz[x,:])
- whoseTurn(plyr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement