Lesson 2.2: Turtle Graphics
海龜繪圖在使用手冊是第八章的內容, 在此先預習. In this lesson, you will learn about:
- Moving the Turtle on the screen by using the Turtle object.
- Creating graphics by using the various properties and operations of the Turtle object.
- Drawing colorful designs by using the Turtle object in For..EndFor loops.
Properties and Operations of the Turtle Object
- To set the location of the Turtle on the screen, you use the X and Y properties of the Turtle object.
- To move the Turtle a particular distance in pixels, you use the Move operation. To move the Turtle to a particular location, you use the MoveTo operation and its parameters to specify the new location.
- To draw with the Turtle, you use the PenDown operation. To stop drawing with the Turtle, you use the PenUp operation.
- To specify the location at which the Turtle appears or a location to which the Turtle moves, you include the x-coordinate and the y-coordinate of the location that you want.
- You can set the speed of the Turtle by using the Speed property and specifying a value between 1 and 10. (To see the Turtle’s fastest speed, specify 10.)
- You can rotate the Turtle by using the Turn operation and specifying an angle in degrees. As an alternative, you can rotate the Turtle 90 degrees by using the TurnRight or TurnLeft operations,respectively.
- You can turn the Turtle to a specific angle of rotation by using the Angle property and specifying the angle of rotation in degrees. By default, the Turtle faces the top of the screen, which is an angle of 0 degrees.
畫海龜主要考驗數學的幾何圖形與角度計算能力, 腦內要有座標圖, 每寫一個指令, 就要知道海龜往哪跑, 畫出來的圖形才不會跟想像中的差太多.
Having Fun with the Turtle
底下就參考微軟網路自學教材Lesson 2.2: Turtle Graphics給的範例, 並修改其中幾行指令, 實做看看海龜會怎麼跑:
最後我在教材上看到一句話: “You can also create nested versions of different shapes, such as triangles, by assigning a For loop and changing the distance and the angles." Nested triangles其實就是上面那個多層三角形, 困難之處不在寫程式, 在於不知道什麼時候該讓海龜轉彎, 要轉幾度, 要走多長距離, 這些都是數學問題, 不是程式問題, 所以: 數學很重要.