Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-- include('examples/showgrabbox.py')--#
- import pyscreenshot as ImageGrab
- from time import sleep
- #------------------------------------------------
- #please change
- #User must change these varibles for specific screen size.
- #Current values are set for 1920x1080 screens
- x_pad = 556
- y_pad = 352
- x_width = 1348
- y_length = 944
- #starting square for bottom left cell
- x_start = 279
- y_start = 542
- #------------------------------------------------
- gameMatrix = [[0 for x in range(10)] for y in range(20)] #matrix for game grid
- def getGameState():
- pix = im.load()
- for y in range (0,20):
- row_block_count = 0 #reset after every row
- #----------------------------------------------------------------------#
- #row scanning sub method
- for x in range (0,10):
- colour = pix[(x_start + (x * 26)), (y_start - (y * 26))] #gets the rgb value of cell every cell (left to right), (bottom to top)
- #print (colour)
- if not(colour[0] < 10 and colour[1] < 10 and colour [2] < 10): #if the cell isn't empty
- gameMatrix[y][x] = 1 #add a 1 to that cell position
- row_block_count
- #check if there is a block in this spot
- #----------------------------------------------------------------------#
- if (x == 0):
- return()
- #break scanning if whole row is empty to save time
- return()
- #once done
- if __name__ == "__main__":
- # part of the screen
- sleep(5)
- #im=ImageGrab.grab(bbox=(10,10,510,510)) # X1,Y1,X2,Y2
- im=ImageGrab.grab(bbox =(x_pad,y_pad,x_width,y_length))
- #im.show()
- im.save("GAMESCREEN.png")
- getGameState()
- #-------------------------------------------------
- #code for testing. Check with screenshot to see if the code is working correctly.
- for y in range (19,-1,-1):
- print ("\n")
- for x in range (0,10):
- print(gameMatrix[y][x], end='')
- #-------------------------------------------------
- #-#
Advertisement
Add Comment
Please, Sign In to add comment