想到十年前刚用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.图片就是普通的截图。