这篇“怎么用Python+Turtle绘制航海王草帽路飞”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“怎么用Python+Turtle绘制航海王草帽路飞”文章吧。
看轮廓描绘效果:
衣服和裤子颜色填充效果:
获取地址
内容预览:
降低刷新率可提升绘制速度,值越大刷新频率越低,速度越快
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()
通过下落画笔 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("轮廓绘制完成")
效果图演示:
绘制衣服、裤子的红色和蓝色。
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("上色完成")
效果图演示:
# -*- 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)
以上就是关于“怎么用Python+Turtle绘制航海王草帽路飞”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。