質問するログイン新規登録

回答編集履歴

6

ログファイル名の修正、2.x 対応(文字コード指定)

2020/04/02 15:38

投稿

teamikl
teamikl

スコア8824

answer CHANGED
@@ -29,12 +29,13 @@
29
29
 
30
30
  記録用(record_motion.py) リダイレクト付きで実行してください
31
31
  ```python
32
+ # -*- coding: utf-8 -*-
32
- # 実行方法: python record_motion.py > handwriting-apple.txt
33
+ # 実行方法: python record_motion.py > motion.log
33
34
  from turtle import *
34
35
 
35
36
  # リダイレクトがうまくいかない場合以下の2行を有効にしてみてください
36
37
  # import sys
37
- # sys.stdout = open("handwriting-apple.txt", "w", encoding="utf-8")
38
+ # sys.stdout = open("motion.log", "w", encoding="utf-8")
38
39
 
39
40
  s = Screen()
40
41
  t = Turtle()
@@ -60,9 +61,11 @@
60
61
 
61
62
  再生用(replay_motion.py)
62
63
  ```
64
+ # -*- coding: utf-8 -*-
65
+
63
66
  from turtle import *
64
67
 
65
- with open("handwriting-apple.txt", encoding="utf-8") as stream:
68
+ with open("motion.log", encoding="utf-8") as stream:
66
69
  write("Apple", None, "center", "serif 64 bold")
67
70
  color("red")
68
71
  penup()
@@ -87,7 +90,7 @@
87
90
  ```
88
91
 
89
92
 
90
- handwriting-apple.txt の出力例
93
+ motion.log の出力例
91
94
  ```
92
95
  pendown 390 332
93
96
  setpos 390 333

5

リダイレクトについて、スクリプト内で出来るように追記

2020/04/02 15:38

投稿

teamikl
teamikl

スコア8824

answer CHANGED
@@ -32,6 +32,10 @@
32
32
  # 実行方法: python record_motion.py > handwriting-apple.txt
33
33
  from turtle import *
34
34
 
35
+ # リダイレクトがうまくいかない場合以下の2行を有効にしてみてください
36
+ # import sys
37
+ # sys.stdout = open("handwriting-apple.txt", "w", encoding="utf-8")
38
+
35
39
  s = Screen()
36
40
  t = Turtle()
37
41
 

4

記録~再生の手順を追加

2020/04/01 13:30

投稿

teamikl
teamikl

スコア8824

answer CHANGED
@@ -11,6 +11,10 @@
11
11
  3. 座標データを読み込み描画アニメーションとして再生するプログラムを作成
12
12
 
13
13
 
14
+ 追記: 記録~再生の手順
15
+ ![イメージ説明](27cc8e16d39d0fb16da80deaa62c0124.gif)
16
+
17
+
14
18
  ![イメージ説明](8909f5df0d645335b975d7e0a7ef99cf.gif)
15
19
 
16
20
  ![イメージ説明](8b2fb75e6c433b6ee701a0959a8fcef6.gif)

3

サンプルコードにファイル名追加。handwriting-apple.txt の出力例を追加

2020/04/01 13:24

投稿

teamikl
teamikl

スコア8824

answer CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  ----
25
25
 
26
- 記録用
26
+ 記録用(record_motion.py) リダイレクト付きで実行してください
27
27
  ```python
28
28
  # 実行方法: python record_motion.py > handwriting-apple.txt
29
29
  from turtle import *
@@ -50,7 +50,7 @@
50
50
  done()
51
51
  ```
52
52
 
53
- 再生用
53
+ 再生用(replay_motion.py)
54
54
  ```
55
55
  from turtle import *
56
56
 
@@ -76,4 +76,18 @@
76
76
 
77
77
  hideturtle()
78
78
  done()
79
- ```
79
+ ```
80
+
81
+
82
+ handwriting-apple.txt の出力例
83
+ ```
84
+ pendown 390 332
85
+ setpos 390 333
86
+ setpos 390 334
87
+ setpos 390 335
88
+ setpos 390 337
89
+ :
90
+ :
91
+ :
92
+ ```
93
+ このような感じに、マウスをドラッグ中に通った座標が記録されます。

2

インデント修正

2020/03/31 11:44

投稿

teamikl
teamikl

スコア8824

answer CHANGED
@@ -35,14 +35,14 @@
35
35
  print("setpos {} {}".format(e.x, e.y))
36
36
 
37
37
  def onrelease(e):
38
- print("penup")
38
+ print("penup")
39
- s.cv.unbind("<Motion>")
39
+ s.cv.unbind("<Motion>")
40
- s.cv.unbind("<ButtonRelease-1>")
40
+ s.cv.unbind("<ButtonRelease-1>")
41
41
 
42
42
  def onpress(e):
43
- print("pendown {} {}".format(e.x, e.y))
43
+ print("pendown {} {}".format(e.x, e.y))
44
- s.cv.bind("<Motion>", onmotion)
44
+ s.cv.bind("<Motion>", onmotion)
45
- s.cv.bind("<ButtonRelease-1>", onrelease)
45
+ s.cv.bind("<ButtonRelease-1>", onrelease)
46
46
 
47
47
  s.cv.bind("<ButtonPress-1>", onpress)
48
48
  t.write("Apple", None, "center", "serif 64 bold")

1

スペルミス修正(コードの実行には影響なし)

2020/03/26 17:01

投稿

teamikl
teamikl

スコア8824

answer CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  記録用
27
27
  ```python
28
- # python record_motion.py > handwiring-apple.txt
28
+ # 実行方法: python record_motion.py > handwriting-apple.txt
29
29
  from turtle import *
30
30
 
31
31
  s = Screen()
@@ -54,7 +54,7 @@
54
54
  ```
55
55
  from turtle import *
56
56
 
57
- with open("handwiring-apple.txt", encoding="utf-8") as stream:
57
+ with open("handwriting-apple.txt", encoding="utf-8") as stream:
58
58
  write("Apple", None, "center", "serif 64 bold")
59
59
  color("red")
60
60
  penup()