# 安装PyGame:pip install pygame
import pygame
#导入pygame库
from pygame.locals import *
#导入一些常用的函数和常量
from sys import exit
#向sys模块借一个exit函数用来退出程序
import pygame
import os
import time
import math
pygame.init()
#初始化pygame,为使用硬件做准备
screen = pygame.display.set_mode((360, 640), 0, 32)
#创建了一个窗口
pygame.display.set_caption("Hello, World!")
#设置窗口标题
bg_image = "yu.png"#"bg""background"背景的缩写获取图片途径
# 加载手机界面
os.system('adb shell screencap -p /sdcard/yu.png')#录屏
os.system('adb pull /sdcard/yu.png')
bg = pygame.image.load(bg_image).convert()#影像加载转换#加载并转换图像
bg = pygame.transform.smoothscale(bg, (360, 640))
jus=[]
while True:
#游戏主循环
for event in pygame.event.get():
if event.type == QUIT:
#接收到退出事件后退出程序
exit()
elif event.type == MOUSEBUTTONUP:
jus.append(event.pos)
print(jus)
if (len(jus)==2):
s = int(math.sqrt((jus[0][0]-jus[1][0])**2 +
(jus[0][1]-jus[1][1])**2) * 4.176)
os.system("adb shell input swipe 50 50 50 50 "+str(s))
# 延迟一秒钟
time.sleep(1)
# 加载手机界面
os.system('adb shell screencap -p /sdcard/yu.png')
os.system('adb pull /sdcard/yu.png')
bg = pygame.image.load(bg_image).convert()#影像加载转换#加载并转换图像
bg = pygame.transform.smoothscale(bg, (360, 640))
jus.clear()
screen.blit(bg, (0,0))
#将背景图画上去
pygame.display.update()
#刷新一下画面