Python+Turtle绘制航海王草帽路飞详解
作者:挣扎的蓝藻 发布时间:2023-12-31 18:08:09
标签:Python,Turtle
一、程序运行
1.效果展示 - 轮廓描绘
看轮廓描绘效果:
2.效果展示 - 颜色填充
衣服和裤子颜色填充效果:
二、实现过程
1.绘图数据下载
获取地址
内容预览:
2.海龟绘图配置项
降低刷新率可提升绘制速度,值越大刷新频率越低,速度越快
t.tracer(5000)
def set_trutle():
'''
作用:海龟绘图配置项
参数:无
返回:无
'''
# 默认颜色区间是[0,1],切换为[0,255]
t.Screen().colormode(255)
# 设置起始大小
t.setup(width=x, height=y)
# 调整坐标,
t.setworldcoordinates(0,y,x,0)
t.pen()
# 设置绘制速度,0为最快
t.speed(0)
# 禁用延迟提升速度
t.delay(0)
# 提升速度,值越大越快
t.tracer(5000)
# 设置默认画笔颜色为白色
t.pencolor((255,255,255))
# 抬起画笔
t.penup()
3.轮廓绘制
通过下落画笔 t.pendown()
和抬起画笔 t.penup()
来避免连线问题。
def draw_lufei_outline():
'''
作用:绘制路飞轮廓
参数:无
返回:无
'''
# 数据文件读取
f=open("lufei.txt","r")
bigmom_date = f.read().split(" ")
for i in bigmom_date:
try:
# 数据分离与转化
j = i.split("_")
x1 = round(float(j[0]))
y1 = round(float(j[1]))
color = j[2][1:-1].split(",")
color[0]=int(color[0])
color[1]=int(color[1])
color[2]=int(color[2])
if((color[0]*0.299 + color[1]*0.587 + color[2]*0.114)>50):
color = (255,255,255);
# 下落画笔
t.pendown()
# 解决图像只绘制一半的问题
t.sety(y1)
# 轨迹追踪与绘制
t.goto(x1, y1)
t.color(color)
# 抬起画笔
t.penup()
except Exception as e:
print()
f.close()
print("轮廓绘制完成")
效果图演示:
4.颜色填充:衣服、裤子
绘制衣服、裤子的红色和蓝色。
def draw_lufei_tintage1():
'''
作用:路飞颜色填充:衣服、帽子
参数:无
返回:无
'''
# 数据文件读取
f=open("lufei.txt","r")
bigmom_date = f.read().split(" ")
for i in bigmom_date:
try:
# 数据分离与转化
j = i.split("_")
x1 = int(j[0])
y1 = int(j[1])
color = j[2][1:-1].split(",")
color[0]=int(color[0])
color[1]=int(color[1])
color[2]=int(color[2])
if((color[0]*0.299 + color[1]*0.587 + color[2]*0.114)>150):
color = (255,255,255);
# 下落画笔
t.pendown()
# 解决图像只绘制一半的问题
t.sety(y1)
# 轨迹追踪与绘制
t.goto(x1, y1)
t.color(color)
# 抬起画笔
t.penup()
except Exception as e:
print()
f.close()
print("上色完成")
效果图演示:
5.颜色填充:草帽、腰带
绘制草帽、腰带的黄色。
def draw_lufei_tintage2():
'''
作用:路飞颜色填充:草帽、腰带
参数:无
返回:无
'''
# 数据文件读取
f=open("lufei.txt","r")
bigmom_date = f.read().split(" ")
for i in bigmom_date:
try:
# 数据分离与转化
j = i.split("_")
x1 = int(j[0])
y1 = int(j[1])
color = j[2][1:-1].split(",")
color[0]=int(color[0])
color[1]=int(color[1])
color[2]=int(color[2])
if((color[0]*0.299 + color[1]*0.587 + color[2]*0.114)>215):
color = (255,255,255);
# 下落画笔
t.pendown()
# 解决图像只绘制一半的问题
t.sety(y1)
# 轨迹追踪与绘制
t.goto(x1, y1)
t.color(color)
# 抬起画笔
t.penup()
except Exception as e:
print()
f.close()
print("上色完成")
效果图演示:
6.完整源码
# -*- coding:utf-8 -*-
# 2022-3-9
# 作者:小蓝枣
# 图像绘制:路飞
import turtle as t
import time
x = 224
y = 345
def set_trutle():
'''
作用:海龟绘图配置项
参数:无
返回:无
'''
# 默认颜色区间是[0,1],切换为[0,255]
t.Screen().colormode(255)
# 设置起始大小
t.setup(width=x, height=y)
# 调整坐标,
t.setworldcoordinates(0,y,x,0)
t.pen()
# 设置绘制速度,0为最快
t.speed(0)
# 禁用延迟提升速度
t.delay(0)
# 提升速度,值越大越快
t.tracer(5000)
# 设置默认画笔颜色为白色
t.pencolor((255,255,255))
# 抬起画笔
t.penup()
def draw_lufei_outline():
'''
作用:绘制路飞轮廓
参数:无
返回:无
'''
# 数据文件读取
f=open("lufei.txt","r")
bigmom_date = f.read().split(" ")
for i in bigmom_date:
try:
# 数据分离与转化
j = i.split("_")
x1 = round(float(j[0]))
y1 = round(float(j[1]))
color = j[2][1:-1].split(",")
color[0]=int(color[0])
color[1]=int(color[1])
color[2]=int(color[2])
if((color[0]*0.299 + color[1]*0.587 + color[2]*0.114)>50):
color = (255,255,255);
# 下落画笔
t.pendown()
# 解决图像只绘制一半的问题
t.sety(y1)
# 轨迹追踪与绘制
t.goto(x1, y1)
t.color(color)
# 抬起画笔
t.penup()
except Exception as e:
print()
f.close()
print("轮廓绘制完成")
def draw_lufei_tintage1():
'''
作用:路飞颜色填充:衣服、帽子
参数:无
返回:无
'''
# 数据文件读取
f=open("lufei.txt","r")
bigmom_date = f.read().split(" ")
for i in bigmom_date:
try:
# 数据分离与转化
j = i.split("_")
x1 = int(j[0])
y1 = int(j[1])
color = j[2][1:-1].split(",")
color[0]=int(color[0])
color[1]=int(color[1])
color[2]=int(color[2])
if((color[0]*0.299 + color[1]*0.587 + color[2]*0.114)>150):
color = (255,255,255);
# 下落画笔
t.pendown()
# 解决图像只绘制一半的问题
t.sety(y1)
# 轨迹追踪与绘制
t.goto(x1, y1)
t.color(color)
# 抬起画笔
t.penup()
except Exception as e:
print()
f.close()
print("上色完成")
def draw_lufei_tintage2():
'''
作用:路飞颜色填充:草帽、腰带
参数:无
返回:无
'''
# 数据文件读取
f=open("lufei.txt","r")
bigmom_date = f.read().split(" ")
for i in bigmom_date:
try:
# 数据分离与转化
j = i.split("_")
x1 = int(j[0])
y1 = int(j[1])
color = j[2][1:-1].split(",")
color[0]=int(color[0])
color[1]=int(color[1])
color[2]=int(color[2])
if((color[0]*0.299 + color[1]*0.587 + color[2]*0.114)>215):
color = (255,255,255);
# 下落画笔
t.pendown()
# 解决图像只绘制一半的问题
t.sety(y1)
# 轨迹追踪与绘制
t.goto(x1, y1)
t.color(color)
# 抬起画笔
t.penup()
except Exception as e:
print()
f.close()
print("上色完成")
set_trutle()
draw_lufei_outline()
draw_lufei_tintage1()
draw_lufei_tintage2()
time.sleep(10000)
来源:https://blog.csdn.net/qq_38161040/article/details/123391039


猜你喜欢
- 理解property和attribute这个要看具体的语境了。不过我们可以从词源的角度来区分一下这两者:property形容词propert
- 本文实例为大家分享了Python Pygame实现俄罗斯方块的具体代码,供大家参考,具体内容如下源码:# coding : utf-8#:
- 目录概述语法定义接口实现接口空接口接口的组合总结概述Go 语言中的接口就是方法签名的集合,接口只有声明,没有实现,不包含变量。语法定义接口t
- 最近工作中写了几个存储过程,需要向存储过程中传递字符串,因为SQL Server 2000中没有内置类似于 split 的函数,只好自己处理
- flask中的sqlalchemy 相比于sqlalchemy封装的更加彻底一些 , 在一些方法上更简单首先import类库:在CODE上查
- 写在前面因为暂时还没有想好做什么具体的某个项目来提升对python的理解,所以就自己想着做一下小玩意来加强一下自己对一些库和方法的理解分析1
- 1. test.txt文件,数据以逗号分割,第一个数据为x坐标,第二个为y坐标,数据如下:1.1,22.1,23.1,34.1,540,38
- 1.资源下载官网下载地址:https://dev.mysql.com/downloads/mysql/2.软件解压 2.1选择位置
- 本文实例讲述了Python实现处理管道的方法。分享给大家供大家参考。具体分析如下:Linux下的可以施展的最炫的魔法是什么?相信不同的人说法
- 切片:方便截取list、tuple、字符串部分索引的内容正序切片语法:dlist = doList[0:3]表示,从索引0开始取,直到索引3
- 去过新浪或者搜狐吗?虽然我们都不愿意看广告,但是它们做广告的技术我们却应该学到手,这不,又一种很流行的做法儿,做成那种两边对称的对联式的广告
- 本文实例讲述了Zend Framework生成验证码并实现验证码验证功能的方法。分享给大家供大家参考,具体如下:今天讲述如何在留言本中实现验
- 提高SQL执行效率的几点建议:◆尽量不要在where中包含子查询;关于时间的查询,尽量不要写成:where to_char(dif_date
- MySQL 表别名(Alias)SQL 表别名在 SQL 语句中,可以为表名称及字段(列)名称指定别名(Alias),别名是 SQL 标准语
- 从一个 Demo 入手为了快速进入状态,我们先搞一个 Demo,当然这个 Demo 是参考 Go 源码 src/net/rpc/s
- 在我们使用log模块输出日志时,经常会遇到log输出重复的问题,如下:先来看这个文件log.py的代码:代码示例:''
- 操作系统 : Windows 10_x64 [版本 10.0.19042.685]pjsip版本 : 2.10pjsip官网:https:/
- 最近需要统计一下项目中代码的总行数,写了一个Python小程序,不得不说Python是多么的简洁,如果用Java写至少是现在代码的2倍。[c
- 不过由于手机的参数多,且不同的手机其参数差异大,所以参数表结构通常是纵表(一个参数是一行),而不是横表(一个参数是一列),此时使用若干参数来
- 这篇文章主要介绍了python定义类self用法实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的