2014年10月31日 星期五

Class04_Turtle



Class04_Turtle

從 Python 3.4.2 以後,

turtle 模組 已經進昇至 IDLE Help 的一部份了,

讓我們先玩一玩吧。
















../_images/turtle-star.png
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
        break
end_fill()
done()



以下為官方使用說明文件

https://docs.python.org/3.4/library/turtle.html


我把整個 TurtleDemo 的原始程式碼整理成 pdf 檔,
適合印出做參考。

http://goo.gl/pfcZOt


6 則留言:

  1. 回覆
    1. 功課

      1. 解 多元1次 方程式
      2. 找1個 turtle 程式 來跑,講給大家聽



      刪除
  2. from turtle import *
    import turtle_font
    shape("turtle")
    pensize(5)
    penup()
    setup(width=600,height=300)
    setposition(-250,0)
    pendown()
    turtle_font.upper_h()
    turtie_font.lower_i()
    done()



    Traceback (most recent call last):
    File "C:/Users/xxx/Desktop/ex 03.py", line 2, in
    import turtle_font
    ImportError: No module named 'turtle_font'

    回覆刪除
    回覆

    1. 下載以下檔案

      https://gist.github.com/renyuanL/47da5c47c2872c18772a#file-turtle_font-py

      1. 存成檔名 turtle_font.py

      2. 把它含你的程式放在同一個 檔案夾

      3. 再重新執行你的程式看看



      刪除
  3. 原因是這樣:
    你的程式中的第2行:

    import turtle_font

    有要 import 一個 模組 名為 turtle_font,
    該 模組 並非 python 官方提供的,
    因此我們得自己 尋找 或 創造 一個 名為 turtle_font.py 的檔案。
    來做為 此 模組。

    其中 此模組中會 包含
    upper_h() 以及
    lower_i()
    這2個 函數。

    這樣,我們才能使用
    turtle_font.upper_h() 以及
    turtle_font.lower_i()
    這 2 行指令。

    我提供給你的檔案,
    是我從 我們所使用的英文彩色教科書的官網找到的。

    回覆刪除