如何创建多个50便士硬币
如何在不重叠或不互动的页面中创建单独的硬币。下面的代码显示了重叠的硬币,如果数字大于2。
import turtle
tegan = turtle.Turtle()
turtle.fillcolor('grey')
turtle.begin_fill()
numbers = int(input("How many 50 pence coins you have: "))
print(numbers)
length = 100
degrees = 51.42857
angle = 40
def draw_heptagon(tegan, length, numbers, angle):
for i in range(numbers):
for x in range(7):
turtle.forward(length)
turtle.left(degrees)
turtle.right(angle)
draw_heptagon(tegan, length, numbers, angle)
turtle.end_fill()
turtle.done()
How can I create separate coins in a page that are not overlapping or not touching each other. The code below shows overlapping coins if the number is greater than 2.
import turtle
tegan = turtle.Turtle()
turtle.fillcolor('grey')
turtle.begin_fill()
numbers = int(input("How many 50 pence coins you have: "))
print(numbers)
length = 100
degrees = 51.42857
angle = 40
def draw_heptagon(tegan, length, numbers, angle):
for i in range(numbers):
for x in range(7):
turtle.forward(length)
turtle.left(degrees)
turtle.right(angle)
draw_heptagon(tegan, length, numbers, angle)
turtle.end_fill()
turtle.done()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您可以完善的大概方法。我们将跟踪我们绘制的随机放置的七琴的中心。我们将它们视为圆圈,以绘制和检查它们之间的距离:
这做了您所描述的,但是七个人实际上可能比圆圈更接近(窗口中更多),因此您需要修改测试,以及您在
位置
中存储的哪些信息,如果要更紧:< img src =“ https://i.sstatic.net/tkmgj.png” alt =“在此处输入图像说明”>
Here's an approximate approach that you can refine. We'll keep track of the centers of the randomly placed heptagons we draw. We'll treat them as circles for purposes of drawing and checking the distances between them:
This does what you describe but the heptagons could actually be closer (fit more of them in the window) than circles, so you need to modify the test, and what information you store in
positions
, if you want to pack them tighter: