python - 尝试根据我的圆圈半径调整位置坐标(Python)

标签 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")

#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/

相关文章:

python - 如何将图像添加到 turtle 屏幕而不会出错?

python - 用python循环绘制棋盘

python - 使用 Whoosh 搜索和索引带连字符的单词

python - 将模块方法分配给类变量或实例变量

python - 如何在 kivy android 和 ios 中实现支付网关和钱包等概念

python - 如果所有值都在同一列中,如何从 csv 文件读取数据?

javascript - 以与 Google bot 类似的方式抓取网站 html 和 javascript

python - 强化算法似乎可以学习,但脚本卡住并且代理没有重置

python - 如何创建多个处于不同位置的 turtle ?

python - Python turtle 图形中的连续屏幕点击事件