Pythonシェルを介してタートルモジュールを制御できる関数を作成しました。その一部を次に示します。
import turtle
turtle.showturtle()
def turtle_commands():
instructions = input().split()
i = instructions[0]
if len(instructions) == 2:
if i == 'forward' :
n = int(instructions[1])
turtle.forward(n)
たとえば、入力するとき
forward 100
カメは100ピクセル前方に移動します。私はほとんどのタートルコマンドで同じことをしました-後方、左、右、ペンアップ、ペンダウン、色など。
私の質問は、テキストファイルからこれらのコマンドをロードする方法はありますか?そんなことを考えていた
instructions = input().split()
i = instructions[0]
if i == 'load' :
n = str(instructions[1])
l = open(n, 'r')
while True:
line = l.readline()
turtle_commands(line) #i don't really know what i did here, but hopefully you get the point
if not line:
break
プログラムは、ファイルとシェルの両方からコマンドを受け入れる必要があります。ご回答ありがとうございます。