我正在输入一个根据输入(半径)绘制奥运五环的程序。我的问题是,在给定输入的情况下,我如何获得相应缩放的位置坐标 (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)
您还可以根据输入缩放笔的大小。
关于python - 尝试根据我的圆圈半径调整位置坐标(Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37354203/