turtle.Shape.addcomponent()
turtle.Shape.addcomponent()
は、Pythonの turtle
(タートルグラフィックス) モジュールで、複数の図形を組み合わせて独自のタートルの形状を作成するためのメソッドです。
簡単に言うと、タートルはデフォルトで矢印や亀の形をしていますが、addcomponent()
を使うと、自分で作った多角形などを複数組み合わせて、新しいタートルの「見た目」を定義できるようになります。
解説
-
turtle.Shape オブジェクトの作成
まず、turtle.Shape
クラスのインスタンスを作成します。このとき、形状のタイプを"compound"
(複合) に指定します。my_shape = turtle.Shape("compound")
"compound"
は、「複数の部品からなる形状」を意味します。 -
addcomponent(poly, fill, outline=None) の使い方
作成したShape
オブジェクトに対して、addcomponent()
メソッドを呼び出して部品を追加していきます。poly
(必須): 追加する部品の形状を定義する多角形の座標のタプルです。例えば、三角形なら((x1, y1), (x2, y2), (x3, y3))
のように、点の座標をペアにしたタプルを要素とするタプルで指定します。fill
(必須): その部品の塗りつぶし色を指定します。色の名前(例:"red"
)やRGB値のタプル(例:(0.5, 0.0, 0.0)
)で指定できます。outline
(オプション): その部品の枠線の色を指定します。省略した場合は枠線は描画されません。
例えば、赤い三角形と青い四角形を組み合わせたい場合:
# 赤い三角形の部品 triangle_coords = ((0, 0), (50, 0), (25, 50)) my_shape.addcomponent(triangle_coords, "red") # 青い四角形の部品 square_coords = ((-20, -20), (20, -20), (20, 20), (-20, 20)) my_shape.addcomponent(square_coords, "blue")
-
形状の登録と適用
部品をすべて追加したら、その複合形状をturtle
モジュールに登録し、タートルに適用します。screen = turtle.Screen() screen.register_shape("my_custom_shape", my_shape) # 形状を登録 t = turtle.Turtle() t.shape("my_custom_shape") # タートルに適用
なぜ addcomponent()
を使うのか?
- 教育的な用途
プログラミング学習において、より創造的なグラフィック表現を可能にします。 - 複数の色や形状の組み合わせ
1つのタートルの形状の中に、異なる色や形の複数の部品を組み込むことができます。 - より複雑なタートルの見た目の作成
デフォルトの形状では表現できない、独自のアートワークやキャラクターなどをタートルに表示させることができます。
以下は、addcomponent()
を使って簡単なカスタム形状(星型)を作成する例です。
import turtle
# スクリーンとタートルを準備
screen = turtle.Screen()
screen.setup(width=600, height=600)
screen.bgcolor("lightblue")
# 複合形状を作成
star_shape = turtle.Shape("compound")
# 星の5つの頂点を計算(簡略化のため、ここでは適当な座標を使用)
# 実際にはもっと正確な計算が必要です
point1 = (0, 50)
point2 = (15, 15)
point3 = (50, 15)
point4 = (25, -5)
point5 = (40, -40)
point6 = (0, -20)
point7 = (-40, -40)
point8 = (-25, -5)
point9 = (-50, 15)
point10 = (-15, 15)
# 複数の三角形で星の形を構成する例
# 真ん中の五角形部分
center_poly = (point2, point4, point6, point8, point10)
star_shape.addcomponent(center_poly, "gold", "orange")
# 外側の三角形の部品を追加
# 例: 上の尖った部分
top_triangle = (point1, point2, point10)
star_shape.addcomponent(top_triangle, "gold", "orange")
# 他の尖った部分も同様に追加していく
# left_top_triangle = (point9, point10, point8) # 例
# star_shape.addcomponent(left_top_triangle, "gold", "orange")
# 形状を登録
screen.register_shape("my_star", star_shape)
# タートルを作成し、カスタム形状を適用
t = turtle.Turtle()
t.shape("my_star")
t.speed(1)
# タートルを動かしてみる
t.penup()
t.goto(-100, 0)
t.pendown()
t.forward(200)
t.hideturtle()
turtle.done()
poly 引数の形式間違い (TypeError または形状が正しく表示されない)
エラーの原因
addcomponent()
の最初の引数 poly
は、多角形の頂点の座標を定義するタプルのタプルである必要があります。具体的には ((x1, y1), (x2, y2), ..., (xn, yn))
の形式です。リストのリストや、座標が単なる数値のタプルになっているなど、形式が間違っているとエラーになるか、意図しない形状になります。
よくある間違い
- 座標のペアがタプルではなくリストになっている(例:
([x1, y1], [x2, y2])
)。 ((x1, y1, x2, y2))
のように、タプルの中にすべての座標を平坦に入れてしまっている。[[x1, y1], [x2, y2]]
のようにリストを使っている。
トラブルシューティング
- 各頂点が
(x, y)
の形式のタプルであること、それらのタプルがさらに外側のタプルで囲まれていることを確認してください。 poly
引数に渡している変数の型と中身をprint()
で確認してください。
例
import turtle
screen = turtle.Screen()
my_shape = turtle.Shape("compound")
# OK: 正しい形式
correct_poly = ((0, 0), (50, 0), (25, 50))
my_shape.addcomponent(correct_poly, "red")
# NG: リストのリスト (TypeError になる可能性、または意図しない動作)
# incorrect_poly1 = [[0, 0], [50, 0], [25, 50]]
# my_shape.addcomponent(incorrect_poly1, "blue") # これを実行するとエラーになる
# NG: 座標が平坦になっている (ValueError など)
# incorrect_poly2 = (0, 0, 50, 0, 25, 50)
# my_shape.addcomponent(incorrect_poly2, "green") # これを実行するとエラーになる
screen.register_shape("test_shape", my_shape)
t = turtle.Turtle()
t.shape("test_shape")
turtle.done()
Shape("compound") の指定忘れ (TypeError など)
エラーの原因
addcomponent()
は turtle.Shape
オブジェクトに対して呼び出されるメソッドですが、その Shape
オブジェクトが "compound"
タイプとして作成されていない場合、期待通りに動作しません。他の形状タイプ(例えば "polygon"
)は単一の多角形を扱うため、addcomponent()
を呼び出そうとするとエラーになるか、意味がありません。
トラブルシューティング
my_shape = turtle.Shape("compound")
のように、形状を複合タイプとして正しく初期化していることを確認してください。
色の指定ミス (TclError または色が適用されない)
エラーの原因
fill
(塗りつぶし色) や outline
(枠線色) の引数に、Pythonの turtle
が認識できない色の名前(例: "re" など)や、無効なRGB値のタプル(例: (300, 0, 0)
)を指定するとエラーが発生します。
トラブルシューティング
- RGB値を指定する場合は、各要素が
0
から1
の浮動小数点数、または0
から255
の整数であることを確認してください。整数で指定する場合は、screen.colormode(255)
を設定する必要があります。 - 標準的な色の名前(例:
"red"
,"blue"
,"green"
,"yellow"
,"black"
,"white"
など)を使用してください。
例
import turtle
screen = turtle.Screen()
# screen.colormode(255) # 0-255 の整数RGB値を使う場合
my_shape = turtle.Shape("compound")
# OK: 有効な色名
my_shape.addcomponent(((0,0), (10,0), (5,10)), "green")
# OK: 有効なRGB (0.0-1.0)
my_shape.addcomponent(((10,0), (20,0), (15,10)), (0.5, 0.2, 0.8))
# NG: 存在しない色名 (TclError)
# my_shape.addcomponent(((20,0), (30,0), (25,10)), "purplle")
screen.register_shape("color_test", my_shape)
t = turtle.Turtle()
t.shape("color_test")
turtle.done()
形状が登録されていない/適用されていない (タートルがデフォルトの形状のまま、またはエラー)
エラーの原因
addcomponent()
で形状を定義した後、その形状を turtle.Screen().register_shape()
で登録し、さらに turtle.Turtle().shape()
でタートルに適用する必要があります。これらを忘れると、タートルはデフォルトの形状のままか、または存在しない形状を指定したとしてエラーになります。
トラブルシューティング
t.shape("形状名")
を呼び出しているか、また"形状名"
がregister_shape()
で登録した名前と一致しているか確認してください。screen.register_shape("形状名", my_shape)
を呼び出しているか確認してください。
座標系の理解不足 (形状が意図しない位置に描画される、回転がおかしい)
エラーの原因
addcomponent()
で指定する多角形の座標は、タートルの中心を原点 (0, 0) とした相対座標です。タートルが動くと、この「形状」もタートルの動きに合わせて移動します。もし形状の原点がタートルの中心から大きくずれていると、回転や移動の際に違和感のある動きになります。
トラブルシューティング
- 特に複雑な形状の場合、小さな部品ごとに座標を計算し、
print()
で確認しながら調整すると良いでしょう。 - 作成したい形状の中心が、座標
(0, 0)
になるように部品の座標を設計してください。
エラーの原因
これは addcomponent()
に直接関係するエラーではありませんが、turtle
モジュール全体でよくある問題です。スクリプトが終了すると同時にタートルグラフィックスのウィンドウも閉じてしまうため、描画結果を確認できません。
トラブルシューティング
- スクリプトの最後に
turtle.done()
またはturtle.Screen().mainloop()
を追加してください。これにより、ウィンドウが閉じずに開いたままになります。
turtle.Shape.addcomponent()
を使う際は、以下の点を特に注意して確認してください。
- 最後に
turtle.done()
を呼び出してウィンドウを閉じないようにしているか。 - 形状の原点をタートルの中心 (0, 0) に合わせているか。
- 作成した形状を
register_shape()
で登録し、shape()
でタートルに適用しているか。 - 色名が有効なものか、またはRGB値が正しい範囲にあるか。
addcomponent()
のpoly
引数が((x, y), ...)
の正しいタプルのタプル形式になっているか。Shape
オブジェクトを"compound"
タイプで作成しているか。
例1:シンプルなカスタム形状(三角形と四角形の組み合わせ)
この例では、赤い三角形と青い四角形を組み合わせて、新しいタートルの形状を作ります。
import turtle
# 1. スクリーンとタートルを準備
screen = turtle.Screen()
screen.setup(width=600, height=400)
screen.bgcolor("lightgray")
screen.title("シンプルなカスタム形状")
# 2. 複合形状 (compound shape) オブジェクトを作成
# addcomponent() を使うには、必ず "compound" タイプでShapeオブジェクトを作成します。
my_custom_shape = turtle.Shape("compound")
# 3. 形状の部品 (component) を追加する
# addcomponent(多角形の頂点座標のタプル, 塗りつぶし色, 枠線色(オプション))
# 部品1:赤い三角形
# タートルの中心 (0,0) を基準に座標を定義します。
# この三角形は (0,0) を頂点の一つとする。
triangle_coords = ((0, 0), (50, 0), (25, 50))
my_custom_shape.addcomponent(triangle_coords, "red")
# 部品2:青い四角形
# この四角形は三角形の下に位置するように座標を調整します。
square_coords = ((-20, -50), (20, -50), (20, -10), (-20, -10))
my_custom_shape.addcomponent(square_coords, "blue")
# 4. 作成したカスタム形状をタートルシステムに登録
# 好きな名前(ここでは "my_combined_shape")と、作成したShapeオブジェクトを渡します。
screen.register_shape("my_combined_shape", my_custom_shape)
# 5. タートルを作成し、カスタム形状を適用
artist_turtle = turtle.Turtle()
artist_turtle.shape("my_combined_shape") # 登録した名前を指定
artist_turtle.speed(1) # アニメーション速度を設定
# 6. タートルを動かして表示を確認
artist_turtle.penup()
artist_turtle.goto(-100, 0)
artist_turtle.pendown()
artist_turtle.forward(200)
artist_turtle.right(90)
artist_turtle.forward(50)
# 画面を閉じないようにする
turtle.done()
例2:矢印に装飾を追加する(より複雑なカスタム形状)
この例では、基本的な矢印の形に、小さな円をいくつか追加して装飾された矢印を作成します。
import turtle
screen = turtle.Screen()
screen.setup(width=600, height=400)
screen.bgcolor("white")
screen.title("装飾された矢印")
decorated_arrow = turtle.Shape("compound")
# 1. 矢印の本体部分
# turtleモジュールのデフォルトの矢印は、(0,0)が矢印の付け根あたりに来るように設計されています。
# 今回は、それに合わせて少し調整します。
arrow_body_coords = ((0, 0), (10, 0), (10, 20), (20, 20), (0, 40), (-20, 20), (-10, 20), (-10, 0))
decorated_arrow.addcomponent(arrow_body_coords, "darkgreen", "black")
# 2. 装飾用の小さな円を追加
# 円は多角形で近似します。ここでは、約12角形を使います。
# タートルの中心 (0,0) は矢印の付け根あたりなので、それに合わせて円の位置を調整します。
import math
def get_circle_coords(radius, center_x, center_y, segments=12):
"""円の頂点座標を生成するヘルパー関数"""
coords = []
for i in range(segments):
angle = 2 * math.pi * i / segments
x = center_x + radius * math.cos(angle)
y = center_y + radius * math.sin(angle)
coords.append((x, y))
return tuple(coords) # addcomponentはタプルのタプルを期待する
# 矢印の先に小さな赤い丸
circle1_coords = get_circle_coords(5, 0, 30) # 矢印の先端近く
decorated_arrow.addcomponent(circle1_coords, "red", "darkred")
# 矢印のボディに沿って青い丸をいくつか
circle2_coords = get_circle_coords(3, 5, 10)
decorated_arrow.addcomponent(circle2_coords, "blue", "darkblue")
circle3_coords = get_circle_coords(3, -5, 10)
decorated_arrow.addcomponent(circle3_coords, "blue", "darkblue")
# 登録と適用
screen.register_shape("decorated_arrow", decorated_arrow)
my_turtle = turtle.Turtle()
my_turtle.shape("decorated_arrow")
my_turtle.color("purple") # タートル自体の色設定は、形状の塗りつぶし色とは別です
my_turtle.speed(3)
# 動きの例
my_turtle.penup()
my_turtle.goto(-150, 0)
my_turtle.pendown()
for _ in range(4):
my_turtle.forward(100)
my_turtle.right(90)
turtle.done()
この例では、addcomponent()
を使って、目と口のある簡単なキャラクターの顔の一部を作成します。
import turtle
screen = turtle.Screen()
screen.setup(width=600, height=600)
screen.bgcolor("pink")
screen.title("キャラクターの顔")
face_shape = turtle.Shape("compound")
# 1. 顔のベースとなる大きな円 (多角形で近似)
# 中心を(0,0)に設定
import math
def get_circle_coords(radius, center_x, center_y, segments=30):
coords = []
for i in range(segments):
angle = 2 * math.pi * i / segments
x = center_x + radius * math.cos(angle)
y = center_y + radius * math.sin(angle)
coords.append((x, y))
return tuple(coords)
face_base_coords = get_circle_coords(100, 0, 0)
face_shape.addcomponent(face_base_coords, "yellow", "orange")
# 2. 目(白い楕円として長方形で近似)
# タートルの中心(0,0)から見た相対位置
# 左目
left_eye_coords = ((-50, 20), (-20, 20), (-20, 50), (-50, 50))
face_shape.addcomponent(left_eye_coords, "white", "black")
# 右目
right_eye_coords = ((20, 20), (50, 20), (50, 50), (20, 50))
face_shape.addcomponent(right_eye_coords, "white", "black")
# 3. 瞳(黒い円)
# 左瞳
left_pupil_coords = get_circle_coords(5, -35, 35, segments=10)
face_shape.addcomponent(left_pupil_coords, "black")
# 右瞳
right_pupil_coords = get_circle_coords(5, 35, 35, segments=10)
face_shape.addcomponent(right_pupil_coords, "black")
# 4. 口(半円を近似する多角形)
# 下向きの弧を描くように座標を調整
mouth_coords = (
(-40, -40), (-30, -55), (-10, -60), (10, -60), (30, -55), (40, -40), (20, -35), (-20, -35)
)
face_shape.addcomponent(mouth_coords, "brown", "darkred")
# 登録と適用
screen.register_shape("my_face", face_shape)
character_turtle = turtle.Turtle()
character_turtle.shape("my_face")
character_turtle.speed(0) # 最速
character_turtle.penup()
character_turtle.goto(-150, 0) # 左に移動
# 動きの例
character_turtle.stamp() # スタンプで複製
character_turtle.goto(0, 0)
character_turtle.stamp()
character_turtle.goto(150, 0)
character_turtle.stamp()
turtle.done()
turtle.Shape.addcomponent()
の代替方法について
turtle.Shape.addcomponent()
は複数の図形を組み合わせて独自のタートル形状を作成するのに非常に便利な機能ですが、必ずしもこれを使わなければならないわけではありません。状況や目的によっては、他の方法がより適切であったり、簡単に実装できたりすることもあります。
主な代替方法は以下の通りです。
turtle.register_shape()
と画像ファイル(GIF/PNG)の使用turtle.addshape()
と独自の多角形(Polygon)の使用- 複数のタートルを重ねて使用する
- スタンプ機能(
turtle.stamp()
)の活用
turtle.register_shape() と画像ファイル(GIF/PNG)の使用
最も簡単で、複雑な見た目を実現できる方法です。あらかじめ作成した画像ファイル(GIF形式が推奨されますが、一部の環境ではPNGもサポートされます)をタートルの形状として登録できます。
メリット
- アニメーションGIF
アニメーションGIFを形状として登録すると、タートルが動くたびにアニメーションする、という面白い効果も得られます。 - 実装が非常に簡単
画像ファイルを用意するだけで、コードは数行で済みます。 - デザインの自由度が高い
外部の画像編集ソフト(Photoshop, GIMPなど)で、どんな複雑なデザインでも作成できます。
デメリット
- 色の変更ができない
一度画像として読み込んだら、プログラムからその画像の色を変えることはできません。 - 画像の解像度
小さなサイズで表示すると荒くなる可能性があります。 - 画像ファイルの準備が必要
プログラム内で動的に形状を生成するわけではないので、別途画像ファイルを作成する必要があります。
使用例
import turtle
screen = turtle.Screen()
screen.setup(width=600, height=400)
screen.bgcolor("white")
screen.title("画像ファイルの形状")
# 画像ファイルを登録(画像ファイルはスクリプトと同じディレクトリに置くか、フルパスを指定)
# 例: "my_custom_image.gif" という画像ファイルがあるとする
try:
screen.register_shape("custom_image", "my_custom_image.gif")
# my_custom_image.gif が存在しないとエラーになるため、try-except で囲むと良いでしょう。
except turtle.TurtleGraphicsError:
print("エラー: 'my_custom_image.gif' が見つからないか、読み込めません。")
print("ダミーの形状を使用します。")
# 代替の形状を設定
screen.register_shape("custom_image", "circle")
# タートルを作成し、画像形状を適用
my_turtle = turtle.Turtle()
my_turtle.shape("custom_image")
my_turtle.penup()
my_turtle.goto(-100, 0)
my_turtle.pendown()
my_turtle.speed(1)
my_turtle.forward(200)
turtle.done()
注意
my_custom_image.gif
という名前のGIF画像を、このPythonスクリプトと同じディレクトリに用意しておく必要があります。
turtle.addshape() と独自の多角形(Polygon)の使用
addcomponent()
が複数の多角形を結合するのに対し、addshape()
は単一の多角形をタートルの形状として登録できます。
- 色変更が可能
turtle.color()
メソッドで、登録した多角形の色を変更できます。 - プログラムで形状を定義
コード内で座標を指定するので、動的な生成が可能です。 - シンプル
addcomponent()
よりも引数が少なく、単一の多角形であれば簡単に定義できます。
- addcomponent() ほど柔軟ではない
複数のパーツからなる複雑な形状を作成するには不向きです。 - 単一の多角形のみ
複数の色や、穴が開いているような複雑な形状は直接表現できません。
import turtle
screen = turtle.Screen()
screen.setup(width=600, height=400)
screen.bgcolor("white")
screen.title("多角形形状")
# 多角形の頂点座標を定義(タートルの中心が(0,0)になるように設計)
# 例: 上向きの矢印
arrow_points = ((0, 20), (-10, 0), (10, 0))
# 形状を登録 (addshape は Shape オブジェクトではなく、直接座標タプルを受け取る)
screen.addshape("up_arrow", turtle.Shape("polygon", arrow_points))
# タートルを作成し、形状を適用
my_turtle = turtle.Turtle()
my_turtle.shape("up_arrow")
my_turtle.color("darkorange") # 色も変更可能
my_turtle.penup()
my_turtle.goto(-100, 0)
my_turtle.pendown()
my_turtle.speed(2)
my_turtle.forward(50)
my_turtle.left(90)
my_turtle.forward(50)
my_turtle.right(45)
my_turtle.forward(50)
turtle.done()
複数のタートルを重ねて使用する
それぞれのタートルに異なる形状や色を設定し、それらを同じ位置に配置することで、あたかも一つの複雑な形状であるかのように見せることができます。
- 複雑な動き
各部品を個別に動かすことで、より複雑なアニメーションを作成できます(例: 目のタートルだけまばたきさせる)。 - 動的な制御
各部品(タートル)の色や形状、表示/非表示を個別に変更できます。 - 理解しやすい
各部分が独立したタートルであるため、個々の部品の制御が直感的です。
- パフォーマンス
非常に多くのタートルを同時に動かすと、描画パフォーマンスが低下する可能性があります。 - 管理が煩雑
部品が増えるほど、タートルの数が増え、位置合わせや管理が複雑になります。
import turtle
screen = turtle.Screen()
screen.setup(width=600, height=400)
screen.bgcolor("lightcyan")
screen.title("複数のタートルを重ねる")
# メインとなるタートル(本体)
main_turtle = turtle.Turtle()
main_turtle.shape("square") # 四角形を本体とする
main_turtle.color("blue")
main_turtle.shapesize(stretch_wid=3, stretch_len=3) # 少し大きめの四角形
main_turtle.penup()
main_turtle.speed(1)
# サブとなるタートル(装飾)
dot_turtle1 = turtle.Turtle()
dot_turtle1.shape("circle")
dot_turtle1.color("red")
dot_turtle1.penup()
dot_turtle1.goto(main_turtle.xcor() - 20, main_turtle.ycor() + 20) # メインのタートルからの相対位置
dot_turtle1.speed(1)
dot_turtle2 = turtle.Turtle()
dot_turtle2.shape("circle")
dot_turtle2.color("red")
dot_turtle2.penup()
dot_turtle2.goto(main_turtle.xcor() + 20, main_turtle.ycor() + 20)
dot_turtle2.speed(1)
# 全体を一緒に動かす
def move_all(x, y):
main_turtle.goto(x, y)
dot_turtle1.goto(x - 20, y + 20)
dot_turtle2.goto(x + 20, y + 20)
move_all(-100, 0)
screen.update() # 描画を強制更新(複数のタートルを動かす際に使うと良い)
move_all(100, 0)
screen.update()
turtle.done()
スタンプ機能(turtle.stamp())の活用
stamp()
メソッドは、現在のタートルの形状を画面に「スタンプ」として残します。タートル本体は移動しても、スタンプは残ります。これを応用して、複数のスタンプを重ねて複雑な形状を作成できます。
- 複雑なパターン
繰り返し処理と組み合わせることで、幾何学的な模様や複雑なパターンを簡単に生成できます。 - 非常に柔軟
好きな形状のタートルを使って、好きな場所にスタンプを押すことで、無限の組み合わせが可能です。
- 管理が難しい
多くのスタンプを管理する場合、それぞれの位置を把握するのが困難になることがあります。 - 静的な形状
スタンプは一度押されると独立した描画となり、後から色を変更したり、個別に動かしたりすることはできません(タートル本体の色を変えてもスタンプの色は変わりません)。
import turtle
screen = turtle.Screen()
screen.setup(width=600, height=400)
screen.bgcolor("lightyellow")
screen.title("スタンプ機能で形状作成")
# ベースとなるタートル
my_turtle = turtle.Turtle()
my_turtle.shape("square") # 四角形をスタンプする
my_turtle.color("orange")
my_turtle.penup()
my_turtle.speed(0) # 最速
# 中心にスタンプをたくさん重ねて花のような形状を作る
center_x, center_y = 0, 0
# 花びらのように四角形をスタンプ
for i in range(12):
my_turtle.goto(center_x, center_y)
my_turtle.setheading(i * 30) # 30度ずつ回転
my_turtle.forward(50) # 少し離れた位置に移動
my_turtle.stamp() # スタンプを押す
my_turtle.backward(50) # 元の位置に戻る
# 中心に円をスタンプ
my_turtle.shape("circle")
my_turtle.color("red")
my_turtle.goto(center_x, center_y)
my_turtle.stamp()
my_turtle.hideturtle() # タートル本体を隠す
turtle.done()
- プログラム内で複数の多角形を組み合わせて、タートルが動くたびにその複合形状全体を動かしたい場合
やはりturtle.Shape.addcomponent()
が最適です。 - 静的なパターンや模様を効率的に生成したい場合
4. スタンプ機能の活用 - 複数の独立した動く部品を組み合わせたい場合
3. 複数のタートルを重ねて使用する - 単一の多角形を形状として登録したい場合
2.turtle.addshape()
- 最も複雑な見た目や外部のデザインを使用したい場合
1. 画像ファイルの使用