Skip to content

Instantly share code, notes, and snippets.

@YatinAdityaT
Created June 20, 2020 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YatinAdityaT/bb6e560ff135425fe776c4890c7412ad to your computer and use it in GitHub Desktop.
Save YatinAdityaT/bb6e560ff135425fe776c4890c7412ad to your computer and use it in GitHub Desktop.
start()
value = 40
start_time = time.time()
readings = []
offset = 28876
x_offset = 0
starttime = time.time()
img = Image.open(BytesIO(canvas.screenshot_as_png)).convert('RGB')
cropped = np.array(img.crop( ( x_n, y_n, x_,y_ ) ) )
while time.time() - start_time < 3:
readings.append(np.sum(np.array(cropped)))
threshold = int(np.mean(readings)) - offset
print('threshold',threshold)
while True:
time_passed = time.time()
if int(time_passed - starttime)%2 == 0:
print(x_offset)
x_offset+=0.01
img = Image.open(BytesIO(canvas.screenshot_as_png)).convert('RGB')
cropped = np.array(img.crop( ( x_n+int(x_offset), y_n, x_+int(x_offset) ,y_) ) )
restart_button = img.crop(( x_ref_top_left, y_ref_top_left, x_ref_bottom_rigth,
y_ref_bottom_rigth ))
img = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2GRAY)
img = cv2.bitwise_not(img)
img[img==8]=0
cv2.rectangle(img, (x_n+int(x_offset), y_n), (x_+int(x_offset),y_) , (255), 2)
cv2.imshow('Test2', img)
cv2.waitKey(1)
roi = img[y1:y2, x1:x2]
if np.sum(cropped) < threshold:
main_body.send_keys(Keys.SPACE)
# print('jump')
if np.sum(restart_button) == 431949:
# print('restart')
pause()
# elif np.sum(restart_button) < 900000:
# print(np.sum(restart_button))
# print('duck!')
# duck()
if keyboard.is_pressed('alt'):
pause()
cv2.destroyAllWindows()
break
if keyboard.is_pressed('p'):
pause()
cv2.imwrite('test.png',img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment