Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. from PIL import Image
  2. import pyscreenshot as ps
  3. import numpy as np
  4. import time
  5.  
  6. img_path='./'
  7. #img_path='/var/www/html/imgs/'
  8. playerNames=['rocapp','kevin1','blink','kevin0']
  9. topThresh=200
  10. botThresh=50
  11. yy=712
  12. xx=[447,479,511,543]
  13. Civ={'r':{'crd':[743,361],'clr':(201, 13, 7)},
  14. 'd':{'crd':[470,10], 'clr':(0, 0, 0)},
  15. 'w':{'crd':[643,743],'clr':(235, 237, 177)} }
  16. def isCiv(pxl):
  17. for k in Civ.keys():
  18. p0=Civ[k]['crd'][0]
  19. p1=Civ[k]['crd'][1]
  20. c=Civ[k]['clr']
  21. clr = pxl[ p0,p1 ]
  22. if clr[0]==c[0] and clr[1]==c[1] and clr[2]==c[2]:
  23. return(True)
  24. else:
  25. return(False)
  26.  
  27. def saveSwatch(clr,pname):
  28. swch = Image.new('RGB',(18,18),clr)
  29. swch.save(img_path+pname+'.jpg')
  30.  
  31. def whoseTurn(plyr):
  32. turn=[0]*4
  33. for p in range(len(plyr)):
  34. if plyr[p] < topThresh and plyr[p] > botThresh:
  35. turn[p]=1
  36. if np.sum(turn)==1:
  37. for p in range(len(plyr)):
  38. if turn[p]==1:
  39. saveSwatch('green',playerNames[p])
  40. else:
  41. saveSwatch('red',playerNames[p])
  42. else:
  43. for p in range(len(plyr)):
  44. saveSwatch('yellow',playerNames[p])
  45.  
  46. ln=100
  47. zz = np.zeros((4,ln))
  48. # initialize zz with real data; takes a minute,
  49. # but doesn't check if civ is fullscreen <lazy>
  50. for j in range(ln):
  51. img = ps.grab()
  52. #img = Image.open("turn.png")
  53. pxl = img.load()
  54. time.sleep(0.25)
  55. zz=np.roll(zz,1)
  56. for x in range(len(xx)):
  57. zz[x,0]=pxl[ xx[x] , yy ][-1]
  58.  
  59. plyr=np.array([0,0,0,0])
  60. while(True):
  61. for dt in range(10): # only updates jpgs every 10 steps
  62. img = ps.grab()
  63. #img = Image.open("turn.png")
  64. pxl = img.load()
  65. time.sleep(0.25)
  66. if isCiv(pxl):
  67. # if Civ isn't fullscreen, don't update player turns
  68. zz=np.roll(zz,1)
  69. for x in range(len(xx)):
  70. zz[x,0]=pxl[ xx[x] , yy ][-1]
  71. plyr[x]=np.mean(zz[x,:])
  72. whoseTurn(plyr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement