尝试调整给定圆半径的位置坐标(Python)

尝试调整给定圆半径的位置坐标(Python),python,turtle-graphics,Python,Turtle Graphics,我正在键入一个程序,根据输入(半径)绘制奥运五环。我的问题是,给定输入,如何获得相应的位置坐标(x,y) 我给他们的默认半径是70。输入70 这是我的密码: radius =input('Enter the radius of your circle: ') #Asking for radius of the circle r = float(radius) import turtle t = turtle.Turtle t = turtle.Turtle(shape="turtle") #

我正在键入一个程序,根据输入(半径)绘制奥运五环。我的问题是,给定输入,如何获得相应的位置坐标(x,y)

我给他们的默认半径是70。输入70

这是我的密码:

radius =input('Enter the radius of your circle: ') #Asking for radius of the circle
r = float(radius)

import turtle
t = turtle.Turtle
t = turtle.Turtle(shape="turtle")

#Circle one
t.pensize(10)
t.penup()
t.goto(0,0)
t.pendown()
t.color("green") #Adds Green
t.circle(r)
#Circle two
t.penup()
t.setposition(-160,0)
t.pendown()
t.color("yellow") #Adds yellow
t.circle(r)
#Circle three
t.penup()
t.setposition(110,60)
t.pendown()
t.color("red") #Adds red
t.circle(r)
#Circle four
t.penup()
t.setposition(-70,60)
t.pendown()
t.color("black") #Adds black
t.circle(r)
#Circle five
t.penup()
t.setposition(-240,60)
t.pendown()
t.color("blue") #Adds blue
t.circle(r)

相应地缩放坐标如何

代码-

radius =input('Enter the radius of your circle: ') #Asking for radius of the circle
r = float(radius)

x = r / 70

import turtle
t = turtle.Turtle
t = turtle.Turtle(shape="turtle")

#Circle one
t.pensize(10)
t.penup()
t.goto(0,0)
t.pendown()
t.color("green") #Adds Green
t.circle(r)
#Circle two
t.penup()
t.setposition(-160 * x,0)
t.pendown()
t.color("yellow") #Adds yellow
t.circle(r)
#Circle three
t.penup()
t.setposition(110 * x,60 * x)
t.pendown()
t.color("red") #Adds red
t.circle(r)
#Circle four
t.penup()
t.setposition(-70 * x,60 * x)
t.pendown()
t.color("black") #Adds black
t.circle(r)
#Circle five
t.penup()
t.setposition(-240 * x,60 * x)
t.pendown()
t.color("blue") #Adds blue
t.circle(r)

您还可以根据输入缩放养老金。

您需要的是一个乘法器。但是,您的代码确实是重复的,当您有类似的东西时,您希望使用一个循环而不是一堆命令,这将使您的代码更易于维护,更具可读性。这就是我的方法:

radius =input('Enter the radius of your circle: ') #Asking for radius of the 

circle
r = float(radius)

import turtle
t = turtle.Turtle(shape="turtle")

m = r/70

colors = ["green", "yellow", "red", "black", "blue"]
coordinates = [(1,1), (-160,0), (110,60), (-70,60), (-240,60)]

t.pensize(10)

for i in range(len(coordinates)):
    t.penup()
    t.goto(coordinates[i][0]*m, coordinates[i][1]*m)
    t.pendown()
    t.color(colors[i])
    t.circle(r)

将点标准化并乘以常数会更好、更灵活。

谢谢大家的帮助。我现在明白怎么做了。