pythonturtle颜色大全_Python:在Turtle中一次使用多种颜色

有人做过吗?在节省时间使用多种颜色.

我有一个颜色列表:

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-3-x,python-2-7,colors,python

来源: https://codeday.me/bug/20191121/2054368.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值