turtle 画照片
# -*- 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)
turtle 画照片的更多相关文章
- python运用turtle 画出汉诺塔搬运过程
python运用turtle 画出汉诺塔搬运过程 1.打开 IDLE 点击File-New File 新建立一个py文件 2.向py文件中输入如下代码 import turtle class Stac ...
- python3 turtle 画国际象棋棋盘
python3 turtle 画国际象棋棋盘 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import turt ...
- day 03 turtle 画鹅
turtle 画鹅 import turtle t=turtle turtle.speed(10) t. setup(800,600) #画头 turtle.penup() turtle.goto(0 ...
- *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】
如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...
- 【Python】【demo实验29】【练习实例】【使用turtle画五角星】
原题: 使用turtle画五角星: 我的代码: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- from turtle impor ...
- 使用turtle画故宫(伍奇,侯俊豪小组)
这个代码主要有两个部分,第一部分是画出故宫,第二部分是用random函数随机画心,故宫部分设置多个函数和循环再进行颜色填充即可完成. 此处为视频链接 from turtle import* impor ...
- 用python turtle画玫瑰
1.turtle 库 2.画玫瑰的代码: import turtle turtle.penup() turtle.left() turtle.fd() turtle.pendown() turtle. ...
- Python之turtle画同心圆和棋盘
画饼图 import turtle t = turtle.Pen() for i in range(5): t.penup() t.goto(0, -i*30) t.pendown() t.circl ...
- 用python的turtle画分形树
由于分形树具有对称性,自相似性,所以我们可以用递归来完成绘制.只要确定开始树枝长.每层树枝的减短长度和树枝分叉的角度,我们就可以把分形树画出来啦!! 代码如下: # -*- coding: utf-8 ...
- python 用turtle 画小猪佩奇
from turtle import * def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 setheading(-30)#将乌龟 ...
随机推荐
- VUE3+VITE 常见问题解决
reactive解构最深的一层,失去响应性问题 pinia创建的store,使用结构失去响应性 reactive包裹后的对象 重新赋值失去响应性 无法动态引入图片 在computed中传参数 vue3 ...
- JS 根据base64获取文件宽高
const {width, height} = await this.getImgSize(base64) async getImgSize(base64) { const image = new I ...
- LeNet,AlexNet,VGG,GoogLeNet
卷积神经网络-LeNet 理解channel:卷积操作完成后输出的 out_channels ,取决于卷积核的数量.此时的 out_channels 也会作为下一次卷积时的卷积核的 in_channe ...
- PHY6230 高性价比低功耗高性能 集成32-bit MCU BLE5.2+2.4G芯片
PHY6230 是一款高性价比低功耗高性能Bluetooth LE 5.2系统级芯片,集成32-bit高性能低功耗MCU,16KB OTP,8KB Retention SRAM和64KB ROM,可选 ...
- svn 中如何checkout出单个文件
A 通过命令行操作 1.检出目录images svn co --depth=empty http://www.iusesvn.com/project1/images images_work_dir 这 ...
- Unity 动态加载图片出现红色问号
因为图片必须是RGB格式的才可以 ,Cao!!!
- k8s 基础
创建pod(kubectl create -f {podname} .yaml pod "{podname} " created -n {namespace}) cat name ...
- JS字符串拼接的方法及性能比较
一.+和+=str += "one" + "two";这段代码在运行过程中,会经历四个步骤:1.在内存中创建一个临时字符串2.将连接后的字符串"one ...
- Excel error - the macros in this project are disabled, please refer to the online help or documentation of the host application to determine how to enable macros.
alt+F11 进入vba界面,F5运行macro后报错. Sub 合并当前工作簿下的所有工作表() Application.ScreenUpdating = False For j = 1 To S ...
- crontab计划运行shell脚本,调用ncl执行失败
编写了bash脚本,调用ncl脚本绘图,在前台运行时候无误,但是加入crontab任务就是始终无法出图,并且无错误输出. 经过搜索,问题得到解决.是环境变量的问题.所有执行的命令,和文件都要指定完整的 ...