turtle 画照片
2024-10-21 23:17:10
# -*- coding: utf-8 -*- import turtle as t
import cv2 def draw_img(img_path, scale=1):
"""
画图片里的内容
:param img_path: 图片路径
:param scale: 缩放比例,比如1,0.5,0.25
:return:
"""
t.getscreen().colormode(255)
img = cv2.imread(img_path)
img1 = img[::int(1/scale)] # 取图片一半(隔行取)的行数据
width = len(img1[0])/int(1/scale) # 取图片的宽度
height = len(img1) # 取图片的高度 t.setup(width=width+100, height=height+100) # 设置画布大小, 600, 370
t.pu()
t.goto(-width/2 + 10, height/2 - 10) # 移动到指定坐标的位置 -140,
t.pd()
t.tracer(3000) # 加快作图速度, 0 or False 时图形一次性画好 for k1, i in enumerate(img1):
for j in i[::int(1/scale)]:
t.pencolor((j[2], j[1], j[0])) # 设置画笔颜色
t.fd(1) # 沿着海龟的前方向运行1
t.pu() # 画笔抬起,不留下痕迹
t.goto(-width/2, height/2 -k1) # 移动画笔到下一行最左侧位置
t.pd() # 画笔落下,留下痕迹
t.done() if __name__ == '__main__':
path = r'./2.jpg'
draw_img(path, 0.5)
最新文章
- Mysql 主从热备份
- SVN使用教程
- Android 网络图片查看器
- IOS8下,百度地图无法定位解决办法
- drawer principle in Combinatorics
- Window nginx+tomcat+https部署方案 支持ios9
- Oracle 动态视图3 V$SESSION
- avconv转换视频
- jQuery Mobile 图标无法显示
- C# 多线程详解
- Java BufferedReader、InputStream简介
- js引用类型数组去重-对象标记法
- 二 Djano模型层之模型字段选项
- Activiti6-TaskService(学习笔记)重要
- rsync同步时,删除目标目录比源目录多余文件的方法(--delete)
- (1.4)mysql sql mode 设置与使用
- java 异步机制与同步机制的区别
- VS2008 试图运行未注册64位调试器组件
- Minicap使用分析
- Python3.x获取网页源码
热门文章
- react hooks组件父组件调用子组件方法
- Java——四种线程创建方式
- windows用curl报错
- Delphi 新语法:匿名函数
- MyBatisPlus 报MP_OPTLOCK_VERSION_ORIGINAL not found. Available parameters are错误
- [MySQL高级](一) EXPLAIN用法和结果分析
- Dell CS24-SC 服务器详情
- 大道至简读后感以及JAVA伪代码
- 有null值的子查询,子查询加排序,速度大幅提升
- SpringBoot配置阿里云https提示端口占用问题