私は本当にタスクによって盗聴されています: ユーザ入力の半径r、その後亀は半径が0Pythonのカメ同心円
答えて
まず、36面/セグメントの正多角形として円を近似しましょう。 半径がrのこの形状を描画するには、
- 各セグメントの長さ
- 長さを計算するために、各セグメント
間オンにする角度は、まず、2πR円周を、(我々は3.1415としてPIを近似する)必要私たち
circumference = 2 * 3.1415 * radius
次を与え、我々は与えて、我々が近似しているセグメントの数によって、これを割る
circumference = 2 * 3.1415 * radius
seg_lenght = circumferece/36
ここで、セグメント間の角度差または外角が必要です。これは、単に360/N正n角形(n個の辺を有する多角形)のためのものであるので、我々は36分の360は10
を=現在のセグメント長を生成し、円を描くように関数を定義することができない。
def circle_around_point(radius):
circumference = 2 * 3.1415 * radius
seg_length = circumference/36
penup()
fd(radius) #Move from the centre to the circumference
right(90) #Face ready to start drawing the circle
pendown()
for i in range(36): #Draw each segment
fd(seg_length)
right(10)
penup()
right(90) #Face towards the centre of the circle
fd(radius) #Go back to the centre of the circle
right(180) #Restore original rotation
pendown()
今同心円のために:@IbraheemRodriguesはあなたの問題の説明に基づいて、亀のcircle()
機能を再コーディングする必要性を感じた理由
def concentric_circles(radius):
while radius > 0:
circle_around_point(radius)
radius -= 10
それは明らかではないが、我々は車輪の再発明しないことによって、彼のソリューションを簡素化することができます。
def circle_around_point(turtle, radius):
is_down = turtle.isdown()
if is_down:
turtle.penup()
turtle.forward(radius) # move from the center to the circumference
turtle.left(90) # face ready to start drawing the circle
turtle.pendown()
turtle.circle(radius)
turtle.penup()
turtle.right(90) # face awary from the center of the circle
turtle.backward(radius) # go back to the center of the circle
if is_down:
turtle.pendown() # restore original pen state
def concentric_circles(turtle, radius):
for r in range(radius, 0, -10):
circle_around_point(turtle, r)
circle()
への鍵は、あなたが特定のポイントに円の中心を作るために、半径によって自分の位置をシフトする必要があるので、現在位置が円の端にあるということです。
しかし、この問題を解決するために、私はスタンプにを描くから切り替えると、それにそれをスピードアップし、コードを簡素化するために、この方法を行う可能性があります:
import turtle
STAMP_SIZE = 20
radius = int(input("Please input a radius: "))
turtle.shape('circle')
turtle.fillcolor('white')
for r in range(radius, 0, -10):
turtle.shapesize(r * 2/STAMP_SIZE)
turtle.stamp()
turtle.mainloop()
しかし、これは、粗円を描きます小さなものを爆破だ:
はそれを修正するには、私は上記の二つのソリューションの間で妥協して行う可能性があります:
import turtle
radius = int(input("Please input a radius: "))
turtle.penup()
turtle.forward(radius)
turtle.left(90)
turtle.pendown()
turtle.begin_poly()
turtle.circle(radius)
turtle.penup()
turtle.end_poly()
turtle.addshape('round', turtle.get_poly()) # 'circle' is already taken
turtle.right(90)
turtle.backward(radius)
turtle.shape('round')
turtle.fillcolor('white')
for r in range(radius - 10, 0, -10):
turtle.shapesize(r/radius)
turtle.stamp()
turtle.mainloop()
これは、大規模なものを縮小する代わりに、小さなものを拡大して円の質を向上させます。
円の質がcircle()
への呼び出しにsteps=
引数を使用して制御することができ 。
しかし、高品質とスピードの高速を維持しながら、私は本当にコードを最小限にしたい場合は、私が行う可能性があります:
import turtle
radius = int(input("Please input a radius: "))
for diameter in range(radius * 2, 0, -20):
turtle.dot(diameter, 'black')
turtle.dot(diameter - 2, 'white')
turtle.hideturtle()
turtle.mainloop()
dot()
方法ではなく、半径の直径を使用して、中央の代わりに、端から引きます、 「なぜあなたは亀を改革でした
import turtle
#### ##### #### Below class draws concentric circles.
class Circle:
def __init__(self, pen, cx, cy, radius):
self.pen = pen
self.cx = cx
self.cy = cy
self.radius = radius
def drawCircle(self):
self.pen.up()
self.pen.setposition(self.cx, self.cy - self.radius)
self.pen.down()
self.pen.circle(self.radius)
def drawConCircle(self, minRadius = 10, delta = 10):
if(self.radius > minRadius) :
self.drawCircle()
self.radius -= delta # reduce radius of next circle
self.drawConCircle()
#### End class circle #######
win = turtle.Screen()
win.bgcolor("white")
s = Circle(turtle.Turtle(), 0, 0, 200)
s.drawConCircle()
win.exitonclick()
- 1. 楕円の同心円リング
- 2. CSS - 同心円
- 3. 同心円のバイナリツリー
- 4. Gnuplot同心円プロット
- 5. C3.jsの同心円弧
- 6. 色がJavaの同心円
- 7. 同心円を描く
- 8. Android:描画同心円
- 9. 散布図のMatplotlib同心円シェーディング(ブルズアイ)?
- 10. forループが同心円の楕円を繰り返す
- 11. D3同心円/入れ子式ドーナツチャート
- 12. 円を描くカメを作成する
- 13. Python 3のカメの速度
- 14. 同心円の長方形と楕円を作成するJavaプログラム?
- 15. forループを使用して同心円の楕円を繰り返す
- 16. Pythonカメの中心から左上に原点を移動しますか?
- 17. カメのグラフィックと同時にカメを実行する
- 18. 複数のカメを同時にPythonで移動するには?
- 19. 2つの座標の同心円を作る方法
- 20. 中心楕円の起点
- 21. c#windowsの同心円を描画するアプリケーション
- 22. 同心円の六角形を描く方法は?
- 23. igraph(R)で同心円のレイアウトを作成する方法
- 24. Pythonカメ移動プラットフォーム
- 25. 自分の中心を中心円とする円を見つける方法
- 26. R ggplot2/ggmap同心円をポイントとして
- 27. cssで同心円カラーブロックを作成するには?
- 28. Pythonのカメの開始位置
- 29. 1つのPythonカメが別のカメを追跡するようにする
- 30. 重心の95%信頼度の楕円
:のみ黒丸を描画し、この特定の運動に対する当社の最善の解決策です'circle()'メソッド?私はOPの質問に何も表示されていないので、追加の努力が必要です。 – cdlane
@cdlane私の悪い、その機能を認識していませんでした。私が使った演習では、私自身の機能を作りました。 –