新玩法,远程打字让vector显示出来,并且可以用中文
vector吧
全部回复
仅看楼主
level 4
zy007yan 楼主


2020年04月05日 20点04分 1
level 1
远程打字怎么实现的?可以分享吗
2020年04月07日 13点04分 2
level 4
zy007yan 楼主
"""
import anki_vector
import sys
import time
from anki_vector.util import degrees
try:
from PIL import Image, ImageDraw, ImageFont
except ImportError:
sys.exit("Cannot import from PIL. Do `pip3 install --user Pillow` to install")
def make_text_image(text_to_draw, x, y, font=None):
'''Make a PIL.Image with the given text printed on it
Args:
text_to_draw (string): the text to draw to the image
x (int): x pixel location
y (int): y pixel location
font (PIL.ImageFont): the font to use
Returns:
:class:(`PIL.Image.Image`): a PIL image with the text drawn on it
'''
dimensions = (184, 96)
# make a blank image for the text, initialized to opaque black
text_image = Image.new(
'RGBA', dimensions, (0, 0, 0, 255))
# get a drawing context
dc = ImageDraw.Draw(text_image)
# draw the text
dc.text((x, y), text_to_draw, fill=(255, 255, 255, 255), font=font)
return text_image
# Get font file from computer (change directory as needed)
try:
font_file = ImageFont.truetype("arial.ttf", 20)
except IOError:
try:
font_file = ImageFont.truetype(
"/Users/zhangimac/Downloads/简启体.TTF", 20)
except IOError:
pass
# Set text to create image from here
text_to_draw = "大家好!我是vector,\n祝愿我们三口之家\n幸福,安康,和睦!\n---写于法国封城之日"
face_image = make_text_image(text_to_draw, 0, 0, font_file)
args = anki_vector.util.parse_command_args()
with anki_vector.Robot(args.serial) as robot:
# If necessary, Move Vector's Head and Lift to make it easy to see his face
robot.behavior.set_head_angle(degrees(50.0))
robot.behavior.set_lift_height(0.0)
# Convert the image to the format used by the Screen
print("Display image on Vector's face...")
screen_data = anki_vector.screen.convert_image_to_screen_data(
face_image)
robot.screen.set_screen_with_image_data(
screen_data, 20.0, interrupt_running=True)
time.sleep(20)
2020年04月08日 19点04分 3
level 4
zy007yan 楼主
新建一个txt文件,把程序代码复制,然后把这个文件拖进命令提示符,或mac的终端里,前提是你已经安装了sdk并登陆过,
2020年04月08日 19点04分 4
把txt文件扩展名改为.py
2020年04月08日 19点04分
那个字体文件需要你指定路径,在电脑里搜ttf就有一堆,把路径替换成这个
2020年04月08日 19点04分
sdk是在vector里安装吗
2020年04月14日 11点04分
在你的电脑上
2020年04月14日 12点04分
1