# 导入模块
import pygame
import random
# 初始化pygame
pygame.init()
# 设置窗口大小
screen = pygame.display.set_mode((800,600))
# 改变窗体的颜色
# 元组中三个值:红 绿 蓝 取值0-255
# screen.fill((0,255,0))
# 画圆形
# pygame.draw.circle(screen,(255,0,0),(100,100),100)
# pygame.draw.circle(screen,(0,0,255),(200,200),20)
# 渲染
# pygame.display.flip()
# 声明 x y
x = 50
y = 50
# 位置偏移
sx = random.randint(5,10)
sy = random.randint(5,10)
# 执行时间状态
running = True
while running:
screen.fill((178, 100, 120))
# 画圆
pygame.draw.circle(screen,(0,255,0),(x,y),30)
# 时间间隔
pygame.time.delay(50)
# 改变位置
x += sx
y += sy
# 判断边界
# 横向 x坐标
if x - 30 <= 0 or x + 30 >= screen.get_width():
sx = -sx
# 纵向 y坐标
if y -30 <= 0 or y +30 >= screen.get_height():
sy = -sy
# 渲染
pygame.display.flip()
# 点击关闭时候 执行对应的操作
for event in pygame.event.get():
# 右上角叉号的事件类型
if event.type == pygame.QUIT:
running = False
获取指定时间三天后的时间戳
import time
# a1 = "2018-01-01 14:00:21"
# # 先转换为时间数组
# timeArray = time.strptime(a1, "%Y-%m-%d %H:%M:%S")
#
# # 转换为时间戳
# timeStamp = int(time.mktime(timeArray))
# print(timeStamp)
#
# # 格式转换 - 转为 /
# a2 = "2018-01-04 14:00:21"
# # 先转换为时间数组,然后转换为其他格式
# timeArray = time.strptime(a2, "%Y/%m/%d %H:%M:%S")
# otherStyleTime = time.strftime("%Y/%m/%d %H:%M:%S", timeArray)
# print(otherStyleTime)
&
import time
def get_time(time_str,days,format_str):
time_tuple = time.strptime(time_str,format_str)
seconds = time.mktime(time_tuple)
times = seconds + (days)*24*3600
print(time.localtime(times))
return times
res = get_time('2018-01-01',-2,"%Y-%m-%d")
print(res)