我制作了一个类似头发的代码,即使形状的两端相遇,颜色也不能正确填充。 this is what I tried to imitate和 this is what I got, which is pretty ambarassing 我不知道如何绘制我想要的弧线,所以我只用半圈填充它们。这是我的代码:
from turtle import*
myvarhead=200
def hair():
rad1=(int(myvarhead)/7*4)
color('black')
begin_fill()
#left side
left(90)
circle(rad1,180)
right(120)
forward(rad1/10)
left(150)
forward((rad1/10)*7)
left(30)
circle(rad1/4,160)
circle(-rad1/4,120)
right(10)
forward((rad1/10)*3)
#going back
right(180)
forward(rad1/10*3)
left(10)
circle(rad1/4,120)
circle(-rad1/4,160)
right(30)
forward(rad1/10*7)
right(150)
forward(rad1/10)
left(120)
circle(-rad1,180)
#right side
left(120)
forward(rad1/10)
right(150)
forward(rad1/10*7)
right(30)
circle(-rad1/4,160)
circle(rad1/4,120)
left(10)
forward(rad1/10*3)
right(180)
end_fill()
hair()
right(90)
#forward(100)
答案 0 :(得分:0)
一种方法是不回溯你的多边形,而只是继续前进直到你完成/关闭它:
from turtle import *
def hair():
radius = (int(my_var_head) / 7 * 4)
color('black')
begin_fill()
# top & left side
left(90)
circle(radius, 180)
right(120)
forward(radius / 10)
left(150)
forward((radius / 10) * 7)
left(30)
circle(radius / 4, 160)
circle(-radius / 4, 120)
right(10)
forward((radius / 10) * 3)
# right side
forward((radius / 10) * 3)
right(10)
circle(-radius / 4, 120)
circle(radius / 4, 160)
left(30)
forward((radius / 10) * 7)
left(150)
forward(radius / 10)
end_fill()
my_var_head = 200
hair()
hideturtle()
done()