logo programming - 佛教慧因法師紀念中學buddhist … 1 : write the following procedure,...
TRANSCRIPT
P.1
佛教慧因法師紀念中學
BUDDHIST WAI YAN MEMORIAL COLLEGE
普通電腦科
COMPUTER LITERACY
LOGO程序編寫
LOGO Programming
姓名/NAME: _______________________ ( )
班別/CLASS : ____
P.2
1:Logo的界面 / The interface of Logo
連按兩下 開始MSWlogo。
Double-Click to start MSWlogo.
界面上的下拉功能表內含有多個指令,如下:
The pull-down menu in the interface contains many commands as below :
例如,要離開MSWLogo,點選功能表 File→Exit。
E.g., click on the menu File→Exit to exit MSWLogo.
Start !!
P.3
2:圖龜的移動和轉動 / Moving and turning the turtle
輸入指令並觀察其功用。
Input the commands and see their uses.
指令
command 功用 use
1. FD 100 前進 100步 Forward 100 steps
2. RT 90 向右轉 90度 Right turn 90 degrees
3. FD 00 前進 100步 Forward 100 steps
4. LT 90 向左轉 90度 Left turn 90 degrees
5. BK 100 後退 100步 Backward 100 steps
6. CS 清除圖幕 Clear screen
輸入指令,看看結果是否與下圖相同。
Input the commands to see if the result is different from the following figure.
CS
FD 50
BK 80
練習:輸入指令並畫出結果。
Exercise : Input the commands and draw the results
指令 commands 結果 results
RT 60
FD 100
RT 60
FD 100
LT 90
BK 100
RT 90
FD 100
P.4
3:顯示和隱藏圖龜 / Show and hide the turtle
輸入指令,觀察圖龜的變化。
Input the commands and see how the turtle changes.
CS
HT (圖龜消失了 / the turtle disappears)
ST (圖龜出現了 / the turtle appears)
FD 80
RT 90
FD 80
HT
HOME (圖龜返回屏幕中央 / the turtle goes to the centre)
練習:輸入指令並畫出結果。
Exercise : input the commands and draw the results.
指令 commands 結果 results
(1) 長方形 / rectangle
CS
FD 50 RT 90
FD 100 RT 90
FD 50 RT 90
FD 100 RT 90
(2)「日」字形 / the「日」shape
CS
FD50 RT 90 FD 50 RT 90
FD 50 RT 90 FD 50 RT 90
FD 25 RT 90
FD 50 HT
P.5
4:繪圖筆功能 / Pen functions
(1) PU 拿起筆 / Pen Up
PD 放下筆/ Pen Down
(2) 點選功能表列的 Set→Screen Color來設定背景顏色。
Click on the menu Set→Screen Color to set the background colour.
(3) 點選 Set→Pen Size來設定畫筆粗幼。
Click on the menu Set→Pen Size to set the size of the pen.
(4) 點選 Set→Pen Color來設定畫筆顏色。
Click on the menu Set→Pen Color to set the colour of the pen.
(5) 點選 Label Font和 Commander Font來設定文字格式。
Click on the menu Set→Pen Color to set the text fonts.
5:儲存和列印圖畫檔案 / Save and print the graphic file
點選功能表列的 Bitmap→Save,然後選取存檔位置。亦可在 Active Area設定圖
畫大小後再儲存檔案。
Click on the menu Bitmap → Save, then select the location for saving the files. The
size of the picture can also be set in the Active Area before saving the file.
在功能表列點選 Bitmap→Print把圖畫列印出來。
Click on the menu Bitmap→Print to print the picture.
P.6
6:REPEAT
A. REPEAT用作重複一些動作 / REPEAT is used to repeat some actions.
任務 1 :輸入指令並畫出結果。
Task 1 : Input the commands and draw the result.
REPEAT 3 [RT 120 FD 150] ,
任務 2 : 參考下表,繪製一些多邊形:
Task 2 : Draw some polygons by referring to the following table :
三角形 五邊形 六邊形
重複次數 repetition 3 5 6
轉向角度 angle 120 72 60
任務 3 : 寫出繪製一個八邊形的指令。
Task 3 : Write down the command of drawing a octagon.
__________________________________________________________
B. 嵌套 REPEAT / Nested REPEAT
任務 4 :畫出右圖
Task 4 : draw the picture at the right
提示 / Hint :
REPEAT ____ [FD 100 REPEAT ____ [FD 50 RT ____ ] BK 100 RT ____]
P.7
任務 5 : 參考下表,繪製一些多角星
Task 5 : Draw some Multi-pointed stars by referring to the following table:
5角
5-pointed
7角
7-pointed
15角
15-pointed
25角
25-pointed
45角
45-pointed
75角
75-pointed
重複次數
repetition 5 7 15 25 45 75
轉向角度
angle 144 160 168 172.8 ? 177.6
任務 6 : 寫出繪製一個 45角星的指令。
Task 6 : Write down the command of drawing a 45-pointed star.
__________________________________________________________ 任務 7 : 試繪製右圖
Task 7 : draw the picture at the right
C. 挑戰題 / Challenge
-
P.8
7:圓形 / Circle
A. 以 REPEAT繪畫一個邊長為 5 的 36邊形 : Use REPEAT to draw a 36-side polygon with side-length to be 5.
任務 1 : 輸入指令並畫出結果。
Task 1 : Input the commands and draw the result.
REPEAT 36 [RT 10 FD 5]
你會發現這個多邊形看起來好像圓形。
You may find that the polygon looks like a circle.
任務 2 :參考下表,繪製一些不同大小的圓形 :
Task 2 : Draw some circles of difference sizes by referring to the following table:
REPEAT 72 180 360
RT 5 2 1
任務 3 : 試繪製下圖。
Task 3 : draw the following picture.
P.9
任務 4 : 圓或弧形。
Task 4 : Circles or arcs
以[rt 1 fd 1] 為基礎,repeat 360 可以畫出一個圓形,repeat的次數
少於 360則可畫出圓形的一部份。
Basing on [rt 1 fd 1], ‘repeat 360’ can be used to draw a circle. If the
number of repetition is less than 360, an arc can be drawn.
輸入指令並畫出結果。
Input the commands and draw the results.
REPEAT 270 [RT 1 FD 1] REPEAT 180 [RT 1 FD 1]
REPEAT 90 [RT 1 FD 1] REPEAT 45 [RT 1 FD 1]
任務 5 :畫出下列圖形。
Task 5 : Draw the following pictures.
P.10
8:程序編寫 / Writing procedures
A. 以 TO為一個程序命名,並啟動程序編輯器。
Use TO to name a procedure and launch the procedure editor.
任務 1 : 編寫一個名為 ABC的程序
Task 1 : Write a program named ABC.
在指令行輸入指令 TO ABC,程序輸入器就會出現如下 :
Input the command TO ABC in the commander, then the To Mode dialog
box appears as below :
在空格內輸入 REPEAT 10[REPEAT 2[REPEAT 90 [RT 1 FD 3] RT 90] RT
36] ,然後按 ,完成後按 ,程序就完成了,程序編輯
器亦自動消失。
Input ‘REPEAT 10[REPEAT 2[REPEAT 90 [RT 1 FD 3] RT 90] RT 36]’ in
the box, then click on . Then click on . The procedure is
finished and the dialog box disappears.
在指令行輸入程序名稱就可啟動該程序 :
Input the name of the procedure in the commander to start the procedure.
P.11
在指令行輸入指令 EDIT "ABC,程序編輯器就會出現如下 :
Input the command ‘EDIT "ABC’ in the commander, then the procedure
editor appears as below :
按需要進行修改,按 File – Save and Exit 以貯存該程序檔案。最後,亦
須要在主畫面按 File – SaveAs以貯存該 LOGO檔案。日後若要使用此
LOGO檔案,按 File – Load 便可。
Edit the procedure as needed. Click on File – Save and Exit to save the
procedure. Lastly, it needs to save the LOGO file by clicking on File –
SaveAs in the main screen. To use this procedure, click on File - Load.
任務2 : 編寫一個名為ABC的程序,用作繪製下圖。
Task 2 : Write a procedure named ABC to draw the following picture :
repeat 360[fd 4 rt 1]
repeat 180[fd 2 rt 1]
repeat 180[fd 2 lt 1]
pu
lt 90 fd 20 fd 20 rt 90
pd
repeat 360[fd 1 lt 1]
pu
lt 90 fd 380 rt 90
pd
repeat 360[fd 1 rt 1]
P.12
9:變量及其應用(遞迴) / Variable and its uses ( recursion)
任務1 / Task 1
編寫下列程序,然後運行這個程序,並畫出結果。
Write the following procedure, then run it and draw the result.
TO LINE :A
FD :A BK :A
RT 15
END
修改LINE如下,然後運行這個程序,並畫出結果。
Edit LINE as below. Then run it and draw the result.
TO LINE :A
FD :A BK :A
RT 15
LINE :A
END
再修改LINE如下,然後運行這個程序,並畫出結果。
Edit LINE again as below. Then run it and draw the result.
TO LINE :A
FD :A BK :A
RT 15
LINE :A*0.9
END
再修改LINE如下,然後運行這個程序,並畫出結果。
Edit LINE again as below. Then run it and draw the result.
TO LINE :A
FD :A BK :A
RT 15
RT 90 FD :A/20 LT 90
LINE :A*0.9
END
P.13
任務2 / Task 2
編寫下列程序,然後運行這個程序,並畫出結果。
Write the following procedure, then run it and draw the result.
TO RING :A
FD :A RT 60 FD :A
RT 150 FD :A*1.7 RT 180
END
修改RING如下,然後運行這個程序,並畫出結果。
Edit RING as below. Then run it and draw the result.
TO RING :A
FD :A RT 60 FD :A
RT 150 FD :A*1.7 RT 180
RING :A*0.9
END
任務 3 : 編寫一個名為 XYZ的程序,用作繪製下圖。
Task 3 : Write a procedure named XYZ to draw the following picture : TO XYZ :B
FD :B LT 10 BK :B
RT 35
RT 90 FD :B/20 LT 90
LINE :B*0.9
END
P.14
10:IF IF – Then / 如果…則
任務1 : 編寫下列程序,然後運行這個程序,並畫出結果。
Task 1 : Write the following procedure, then run it and draw the result.
TO HEXAGON :N
REPEAT 6 [REPEAT 3 [FD :N RT 120] RT 60]
END
HEXAGON 60
HEXAGON 80
HEXAGON 100
任務2 : 編寫下列程序,然後運行這個程序,並畫出結果。
Task 2 : Write the following procedure, then run it and draw the result.
TO SPIDERMAN :N
HEXAGON :N
SPIDERMAN :N + 10
END
SPIDERMAN 40
**提示 : 要停止程序的運行,按 Halt 。
**Hint : to stop the procedure, press Halt
任務3 : 參考下列程序,以IF設下停止運行[STOP]的條件,並畫出結果。
Task 3 : Refering the following procedure, use IF to set the condition to STOP
the procedure. Draw the result.
TO SPIDERMAN :N
IF :N > 100 [STOP]
HEXAGON :N
SPIDERMAN :N + 10
END
SPIDERMAN 40
P.15
11:方向及座標 / Directions and Coordinates
輸入 SHOW HEADING 可顯示圖龜方向
Input SHOW HEADING can show the direction of the turtle.
輸入 SETHEADING _____ ( 或 SETH _____ ) 可設定方向。例子: SETH 270
Input SETHEADING _____ ( or SETH _____ ) to set the direction, e.g. SETH 270
設定 X座標: SETX _____ 例子: SETX 250
Set the X coordinate : SETX _____ e.g. SETX 250
設定 Y座標: SETY _____ 例子: SETY 100
Set the Y coordinate : SETX _____ e.g. SETY 250
設定 X和 Y座標: SETXY _____ _____例子: SETXY 250 300
或 SETPOS [ _____ _____ ] 例子: SETPOS [250 300]
Set the X and Y coordinates : SETX _____ e.g. SETXY 250 300
Or SETPOS [ _____ _____ ] e.g. SETPOS [250 300]
P.16
試一試!
Try it !
TO BOAT
CS PU SETPOS [ 20 -40] PD
SETPOS [-160 -40] SETPOS [ 20 160]
SETPOS [ 140 -40] SETPOS [ 20 -40]
PU SETPOS [ -120 -60] PD
SETPOS [ -80 -100]
SETPOS [ 80 -100]
SETPOS [ 120 -60]
SETPOS [ 20 -60]
SETPOS [ 20 -40]
SETPOS [ 20 -60]
SETPOS [ -120 -60]
END
終極挑戰 : 利用以上程式,畫出一艘向左航行的船。
Ultimate challenge : Use the procedure above to draw a
boat which is moving left.
在下列方格寫出LOGO程式碼:
Write down the commands in the box below :
TO MOVINGBOAT
END
P.17
第 6章答案 Answers to Section 6
任務 1
REPEAT 3 [RT 120 FD 150]
任務 3 :八邊形 octagon
REPEAT 8 [RT 45 FD 150]
任務 4
REPEAT 10 [FD 100 REPEAT 5 [FD 50 RT 72] BK 100 RT 36]
任務 6 : 45角星
REPEAT 45 [RT 176 FD 300]
任務 7
FD 200 REPEAT 5 [FD 100 RT 144]
挑戰題
REPEAT 25 [FD 250 REPEAT 25 [FD 50 RT 172.8] RT 172.8]
P.18
第 7章答案 Answers to Section 7
任務 1 / task 1
任務 3 / task 3
REPEAT 360 [RT 1 FD 5] REPEAT 360 [RT 1 FD 4] REPEAT 360 [RT 1 FD 3] REPEAT 360 [RT 1 FD 2] REPEAT 360 [RT 1 FD 1] REPEAT 360 [RT 1 FD 4.5] REPEAT 360 [RT 1 FD 3.5] REPEAT 360 [RT 1 FD 3.5] REPEAT 360 [RT 1 FD 2.5] REPEAT 360 [RT 1 FD 1.5] REPEAT 360 [RT 1 FD 0.5]
任務 5 / Task 5
REPEAT 10[REPEAT 2[REPEAT 90 [RT 1 FD 3] RT 90] RT 36]
REPEAT 10[REPEAT 2[REPEAT 90 [RT 1 FD 3] RT 90] RT 36] REPEAT 10[REPEAT 2[REPEAT 90 [RT 1 FD 2] RT 90] RT 36] REPEAT 10[REPEAT 2[REPEAT 90 [RT 1 FD 1] RT 90] RT 36]
REPEAT 18[FD 10 RT 90 REPEAT 10 [RT 1 FD 3] LT 90 BK 10 RT 90 REPEAT 10[RT 1 FD 2] LT 90]
REPEAT 36[REPEAT 2[REPEAT 90 [RT 1 FD 3] REPEAT 360 [RT 1 FD 1] RT 90] RT 10]
P.19
第 10章答案 Answers to Section 10
任務 1
TO HEXAGON :N REPEAT 6 [REPEAT 3 [FD :N RT 120] RT 60] END HEXAGON 60 HEXAGON 80 HEXAGON 100
任務 2
TO SPIDERMAN :N HEXAGON :N SPIDERMAN :N + 10 END SPIDERMAN 40
任務 3
TO SPIDERMAN :N IF :N > 100 [STOP] HEXAGON :N SPIDERMAN :N + 10 END SPIDERMAN 40