L4K ︰ Logo 神龜之故鄉!!

講起為小朋友設計的編程學習語言,焉能不提及『神龜之故鄉』︰

Logo 語言

Logo 是一種計算機程式設計語言,在1966年由西摩爾·派普特 和Wally Feurzeig 在 BNN 設計,設計 Logo 的初衷是為了向兒童教授計算機編程技能。Logo 一詞源自希臘語邏各斯(logos)。

Logo 的原型來自另一個計算機語言 LISP ,派普特修改了 LISP 的語法使得他更易於閱讀。Logo 通常被稱作沒有括號的 Lisp 。

Logo 是一種直譯語言,和其它的語言不同,它內置一套海龜繪圖(Turtle Graphics)系統,通過向海龜發送命令,用戶可以直觀地學習程序的運行過程,因此它很適合於兒童學習。它亦適合作數學教學。

Logo 繼承了 Lisp 的「表」的概念,所以在函數處理等方面擁有強大的能力,因此 Logo 不僅是初學者學習程序設計的良藥,更是有特殊需求計算機科學家的助手。

300px-remi_turtlegrafik

Logo 海龜繪圖

Logo (programming language)

History

Logo was created in 1967 at Bolt, Beranek and Newman (BBN), a Cambridge, Massachusetts research firm, by Wally Feurzeig and Seymour Papert.[5] Its intellectual roots are in artificial intelligence, mathematical logic and developmental psychology. The first four years of Logo research, development and teaching work was done at BBN. The first implementation of Logo, called Ghost, was written in LISP on a PDP-1. The goal was to create a mathematical land where children could play with words and sentences.[6] Modeled on LISP, the design goals of Logo included accessible power[clarification needed] and informative error messages. The use of virtual Turtles allowed for immediate visual feedback and debugging of graphic programming.

The first working Logo turtle robot was created in 1969. A display turtle preceded the physical floor turtle. Modern Logo has not changed too much from the basic concepts before the first turtle. The first turtle was a tethered floor roamer, not radio-controlled or wireless. At BBN Paul Wexelblat developed a turtle named Irving that had touch sensors and could move forwards, backwards, rotate, and ding its bell. The earliest year-long school users of Logo were in 1968-69 at Muzzey Jr High, Lexington MA. The virtual and physical turtles were first used by fifth graders at the Bridge School in Lexington, MA in 1970-71.

Turtle and graphics

See also: Turtle graphics

Logo’s most-known feature is the turtle (derived originally from a robot of the same name),[7] an on-screen “cursor” that showed output from commands for movement and small retractable pen, together producing line graphics. It has traditionally been displayed either as a triangle or a turtle icon (though it can be represented by any icon). Turtle graphics were added to the Logo language by Seymour Papert in the late 1960s to support Papert’s version of the turtle robot, a simple robot controlled from the user’s workstation that is designed to carry out the drawing functions assigned to it using a small retractable pen set into or attached to the robot’s body.

As a practical matter, the use of turtle geometry instead of a more traditional model mimics the actual movement logic of the turtle robot. The turtle moves with commands that are relative to its own position, LEFT 90 means spin left by 90 degrees. Some Logo implementations, particularly those that allow the use of concurrency and multiple turtles, support collision detection and allow the user to redefine the appearance of the turtle cursor, essentially allowing the Logo turtles to function as sprites.

Multiple turtles are supported by MSWLogo, as well as 3D graphics. Input from COM ports and LPT ports are also allowed by MSWLogo through windows GUI. Interrupts can be triggered via keyboard and mouse events. Simple GIF animations may also be produced on MSWLogo version 6.5 with the gifsave command.

Turtle geometry is also sometimes used in environments other than Logo as an alternative to a strictly coordinate-addressed graphics system. For instance, the idea of turtle graphics is also useful in Lindenmayer system for generating fractals.

 

的呢??這裡先以樹莓派上容易安裝

sudo apt-get install turtleart

TurtleArt

Welcome to TurtleArt!

TurtleArt lets you make images with your computer. The Turtle follows a sequence of commands. You specify the sequence by snapping together puzzle like blocks. The blocks can tell the turtle to draw lines and arcs, draw in different colors, go to a specific place on the screen, etc. There are also blocks that let you repeat or name sequences. Other blocks perform logical operations.

The sequence of blocks as a program that describes an image. This kind of programming is inspired by the LOGO programming language. It was designed to be easy enough for children and yet powerful enough for people of all ages. TurtleArt is focused on making images while allowing you to explore geometry and programming.

