L4K ︰ Python Turtle《二》

道德經‧六十四章

其安易持,其未兆易謀。其脆易泮,其微易散。為之於未有,治之於未亂。合抱之木,生於毫末;九層之臺,起於累土;千里之行,始於足下。為者敗之,執者失之。是以聖人無為故無敗;無執故無失。民之從事,常於幾成而敗之。慎終如始,則無敗事,是以聖人欲不欲,不貴難得之貨;學不學,復衆人之所過,以輔萬物之自然 ,而不敢為。

 

『重複』 repeat 之概念深矣。積步能至千里,故而易曰︰

馴致其道,至堅冰也。

︰初六:履霜,堅冰至。
象傳︰履霜堅冰,陰始凝也。馴致其道,至堅冰也。

 

怎麼體會『簡單行為』之『重複』所產生的『壯觀現象』耶?想起早年讀過之一本很有啟發性的書︰

Turtle Geometry

The Computer as a Medium for Exploring Mathematics

Overview

Turtle Geometry presents an innovative program of mathematical discovery that demonstrates how the effective use of personal computers can profoundly change the nature of a student’s contact with mathematics. Using this book and a few simple computer programs, students can explore the properties of space by following an imaginary turtle across the screen.The concept of turtle geometry grew out of the Logo Group at MIT. Directed by Seymour Papert, author of Mindstorms, this group has done extensive work with preschool children, high school students and university undergraduates. Harold Abelson is an associate professor in the Department of Electrical Engineering and Computer Science at MIT. Andrea diSessa is an associate professor in the Graduate School of Education, University of California, Berkeley.

9780262510370

 

書裡有個範例,頗能展現個中三昧,特以 Python3 Turtle 將之改寫 ,映此歲末年終之思夫︰

pi@raspberrypi:~ $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
>>> turtle.setup(width=800, height=600)
>>> turtle.shape('turtle')
>>> turtle.mode('logo')
>>> 
>>> def thing():
...     turtle.forward(100)
...     turtle.right(90)
...     turtle.forward(100)
...     turtle.right(90)
...     turtle.forward(50)
...     turtle.right(90)
...     turtle.forward(50)
...     turtle.right(90)
...     turtle.forward(100)
...     turtle.right(90)
...     turtle.forward(25)
...     turtle.right(90)
...     turtle.forward(25)
...     turtle.right(90)
...     turtle.forward(50)
... 
>>> thing()
>>> turtle.reset()
>>> 
>>> def thing1():
...     for repeat in range(4):
...         thing()
... 
>>> thing1()
>>> turtle.reset()
>>> 
>>> def thing2():
...     for repeat in range(9):
...         thing()
...         turtle.right(10)
...         turtle.forward(50)
... 
>>> thing2()
>>> turtle.reset()
>>> 
>>> def thing3():
...     for repeat in range(8):
...         thing()
...         turtle.left(45)
...         turtle.forward(100)
... 
>>> thing3()
>>> 

 

【Thing】

python-turtle-graphics_thing

 

【Thing1】

python-turtle-graphics_thing1

 

【Thing2】

python-turtle-graphics_thing2

 

【Thing3】

python-turtle-graphics_thing3