python笔记-2020/09/08下午-案例

# 导入模块
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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值