Goo*_*ose 3 python turtle-graphics
我想填补这些方块的颜色:

现在乌龟只填充这些正方形的角落,而不是整个正方形.
这是我的代码:
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()
Run Code Online (Sandbox Code Playgroud)
我试着走动turtle.begin_fill(),并end_fill()没有运气在许多地方...使用Python 3.2.3,谢谢.
我没有真正使用龟,但看起来这可能是你想要做的.如果我为这些调用假设了错误的功能,请纠正我:
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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69002 次 |
| 最近记录: |