Reputation: 109
Has anyone ever done this? Using multiple colors at the save time.
I have a list of colors:
colors = ["#880000",\
"#884400",\
"#888800",\
"#008800",\
"#008888",\
"#000088",\
"#440088",\
"#880088"]
My aim is to take that list of colors and pass it to turtle so it can draw a colorful circle in one line of turn.
my functions is as follows:
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
The problem with the above function is that it draws using only one color instead of little arcs of different colors from the list. can anyone help me solve this or point to what I'm doing wrong?
the function is called like drawImage(colors,200)
this will draw a colorful circle with a radius of 200
Upvotes: 3
Views: 5788
Reputation: 142671
Do you mean this circle ?
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)
There will be more work with filled circle because you have to draw filled "triangle" (arc) one by one.
EDIT:
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)
Upvotes: 3