我正在尝试填充这些方块中的颜色:
现在 turtle 只填满这些方块的角落,而不是整个方块。
这是我的代码:
import turtle
import time
import random
print ("This program draws shapes based on the number you enter in a uniform pattern.")
num_str = input("Enter the side number of the shape you want to draw: ")
if num_str.isdigit():
squares = int(num_str)
angle = 180 - 180*(squares-2)/squares
turtle.up
x = 0
y = 0
turtle.setpos(x,y)
numshapes = 8
for x in range(numshapes):
turtle.color(random.random(),random.random(), random.random())
x += 5
y += 5
turtle.forward(x)
turtle.left(y)
for i in range(squares):
turtle.begin_fill()
turtle.down()
turtle.forward(40)
turtle.left(angle)
turtle.forward(40)
print (turtle.pos())
turtle.up()
turtle.end_fill()
time.sleep(11)
turtle.bye()
我试过在很多地方移动
turtle.begin_fill()
和 end_fill()
都没有成功……使用 Python 3.2.3,谢谢。 最佳答案
我还没有真正使用过 turtle ,但看起来这可能是你想要做的。如果我为这些调用假设了错误的功能,请纠正我:
turtle.begin_fill() # Begin the fill process.
turtle.down() # "Pen" down?
for i in range(squares): # For each edge of the shape
turtle.forward(40) # Move forward 40 units
turtle.left(angle) # Turn ready for the next edge
turtle.up() # Pen up
turtle.end_fill() # End fill.
关于python - 如何在 Turtle 中填充这些方块 - Python,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12453572/