【问题标题】:How do I draw a circle looping around with a circle in the middle at the end using python turtle?如何使用 python turtle 绘制一个在中间有一个圆圈的圆圈?
【发布时间】:2013-12-02 13:26:38
【问题描述】:

形状应该像这张图片 Image of Circle Loop

这应该是一个简单的硬件分配,所以如果您使用任何高级数学或任何东西,您可能没有正确执行它。它应该只涉及简单的功能,如左、右、前进、上笔、下笔等。

我真的需要帮助来完成这个。这是我到目前为止的代码,但圆圈没有正确移动。

# Repeating Circle Loop

import turtle

turtle.colormode(255)

window = turtle.Screen()
window.title('Circle Loop')
window.bgcolor('black')

red, green, blue = 255, 255, 0

draw = turtle.Turtle()
draw.color(red, green, blue)

radius = 50

for i in range(12):
    draw.circle(radius)
    draw.penup()
    draw.setposition(i * - 10, 0)
    draw.left(30)
    draw.pendown()
    green = green - 20
    blue = blue + 20
    draw.color(red, green, blue)

window.mainloop()

【问题讨论】:

  • 告诉人们“这应该是一个简单的硬件作业,所以如果你们使用任何高级数学或任何东西,你可能做得不对。”,并没有邀请任何人实际回答.

标签: python loops geometry turtle-graphics


【解决方案1】:

编写一个画圆的子程序。然后,编写另一个画圆的子程序,以相反的方向弯曲,并调用第一个子程序以固定间隔围绕内圆画额外的圆。

【讨论】:

    【解决方案2】:

    试试这个循环:

    for i in range(12):
        draw.circle(radius)
        draw.penup()
        draw.left(180)
        draw.circle(radius,30)
        draw.right(180)
        draw.pendown()
    

    【讨论】:

      【解决方案3】:

      您可能对以下代码感兴趣:

      from math import sin, cos, pi
      from turtle import *
      
      tracer(2,1)
      
      def myCircle(x, y, r, c1, c2): # draw a circle with radius r in the point (x,y)
                  up(); goto(x+r, y) ; down()
                  color(c1, c2)
                  begin_fill()
                  for i in range(361):
                      a = x + r*cos(pi*i/180)
                      b = y + r*sin(pi*i/180)
                      goto(a, b)
                  end_fill()
      
      c1, c2 = 'red', 'blue'
      for i in range(5):
          myCircle(0, 0, 200-i*40,c1, c2 )
          c1, c2 = c2, c1
      

      【讨论】:

        猜你喜欢
        • 2018-12-15
        • 2020-01-02
        • 1970-01-01
        • 2012-11-12
        • 2018-10-18
        • 2012-08-16
        • 1970-01-01
        • 1970-01-01
        • 2013-09-20
        相关资源
        最近更新 更多