2019年1月30日水曜日

python turrtle で「カメ」を任意の画像に置き換える。


Ubuntuに搭載されているPythonの標準のGUIはGtkです。
turtle モジュールをimportするには
Tkinterをインストールします。

$  sudo apt-get install python-tk

turtle の形は次の5種類から選べます。

 "arrow", "turtle", "circle", "square", "triangle", "classic"

 turtle.shape("turtle")

と指定すれば文字どおり亀になります。

'blank'を指定することもできます。

 また任意のGif画像を指定することもできます。



from turtle import *
def yen(t,x,y,s) :
t.penup()
t.setx (x)
t.sety (y-s)
t.pendown()
t.circle(s)
t=Turtle()
s=t.getscreen()
s.register_shape("a.gif")
t.shape('a.gif')
yen(t,0,0,100)
done()
view raw a.py hosted with ❤ by GitHub




(注:「カメ」のように向きを変えながら描画はできない。)

0 件のコメント:

コメントを投稿