古詩詞大全網 - 成語經典 - logo(小海龜作圖)語言中 towards 命令如何使用變量?

logo(小海龜作圖)語言中 towards 命令如何使用變量?

以下是從logo的幫助文檔裏復制過來的關於towards命令的說明:

TOWARDS

Syntax

TOWARDS [xcoordinate ycoordinate]

Explanation

TOWARDS outputs a number which is the heading necessary for the turtle to rotate from its present position to the new position indicated by its input

list.

SETHEADING TOWARDS [xcoordinate ycoordinate] heads the turtle in the direction of its input list.

我試了壹下,這個命令就是輸出壹個關於方向(角度)的數,用以指明海龜從現在所在的位置點朝向下壹個目標位置點的方向(角度)。如果配合使用seth命令,就可以將海龜的方向直接指向目標點。

比如,海龜現在位於[0 0],如果海龜想要“看”向目標點[30 60],該設定多少度的方向呢?

towards [30 60]的結果是26.57度,這樣,只要使用seth 26.57,就可以設置海龜的方向為26.57度,海龜的頭就朝向目標點[30 60]所在的方向了。

兩個命令可以合起來用,就是 seth towards [30 60],意思就是“將海龜的頭轉向目標點[30 60]所在的方向”。