turtle-art-arc-moves-turtle-along-an-arc

 

,擬現洛水神龜之風采︰

Adrian Toncean 先生在 GitHub 上發表了一個用 javascript 寫的『lindenmayer-power』的 L 系統,其中使用小海龜繪圖法。於此我們將簡單介紹這個軟體的使用方法︰

程式由『文法輸入』Grammar input 和『命令輸入』Commands input 兩個部份組成。文法輸入使用『脈絡無關之隨機的文法』stocastic context-free grammars,按造所給的例子︰

-> Start
0.2 Number
0.4 Start + Start
0.3 Start – Start
0.1 ( Start )
-> Number
0.1 0
0.1 1
0.1 2
0.7 3

改 寫規則── 『非終端』nonterminal 字詞符號 ── 是用『->規則名稱』起始定義,比如這裡的『Start』,接著是『【機率大小】 【使用之改寫規則名稱或字詞符號】』,指定將被『使用之改寫規則』的機率數值,軟體會自動作『歸一化』,所以你只需管機率大小數值就好,不必理會是不是所 有被定義的 規則加總起來是『1』。比方例子中,『Start』改寫規則有︰

20% 的機會使用『Number』改寫規則
40% 的機會改寫成『【Start 】【+ 】【Start 】』,此處【Start 】就是『Start』改寫規則,而『+』是叫做『終端』 terminal 任意字詞符號,也就是說它不是一個改寫規則 。

如 此依次定義改寫規則完成整個文法輸入。當按 Generate 鍵時,軟體將依據此『文法輸入』以及指定『層次』level 產生整個改寫字串。這個過程中每個非終端符號必被改寫,看起來可能像 Start \rightarrow Start + Start \rightarrow Number + ( Start ) \rightarrow  3 + ( Start - Start )  \dots

洛書

Turtle

L3

L2

images

子虛先生說︰昔時洛水有神龜,總於晨昏之時,彩雲滿天之際,游於洛水之波光霞影之中。興起就神足直行,左旋右轉飛舞迴旋,那時波濤不起漣漪不見,河面只隨神龜尾上下,或粗或細或長或短或直或曲契刻成圖文。一日大禹治水偶經洛水恰遇神龜,神龜感念大禹昔日洩洪疏河之恩,特演平日最得意水畫之作,所以歷史才傳說『大禹得洛書』。

雖然作者以為子虛先生所說乃是烏有之言,然而他卻把『小海龜』繪圖法的精神描寫的活靈活現。小海龜頭的朝向決定它『前進』的方向,『【向前】【數值】 』表示向前走多少單位距離的指令,比方 forward 10,是說向前走十個單位。除了直行之外小海龜還可以『轉向』,這個轉向是依據當前之前進的方向『左轉』或是『右轉』,用『【旋轉】【角度】』表示,比方 rotate 90 是說右轉九十度, 而 rotate -90 是講左轉九十度。小海龜在網頁上的『位置』是由網頁上的 (X,Y) 座標來決定的,它的設定是『左上』(0,0)和『右下』 (600,600) 。小海龜當下的『狀態』state 是由『現在』的『位置』與『朝向角度』所一起決定的,這也就是『存上堆疊』push 與『堆疊取回』pop 存上取回指令裡所說的狀態。小海龜可以給定一個『開始』的『位置』與『朝向』,初進網頁時它在 (50,300),小海龜的頭朝右,它的角度是 0。

比方說下面的例子畫出一個正三角形︰

【文法輸入】︰
-> T
1 F – F – F

文法輸入後按 Read 鍵讀取。然後設定 levels 為 1 ,按 Generate 鍵產生文法的【輸出 Output】︰

T
F – F – F

每一個『終端符號』都給與一個『小海龜程式』,以『【:】【空白】【終端符號】』為定義起始,是說遇見這個終端符號時,將會執行程式裡的哪些小海龜命令。

【命令輸入】︰
:  F
forward 100
:  –
rotate -120

命令輸入後,按 Draw 鍵開始繪圖。請參考 Adrian Toncean 先生的網頁說明以及更多的程式範例。假使還不知道『改寫系統』是什麼的讀者,建議先閱讀『Thue 之改寫系統系列』。

─── 摘自《科赫傳說!!

 

,說說語言與寫作之眉眉角角☆