python turtle库画图(有源码) 您所在的位置:网站首页 用scratch软件制作动漫的奥运会 python turtle库画图(有源码)

python turtle库画图(有源码)

2023-12-24 20:14| 来源: 网络整理| 查看: 265

第1种: 在此之前你需要一张图片,命名为img.png(当然你也可以改代码里面的图片路径),图片和python代码在同一个目录下(或者代码中的照片路径用绝对路径)。

完整代码1:

import turtle as t import cv2 t.getscreen().colormode(255) img1 = cv2.imread('img.png')[0: -2: 2] width = len(img1[0]) height = len(img1) t.setup(width=width / 2 + 100, height=height + 100) t.pu() t.goto(-width / 4 + 10, height / 2 - 10) t.pd() t.tracer(2000) for k1, i in enumerate(img1): for j in i[::2]: t.pencolor((j[0], j[1], j[2])) t.fd(1) t.pu() t.goto(-width / 4 + 10, height / 2 - 10 - k1 - 1) t.pd() t.done()

在这里插入图片描述 如果出现这个报错,请安装opencv-python库。 可以在terminal输入下面代码,也可以用pycharm直接安装。

pip install opencv-python


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有