Python:在Turtle中一次使用多种颜色
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python:在Turtle中一次使用多种颜色,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1651字,纯文字阅读大概需要3分钟。
内容图文
![Python:在Turtle中一次使用多种颜色](/upload/InfoBanner/zyjiaocheng/660/756cb49bdd074b06bbefd133870f6a0a.jpg)
有人做过吗?在节省时间使用多种颜色.
我有一个颜色列表:
colors = ["#880000", "#884400", "#888800", "#008800", "#008888", "#000088", "#440088", "#880088"]
我的目标是获取该颜色列表并将其传递给乌龟,以便它可以在一行中画出一个彩色圆圈.
我的功能如下:
def drawImage(colorList, radius):
for color in colorList:
turtle.color(color)
turtle.penup()
turtle.setpos(0, -radius)
xpos=turtle.xcor()
ypos=turtle.ycor()
turtle.begin_fill()
turtle.pendown()
turtle.home()
turtle.setpos(xpos,ypos)
turtle.circle(radius)
turtle.end_fill()
turtle.color('black')
turtle.width(2)
turtle.circle(radius)
return
上述功能的问题在于,它仅使用一种颜色绘制,而不使用列表中不同颜色的小圆弧.谁能帮助我解决这个问题或指出我做错了什么?
该函数的调用方式类似于drawImage(colors,200),它将绘制一个半径为200的彩色圆圈
解决方法:
你是说这个圈子吗?
import turtle
colors = [
"#880000",
"#884400",
"#888800",
"#008800",
"#008888",
"#000088",
"#440088",
"#880088"
]
#--------------------
#turtle.reset()
angle = 360/len(colors)
turtle.width(10)
for color in colors:
turtle.color(color)
turtle.circle(100, angle)
实心圆将有更多工作,因为您必须一一绘制实心“三角形”(弧).
编辑:
import turtle
colors = [
"#880000",
"#884400",
"#888800",
"#008800",
"#008888",
"#000088",
"#440088",
"#880088"
]
#--------------------
def filled_arc(radius, angle, color):
turtle.color(color)
turtle.begin_fill()
turtle.forward(radius)
turtle.left(90)
turtle.circle(radius, angle)
turtle.left(90)
turtle.forward(radius)
turtle.end_fill()
turtle.left(180-angle)
#--------------------
angle = 360/len(colors)
for color in colors:
filled_arc(100, angle, color)
turtle.left(angle)
内容总结
以上是互联网集市为您收集整理的Python:在Turtle中一次使用多种颜色全部内容,希望文章能够帮你解决Python:在Turtle中一次使用多种颜色所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。