MS Small Basic第七章: Fun with Shapes(玩形)(Part3: Turtle Graphics)

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.

海龜畫正方形(Turtle.Show( )可省略):

用For迴圈讓程式變簡潔:

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.

全部功能都拿來玩玩看, 加上改變海龜畫筆的顏色(Random):

畫海龜主要考驗數學的幾何圖形與角度計算能力, 腦內要有座標圖, 每寫一個指令, 就要知道海龜往哪跑, 畫出來的圖形才不會跟想像中的差太多.

海龜畫直角三角形:

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其實就是上面那個多層三角形, 困難之處不在寫程式, 在於不知道什麼時候該讓海龜轉彎, 要轉幾度, 要走多長距離, 這些都是數學問題, 不是程式問題, 所以: 數學很重要.

廣告

About leeoxygen

吱吱喳喳,嚕嚕啦啦,嗯嗯啊啊.
本篇發表於 我的Small Basic學習記錄 並標籤為 , 。將永久鏈結加入書籤。

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s