cozmo玩耍记录2-倒计时整蛊

想到十年前刚用qq的时候有个倒计时表情包            有个惊喜!-10-9-8-7-6-5-4-3-2-1-0-哈哈什么都没有!.gif



import os
import sys
import time

try:
    from PIL import Image
except ImportError:
    sys.exit("Cannot import from PIL: Do `pip3 install --user Pillow` to install")

import cozmo


def get_in_position(robot: cozmo.robot.Robot):
    '''If necessary, Move Cozmo's Head and Lift to make it easy to see Cozmo's face'''
    if (robot.lift_height.distance_mm > 45) or (robot.head_angle.degrees < 40):
        with robot.perform_off_charger():
            lift_action = robot.set_lift_height(0.0, in_parallel=True)
            head_action = robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE,
                                               in_parallel=True)
            lift_action.wait_for_completed()
            head_action.wait_for_completed()


def cozmo_program(robot: cozmo.robot.Robot):
    current_directory = os.path.dirname(os.path.realpath(__file__))
    get_in_position(robot)
    surprise_png = os.path.join(current_directory, "..", "..", "face_images", "surprise.png")
    five_png = os.path.join(current_directory, "..", "..", "face_images", "5.png")
    four_png = os.path.join(current_directory, "..", "..", "face_images", "4.png")
    three_png = os.path.join(current_directory, "..", "..", "face_images", "3.png")
    two_png = os.path.join(current_directory, "..", "..", "face_images", "2.png")
    one_png = os.path.join(current_directory, "..", "..", "face_images", "1.png")
    zero_png = os.path.join(current_directory, "..", "..", "face_images", "0.png")
    none_png = os.path.join(current_directory, "..", "..", "face_images", "none.png")

    # load some images and convert them for display cozmo's face
    image_settings = [(surprise_png, Image.BICUBIC),
                      (five_png, Image.BICUBIC),
                      (four_png, Image.BICUBIC),
                      (three_png, Image.BICUBIC),
                      (two_png, Image.BICUBIC),
                      (one_png, Image.BICUBIC),
                      (zero_png, Image.BICUBIC),
                      (none_png, Image.NEAREST)] 
    face_images = []
    for image_name, resampling_mode in image_settings:
        image = Image.open(image_name)

        # resize to fit on Cozmo's face screen
        resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)

        # convert the image to the format used by the oled screen
        face_image = cozmo.oled_face.convert_image_to_screen_data(resized_image,
                                                                 invert_image=True)
        face_images.append(face_image)

    num_loops = 1
    duration_s = 1.0

    print("Press CTRL-C to quit (or wait %s seconds to complete)" % int(num_loops*duration_s) )

    for _ in range(num_loops):
        for image in face_images:
            robot.display_oled_face_image(image, duration_s * 1000.0)
            time.sleep(duration_s)


cozmo.robot.Robot.drive_off_charger_on_connect = False

cozmo.run_program(cozmo_program)

ps.图片就是普通的截图。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangjiali12011

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值