Cách hiển thị tọa độ trong Python

Đồ họa con rùa là một cách phổ biến để giới thiệu lập trình cho trẻ em. Nó là một phần của ngôn ngữ lập trình Logo ban đầu được phát triển bởi Wally Feurzeig, Seymour Papert và Cynthia Solomon vào năm 1967

Hãy tưởng tượng một con rùa robot bắt đầu từ [0, 0] trong mặt phẳng x-y. Sau một

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
9, hãy cho nó lệnh
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
0, và nó di chuyển [trên màn hình. ] 15 pixel theo hướng mà nó hướng tới, vẽ một đường khi nó di chuyển. Đưa cho nó lệnh
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1, và nó xoay tại chỗ 25 độ theo chiều kim đồng hồ

rùa sao

Rùa có thể vẽ các hình phức tạp bằng các chương trình lặp lại các bước di chuyển đơn giản

from turtle import *
color['red', 'yellow']
begin_fill[]
while True:
    forward[200]
    left[170]
    if abs[pos[]] >> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
3

Mô-đun rùa cung cấp các nguyên mẫu đồ họa rùa, theo cả hai cách hướng đối tượng và hướng thủ tục. Bởi vì nó sử dụng cho đồ họa cơ bản, nên nó cần cài đặt phiên bản Python có hỗ trợ Tk

Giao diện hướng đối tượng về cơ bản sử dụng hai+hai lớp

  1. Lớp định nghĩa cửa sổ đồ họa là sân chơi cho rùa vẽ. Hàm tạo của nó cần một đối số

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    6 hoặc as. Nó nên được sử dụng khi được sử dụng như một phần của một số ứng dụng

    Hàm trả về một đối tượng đơn lẻ của một lớp con. Chức năng này nên được sử dụng khi được sử dụng như một công cụ độc lập để làm đồ họa. Là một đối tượng đơn lẻ, không thể kế thừa từ lớp của nó

    Tất cả các phương thức của TurtleScreen/Screen cũng tồn tại dưới dạng hàm, tôi. e. như một phần của giao diện hướng thủ tục

  2. [bí danh. ] định nghĩa các đối tượng Rùa vẽ trên một. Hàm tạo của nó cần một Canvas, ScrolledCanvas hoặc TurtleScreen làm đối số, vì vậy các đối tượng RawTurtle biết nơi để vẽ

    Bắt nguồn từ RawTurtle là lớp con [bí danh.

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.forward[25]
    >>> turtle.position[]
    [25.00,0.00]
    >>> turtle.forward[-75]
    >>> turtle.position[]
    [-50.00,0.00]
    
    06], dựa trên “thực thể” được tạo tự động, nếu chưa có

    Tất cả các phương thức của RawTurtle/Turtle cũng tồn tại dưới dạng hàm, tôi. e. một phần của giao diện hướng thủ tục

Giao diện thủ tục cung cấp các chức năng bắt nguồn từ các phương thức của các lớp và. Chúng có cùng tên với các phương thức tương ứng. Một đối tượng màn hình được tạo tự động bất cứ khi nào một hàm bắt nguồn từ phương thức Màn hình được gọi. Một đối tượng rùa [chưa được đặt tên] được tạo tự động bất cứ khi nào bất kỳ hàm nào bắt nguồn từ phương thức Rùa được gọi

Để sử dụng nhiều con rùa trên một màn hình, người ta phải sử dụng giao diện hướng đối tượng

Ghi chú

Trong tài liệu sau đây, danh sách đối số cho các hàm được đưa ra. Tất nhiên, các phương thức có đối số đầu tiên bổ sung self được bỏ qua ở đây

Tổng quan về các phương pháp Con rùa và Màn hình có sẵn

phương pháp rùa

Chuyển động của rùa Di chuyển và vẽ

.

. .

.

.

. .

.

Cho biết trạng thái của Rùa

.

Cài đặt và đo lường

Điều khiển bút Trạng thái vẽ

. .

. .

.

Kiểm soát màu sắc

đổ đầy

Kiểm soát bản vẽ nhiều hơn

Trạng thái rùaKhả năng hiển thị

.

.

Vẻ bề ngoài

.

Sử dụng các sự kiện

Phương pháp rùa đặc biệt

.

Phương pháp của TurtleScreen/Screen

Kiểm soát cửa sổ

kiểm soát hoạt ảnh

Sử dụng các sự kiện màn hình

.

.

.

Cài đặt và phương pháp đặc biệt

.

Phương thức nhập liệu

Các phương pháp dành riêng cho Màn hình

Các phương thức của RawTurtle/Turtle và các hàm tương ứng

Hầu hết các ví dụ trong phần này đề cập đến một cá thể Rùa có tên là

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
8

chuyển động rùa

rùa. về phía trước[khoảng cách]rùa. fd[khoảng cách] Tham số

khoảng cách – một số [số nguyên hoặc số thực]

Di chuyển rùa về phía trước theo khoảng cách xác định, theo hướng rùa đang đi

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]

rùa. lùi lại[khoảng cách]rùa. bk[khoảng cách]rùa. lùi[khoảng cách] Tham số

khoảng cách - một con số

Di chuyển rùa lùi một đoạn, ngược với hướng rùa đi. Không thay đổi tiêu đề của rùa

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]

rùa. phải[góc]rùa. rt[góc] Tham số

góc – một số [số nguyên hoặc số float]

Xoay rùa sang phải theo đơn vị góc. [Các đơn vị theo độ mặc định, nhưng có thể được thiết lập thông qua chức năng và. ] Định hướng góc phụ thuộc vào chế độ con rùa, xem

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0

rùa. trái[góc]rùa. lt[góc] Tham số

góc – một số [số nguyên hoặc số float]

Xoay rùa sang trái theo đơn vị góc. [Các đơn vị theo độ mặc định, nhưng có thể được thiết lập thông qua chức năng và. ] Định hướng góc phụ thuộc vào chế độ con rùa, xem

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0

rùa. goto[x , y . =None]turtle.đặt vị trí[x , y . =None]turtle.vị trí đặt[x , y=None]Parameters
  • x – một số hoặc một cặp/vectơ số

  • y – một số hoặc

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29

Nếu y là

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, x phải là một cặp tọa độ hoặc một [e. g. như được trả về bởi ]

Di chuyển rùa đến một vị trí tuyệt đối. Nếu bút xuống, vẽ đường. Không thay đổi hướng của rùa

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]

rùa. setx[x] Tham số

x – một số [số nguyên hoặc số thực]

Đặt tọa độ đầu tiên của rùa thành x, giữ nguyên tọa độ thứ hai

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]

rùa. sety[y] Tham số

y – một số [số nguyên hoặc số thực]

Đặt tọa độ thứ hai của rùa thành y, giữ nguyên tọa độ đầu tiên

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]

rùa. tiêu đề[to_angle]rùa. seth[to_angle] Tham số

to_angle – một số [số nguyên hoặc số thực]

Đặt hướng của rùa thành to_angle. Dưới đây là một số hướng phổ biến theo độ

chế độ căn bản

chế độ logo

0 - đông

0 - bắc

90 - bắc

90 - đông

180 - tây

180 - nam

270 - nam

270 - tây

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0

rùa. nhà[]

Di chuyển con rùa đến điểm gốc – tọa độ [0,0] – và đặt tiêu đề của nó thành hướng bắt đầu [tùy thuộc vào chế độ, xem phần ]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0

rùa. hình tròn[bán kính , phạm vi=None, steps=None]Parameters
  • bán kính - một số

  • phạm vi – một số [hoặc

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29]

  • các bước – một số nguyên [hoặc

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29]

Vẽ đường tròn có bán kính cho trước. Trung tâm là các đơn vị bán kính bên trái của con rùa; . Nếu phạm vi không được đưa ra, hãy vẽ toàn bộ vòng tròn. Nếu phạm vi không phải là một vòng tròn đầy đủ, một điểm cuối của vòng cung là vị trí bút hiện tại. Vẽ cung theo hướng ngược chiều kim đồng hồ nếu bán kính dương, ngược lại theo chiều kim đồng hồ. Cuối cùng, hướng của rùa được thay đổi theo mức độ

Vì hình tròn được xấp xỉ bằng một đa giác đều nội tiếp, các bước xác định số bước sẽ sử dụng. Nếu không được cung cấp, nó sẽ được tính toán tự động. Có thể được sử dụng để vẽ đa giác thông thường

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
0

rùa. chấm[kích thước=Không, *color]Parameters
  • size – một số nguyên >= 1 [nếu có]

  • màu – một chuỗi màu hoặc một bộ màu số

Vẽ một chấm tròn có kích thước đường kính, sử dụng màu. Nếu kích thước không được cung cấp, thì tối đa pensize+4 và 2*pensize được sử dụng

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
1

rùa. đóng dấu[]

Đóng dấu một bản sao của hình con rùa lên canvas ở vị trí con rùa hiện tại. Trả lại một tem_id cho tem đó, có thể được sử dụng để xóa nó bằng cách gọi

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
36

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
2

rùa. dấu xóa[dấu] Tham số

temid - một số nguyên, phải là giá trị trả về của cuộc gọi trước đó

Xóa tem với tem đã cho

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
3

rùa. dấu xóa[n=Không]Parameters

n – một số nguyên [hoặc

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29]

Xóa tất cả hoặc n tem đầu tiên/cuối cùng của rùa. Nếu n là

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, xóa tất cả tem, nếu n > 0 xóa n tem đầu tiên, ngược lại nếu n < 0 xóa n tem cuối cùng

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
4

rùa. hoàn tác[]

Hoàn tác [nhiều lần] [các] hành động rùa cuối cùng. Số lượng hành động hoàn tác khả dụng được xác định bởi kích thước của bộ đệm hoàn tác

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
5

rùa. tốc độ[tốc độ=Không]Parameters

tốc độ – một số nguyên trong phạm vi 0. 10 hoặc dây tốc độ [xem bên dưới]

Đặt tốc độ của rùa thành một giá trị nguyên trong phạm vi 0. 10. Nếu không có đối số nào được đưa ra, hãy trả về tốc độ hiện tại

Nếu đầu vào là một số lớn hơn 10 hoặc nhỏ hơn 0. 5, tốc độ được đặt thành 0. Dây tốc độ được ánh xạ tới các giá trị tốc độ như sau

  • “nhanh nhất”. 0

  • "Nhanh". 10

  • "thông thường". 6

  • "chậm". 3

  • “chậm nhất”. 1

Tốc độ từ 1 đến 10 thực thi hoạt ảnh vẽ đường thẳng và xoay rùa ngày càng nhanh hơn

Chú ý. tốc độ = 0 có nghĩa là không có hoạt ảnh nào diễn ra. tiến/lùi khiến rùa nhảy và tương tự trái/phải khiến rùa quay ngay lập tức

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
6

Cho biết trạng thái của Rùa

rùa. vị trí[]rùa. tư thế[]

Trả về vị trí hiện tại của rùa [x,y] [dưới dạng vectơ]

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
7

rùa. về phía[x , y=None]Parameters
  • x – một số hoặc một cặp/vec-tơ số hoặc một cá thể rùa

  • y – một số nếu x là một số, ngược lại

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29

Trả lại góc giữa đường từ vị trí con rùa đến vị trí được chỉ định bởi [x,y], vectơ hoặc con rùa khác. Điều này phụ thuộc vào hướng bắt đầu của rùa, tùy thuộc vào chế độ - “tiêu chuẩn”/”thế giới” hoặc “logo”

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
8

rùa. xcor[]

Trả về tọa độ x của con rùa

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
9

rùa. ycor[]

Trả về tọa độ y của rùa

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
0

rùa. tiêu đề[]

Trả về tiêu đề hiện tại của rùa [giá trị tùy thuộc vào chế độ rùa, xem phần ]

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
1

rùa. khoảng cách[x , y=None]Parameters
  • x – một số hoặc một cặp/vec-tơ số hoặc một cá thể rùa

  • y – một số nếu x là một số, ngược lại

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29

Trả về khoảng cách từ con rùa đến [x,y], vectơ đã cho hoặc con rùa đã cho khác, theo đơn vị bước rùa

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
2

Cài đặt để đo lường

rùa. độ[vòng tròn=360. 0] Tham số

hình tròn – một số

Đặt đơn vị đo góc, i. e. đặt số "độ" cho một vòng tròn đầy đủ. Giá trị mặc định là 360 độ

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
3

rùa. radian[]

Đặt đơn vị đo góc thành radian. Tương đương với

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
44

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
4

điều khiển bút

Trạng thái bản vẽ

rùa. xuống dốc[]rùa. pd[]rùa. xuống[]

Kéo bút xuống – vẽ khi di chuyển

rùa. bút chì[]rùa. pu[]rùa. lên[]

Kéo bút lên – không vẽ khi di chuyển

rùa. kích thước[chiều rộng=Không có . ]turtle.chiều rộng[chiều rộng=Không có]Parameters

chiều rộng – một số dương

Đặt độ dày của đường thành chiều rộng hoặc trả lại. Nếu chế độ thay đổi kích thước được đặt thành “tự động” và hình con rùa là một đa giác, thì đa giác đó được vẽ với cùng độ dày nét vẽ. Nếu không có đối số nào được đưa ra, thì pensize hiện tại được trả về

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
5

rùa. bút[bút=Không có, **pendict]Parameters
  • bút – một từ điển với một số hoặc tất cả các phím được liệt kê bên dưới

  • pendict – một hoặc nhiều đối số từ khóa với các khóa được liệt kê bên dưới làm từ khóa

Trả lại hoặc đặt các thuộc tính của bút trong “từ điển bút” với các cặp khóa/giá trị sau

  • "cho xem". Đúng sai

  • "đặt bút xuống". Đúng sai

  • “màu bút”. chuỗi màu hoặc bộ màu

  • "tô màu". chuỗi màu hoặc bộ màu

  • “bù”. số dương

  • "tốc độ". số trong phạm vi 0. 10

  • "chế độ thay đổi kích thước". “tự động” hoặc “người dùng” hoặc “noresize”

  • "máy kéo dài". [số dương, số dương]

  • "đề cương". số dương

  • “nghiêng”. số

Từ điển này có thể được sử dụng làm đối số cho lệnh gọi tiếp theo để khôi phục trạng thái bút cũ. Ngoài ra, một hoặc nhiều thuộc tính này có thể được cung cấp dưới dạng đối số từ khóa. Điều này có thể được sử dụng để đặt một số thuộc tính bút trong một câu lệnh

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
6

rùa. ngừng hoạt động[]

Trả lại

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
46 nếu bút xuống,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
47 nếu bút lên

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
7

Kiểm soát màu sắc

rùa. bút màu[*args]

Trả lại hoặc đặt màu bút

Bốn định dạng đầu vào được cho phép

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
54

Trả về pencolor hiện tại dưới dạng chuỗi đặc tả màu hoặc dưới dạng bộ [xem ví dụ]. Có thể được sử dụng làm đầu vào cho lệnh gọi color/pencolor/fillcolor khác

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
49

Đặt pencolor thành chuỗi màu, là chuỗi đặc tả màu Tk, chẳng hạn như

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
50,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
51 hoặc
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
52

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
53

Đặt pencolor thành màu RGB được biểu thị bằng bộ của r, g và b. Mỗi r, g và b phải nằm trong phạm vi 0. colormode, trong đó colormode là 1. 0 hoặc 255 [xem ]

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
55

Đặt pencolor thành màu RGB được biểu thị bằng r, g và b. Mỗi r, g và b phải nằm trong phạm vi 0. chế độ màu

Nếu hình con rùa là một đa giác, thì đường viền của đa giác đó được vẽ bằng bút màu mới được đặt

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
8

rùa. màu tô[*args]

Trả lại hoặc đặt màu tô

Bốn định dạng đầu vào được cho phép

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
55

Trả về màu tô hiện tại dưới dạng chuỗi đặc tả màu, có thể ở định dạng tuple [xem ví dụ]. Có thể được sử dụng làm đầu vào cho lệnh gọi color/pencolor/fillcolor khác

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
57

Đặt màu tô thành chuỗi màu, là chuỗi đặc tả màu Tk, chẳng hạn như

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
50,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
51 hoặc
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
52

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
61

Đặt màu tô thành màu RGB được biểu thị bằng bộ của r, g và b. Mỗi r, g và b phải nằm trong phạm vi 0. colormode, trong đó colormode là 1. 0 hoặc 255 [xem ]

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
63

Đặt màu tô thành màu RGB được biểu thị bằng r, g và b. Mỗi r, g và b phải nằm trong phạm vi 0. chế độ màu

Nếu hình con rùa là một đa giác, phần bên trong của đa giác đó được vẽ bằng màu tô mới được đặt

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
9

rùa. màu[*args]

Trả lại hoặc đặt pencolor và fillcolor

Một số định dạng đầu vào được cho phép. Họ sử dụng 0 đến 3 đối số như sau

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
53

Trả về màu bút hiện tại và màu tô hiện tại dưới dạng một cặp chuỗi hoặc bộ đặc tả màu khi được trả về bởi và

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
67,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
68,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
69

Các đầu vào như trong , đặt cả hai, màu tô và màu bút, thành giá trị đã cho

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
71,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
72

Tương đương với

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
73 và
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
74 và tương tự nếu định dạng đầu vào khác được sử dụng

Nếu hình con rùa là một đa giác, đường viền và phần bên trong của đa giác đó được vẽ bằng các màu mới được đặt

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
0

Xem thêm. phương pháp màn hình

đổ đầy

rùa. điền[]

Trả về trạng thái điền [

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
46 nếu điền,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
47 khác]

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
1

rùa. begin_fill[]

Được gọi ngay trước khi vẽ một hình cần tô

rùa. end_fill[]

Tô màu cho hình được vẽ sau lần gọi cuối cùng đến

Việc các vùng chồng lấp cho đa giác tự giao nhau hoặc nhiều hình có được lấp đầy hay không tùy thuộc vào đồ họa của hệ điều hành, loại chồng lấp và số lượng chồng lấp. Ví dụ: ngôi sao Rùa ở trên có thể toàn màu vàng hoặc có một số vùng màu trắng

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
2

Kiểm soát bản vẽ nhiều hơn

rùa. đặt lại[]

Xóa hình vẽ của rùa khỏi màn hình, căn giữa lại rùa và đặt các biến về giá trị mặc định

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
3

rùa. xóa[]

Xóa hình vẽ của rùa khỏi màn hình. Đừng di chuyển rùa. Trạng thái và vị trí của rùa cũng như hình vẽ của các loài rùa khác không bị ảnh hưởng

rùa. viết[arg , di chuyển=False, align='left', font=['Arial', 8, 'normal']]Parameters
  • arg – đối tượng được ghi vào TurtleScreen

  • di chuyển – Đúng/Sai

  • căn chỉnh – một trong các chuỗi “trái”, “trung tâm” hoặc phải”

  • phông chữ – một bộ ba [tên phông chữ, cỡ chữ, loại phông chữ]

Viết văn bản - biểu diễn chuỗi của arg - tại vị trí con rùa hiện tại theo căn chỉnh [“trái”, “giữa” hoặc “phải”] và với phông chữ đã cho. Nếu di chuyển là đúng, bút sẽ được di chuyển đến góc dưới cùng bên phải của văn bản. Theo mặc định, di chuyển là

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
47

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
4

bang con rùa

Hiển thị

rùa. con rùa ẩn nấp[]con rùa. ht[]

Làm cho con rùa vô hình. Bạn nên làm điều này khi đang thực hiện một số bản vẽ phức tạp, bởi vì việc ẩn con rùa sẽ tăng tốc độ vẽ một cách đáng kể

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
5

rùa. rùa chiếu[]rùa. st[]

Làm cho con rùa có thể nhìn thấy

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
6

rùa. hiển thị[]

Quay trở lại

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
46 nếu Rùa được hiển thị,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
47 nếu nó bị ẩn

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
7

Vẻ bề ngoài

rùa. hình dạng[tên=Không có]Parameters

tên - một chuỗi là một shapename hợp lệ

Đặt hình dạng con rùa thành hình dạng với tên đã cho hoặc, nếu tên không được đặt, hãy trả về tên của hình dạng hiện tại. Hình dạng có tên phải tồn tại trong từ điển hình dạng của TurtleScreen. Ban đầu có các hình đa giác sau. “mũi tên”, “con rùa”, “hình tròn”, “hình vuông”, “hình tam giác”, “cổ điển”. Để tìm hiểu về cách xử lý các hình, hãy xem Phương pháp màn hình

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
8

rùa. resizemode[rmode=Không có]Parameters

rmode – một trong các chuỗi “auto”, “user”, “noresize”

Đặt resizemode thành một trong các giá trị. “tự động”, “người dùng”, “noresize”. Nếu rmode không được cung cấp, hãy trả về resizemode hiện tại. Các chế độ thay đổi kích thước khác nhau có các hiệu ứng sau

  • "Tự động". điều chỉnh sự xuất hiện của con rùa tương ứng với giá trị của pensize

  • "người sử dụng". điều chỉnh sự xuất hiện của con rùa theo các giá trị của hệ số kéo dài và chiều rộng đường viền [đường viền], được đặt bởi

  • “noresize”. không có sự thích nghi nào về ngoại hình của con rùa diễn ra

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
84 được gọi bởi khi được sử dụng với các đối số

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
9

rùa. kích thước hình dạng[stretch_wid=Không có . , stretch_len=None, outline=None]turtle.kích thước rùa[stretch_wid=Không có, stretch_len=None, outline=None]Parameters
  • stretch_wid – số dương

  • stretch_len – số dương

  • đại cương – số dương

Trả lại hoặc đặt các thuộc tính x/y-stretchfactors và/hoặc phác thảo của bút. Đặt resizemode thành “người dùng”. Khi và chỉ khi chế độ thay đổi kích thước được đặt thành "người dùng", con rùa sẽ được hiển thị kéo dài theo các yếu tố kéo dài của nó. stretch_wid là hệ số giãn vuông góc với hướng của nó, stretch_len là hệ số giãn theo hướng của hướng của nó, đường viền xác định chiều rộng của đường viền của hình dạng

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
0

rùa. máy cắt[máy cắt=Không có]Parameters

cắt - số [tùy chọn]

Đặt hoặc trả lại shearfactor hiện tại. Cắt hình rùa theo lực cắt shearfactor đã cho, là tiếp tuyến của góc cắt. Không thay đổi tiêu đề của rùa [hướng di chuyển]. Nếu cắt không được đưa ra. trả lại shearfactor hiện tại, tôi. e. tiếp tuyến của góc cắt, theo đó các đường song song với tiêu đề của con rùa bị cắt

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
1

rùa. độ nghiêng[góc] Tham số

góc – một số

Xoay hình con rùa theo góc so với góc nghiêng hiện tại của nó, nhưng không thay đổi hướng của con rùa [hướng di chuyển]

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
2

rùa. settiltangle[góc] Tham số

góc – một số

Xoay hình con rùa để chỉ theo hướng được chỉ định theo góc, bất kể góc nghiêng hiện tại của nó là gì. Không thay đổi tiêu đề của rùa [hướng di chuyển]

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
3

Không dùng nữa kể từ phiên bản 3. 1

rùa. nghiêng[góc=Không có]Parameters

góc – một số [tùy chọn]

Đặt hoặc trả lại góc nghiêng hiện tại. Nếu góc được đưa ra, hãy xoay hình con rùa để chỉ theo hướng được chỉ định bởi góc, bất kể góc nghiêng hiện tại của nó là gì. Không thay đổi tiêu đề của rùa [hướng di chuyển]. Nếu góc không được đưa ra. trả lại góc nghiêng hiện tại, tôi. e. the angle between the orientation of the turtleshape and the heading of the turtle [its direction of movement]

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
4

turtle. shapetransform[t11=None , t12=None , t21=None , t22=None] Parameters
  • t11 – a number [optional]

  • t12 – a number [optional]

  • t21 – a number [optional]

  • t12 – a number [optional]

Set or return the current transformation matrix of the turtle shape

If none of the matrix elements are given, return the transformation matrix as a tuple of 4 elements. Otherwise set the given elements and transform the turtleshape according to the matrix consisting of first row t11, t12 and second row t21, t22. The determinant t11 * t22 - t12 * t21 must not be zero, otherwise an error is raised. Modify stretchfactor, shearfactor and tiltangle according to the given matrix

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
5

turtle. get_shapepoly[]

Return the current shape polygon as tuple of coordinate pairs. This can be used to define a new shape or components of a compound shape

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
6

Sử dụng các sự kiện

turtle. title[fun , btn=1 , add=None] Parameters
  • fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas

  • btn – number of the mouse-button, defaults to 1 [left mouse button]

  • add –

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46 or
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    47 – if
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46, a new binding will be added, otherwise it will replace a former binding

Bind fun to mouse-click events on this turtle. If fun is

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, existing bindings are removed. Example for the anonymous turtle, i. e. the procedural way

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
7

turtle. onrelease[fun , btn=1 , add=None] Parameters
  • fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas

  • btn – number of the mouse-button, defaults to 1 [left mouse button]

  • add –

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46 or
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    47 – if
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46, a new binding will be added, otherwise it will replace a former binding

Bind fun to mouse-button-release events on this turtle. If fun is

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, existing bindings are removed

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
8

turtle. ondrag[fun , btn=1 , add=None] Parameters
  • fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas

  • btn – number of the mouse-button, defaults to 1 [left mouse button]

  • add –

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46 or
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    47 – if
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46, a new binding will be added, otherwise it will replace a former binding

Bind fun to mouse-move events on this turtle. If fun is

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, existing bindings are removed

Remark. Every sequence of mouse-move-events on a turtle is preceded by a mouse-click event on that turtle

>>> turtle.heading[]
22.0
>>> turtle.left[45]
>>> turtle.heading[]
67.0
9

Subsequently, clicking and dragging the Turtle will move it across the screen thereby producing handdrawings [if pen is down]

Phương pháp rùa đặc biệt

turtle. begin_poly[]

Start recording the vertices of a polygon. Current turtle position is first vertex of polygon

turtle. end_poly[]

Stop recording the vertices of a polygon. Current turtle position is last vertex of polygon. This will be connected with the first vertex

turtle. get_poly[]

Return the last recorded polygon

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]
0

turtle. clone[]

Create and return a clone of the turtle with same position, heading and turtle properties

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]
1

turtle. getturtle[]turtle. getpen[]

Return the Turtle object itself. Only reasonable use. as a function to return the “anonymous turtle”

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]
2

turtle. getscreen[]

Return the object the turtle is drawing on. TurtleScreen methods can then be called for that object

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]
3

turtle. setundobuffer[size] Parameters

size – an integer or

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29

Set or disable undobuffer. If size is an integer, an empty undobuffer of given size is installed. size gives the maximum number of turtle actions that can be undone by the method/function. If size is

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, the undobuffer is disabled

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]
4

turtle. undobufferentries[]

Return number of entries in the undobuffer

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]
5

Compound shapes

To use compound turtle shapes, which consist of several polygons of different color, you must use the helper class explicitly as described below

  1. Create an empty Shape object of type “compound”

  2. Add as many components to this object as desired, using the

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    03 method

    For example

     >>> tp = turtle.pos[]
     >>> tp
     [0.00,0.00]
     >>> turtle.setpos[60,30]
     >>> turtle.pos[]
     [60.00,30.00]
     >>> turtle.setpos[[20,80]]
     >>> turtle.pos[]
     [20.00,80.00]
     >>> turtle.setpos[tp]
     >>> turtle.pos[]
     [0.00,0.00]
    
    6

  3. Now add the Shape to the Screen’s shapelist and use it

     >>> tp = turtle.pos[]
     >>> tp
     [0.00,0.00]
     >>> turtle.setpos[60,30]
     >>> turtle.pos[]
     [60.00,30.00]
     >>> turtle.setpos[[20,80]]
     >>> turtle.pos[]
     [20.00,80.00]
     >>> turtle.setpos[tp]
     >>> turtle.pos[]
     [0.00,0.00]
    
    7

Ghi chú

The class is used internally by the method in different ways. The application programmer has to deal with the Shape class only when using compound shapes like shown above

Methods of TurtleScreen/Screen and corresponding functions

Most of the examples in this section refer to a TurtleScreen instance called

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
06

Kiểm soát cửa sổ

turtle. bgcolor[*args] Parameters

args – a color string or three numbers in the range 0. colormode or a 3-tuple of such numbers

Set or return background color of the TurtleScreen

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]
8

rùa. bgpic[picname=None] Parameters

picname – a string, name of a gif-file or

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
07, or
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29

Đặt hình nền hoặc trả về tên của hình nền hiện tại. If picname is a filename, set the corresponding image as background. If picname is

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
07, delete background image, if present. Nếu picname là
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, hãy trả về tên tệp của ảnh nền hiện tại

 >>> tp = turtle.pos[]
 >>> tp
 [0.00,0.00]
 >>> turtle.setpos[60,30]
 >>> turtle.pos[]
 [60.00,30.00]
 >>> turtle.setpos[[20,80]]
 >>> turtle.pos[]
 [20.00,80.00]
 >>> turtle.setpos[tp]
 >>> turtle.pos[]
 [0.00,0.00]
9

rùa. xóa[]

Ghi chú

This TurtleScreen method is available as a global function only under the name

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
11. Hàm toàn cục
>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
12 là một hàm khác bắt nguồn từ phương thức Rùa
>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
12

rùa. xóa màn hình[]

Xóa tất cả các bản vẽ và tất cả rùa khỏi TurtleScreen. Đặt lại TurtleScreen hiện đang trống về trạng thái ban đầu. white background, no background image, no event bindings and tracing on

rùa. đặt lại[]

Ghi chú

This TurtleScreen method is available as a global function only under the name

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
14. The global function
>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
15 is another one derived from the Turtle method
>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
15

turtle. resetscreen[]

Reset all Turtles on the Screen to their initial state

turtle. screensize[canvwidth=None , canvheight=None , bg=None] Parameters
  • canvwidth – positive integer, new width of canvas in pixels

  • canvheight – positive integer, new height of canvas in pixels

  • bg – colorstring or color-tuple, new background color

If no arguments are given, return current [canvaswidth, canvasheight]. Else resize the canvas the turtles are drawing on. Do not alter the drawing window. To observe hidden parts of the canvas, use the scrollbars. With this method, one can make visible those parts of a drawing which were outside the canvas before

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
0

e. g. to search for an erroneously escaped turtle ;-]

turtle. setworldcoordinates[llx , lly , urx , ury] Parameters
  • llx – a number, x-coordinate of lower left corner of canvas

  • lly – a number, y-coordinate of lower left corner of canvas

  • urx – a number, x-coordinate of upper right corner of canvas

  • ury – a number, y-coordinate of upper right corner of canvas

Set up user-defined coordinate system and switch to mode “world” if necessary. This performs a

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
17. If mode “world” is already active, all drawings are redrawn according to the new coordinates

ATTENTION. in user-defined coordinate systems angles may appear distorted

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
1

kiểm soát hoạt ảnh

turtle. delay[delay=None] Parameters

delay – positive integer

Set or return the drawing delay in milliseconds. [This is approximately the time interval between two consecutive canvas updates. ] The longer the drawing delay, the slower the animation

Optional argument

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
2

turtle. tracer[n=None , delay=None] Parameters
  • n – nonnegative integer

  • delay – nonnegative integer

Turn turtle animation on/off and set delay for update drawings. If n is given, only each n-th regular screen update is really performed. [Can be used to accelerate the drawing of complex graphics. ] When called without arguments, returns the currently stored value of n. Second argument sets delay value [see ]

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
3

turtle. update[]

Thực hiện cập nhật TurtleScreen. To be used when tracer is turned off

See also the RawTurtle/Turtle method

Sử dụng các sự kiện màn hình

turtle. listen[xdummy=None , ydummy=None]

Set focus on TurtleScreen [in order to collect key-events]. Dummy arguments are provided in order to be able to pass to the title method

turtle. onkey[fun , key]turtle. onkeyrelease[fun , key] Parameters
  • fun – a function with no arguments or

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29

  • key – a string. key [e. g. “a”] or key-symbol [e. g. “space”]

Bind fun to key-release event of key. If fun is

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, event bindings are removed. Remark. in order to be able to register key-events, TurtleScreen must have the focus. [See method . ]

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
4

turtle. onkeypress[fun , key=None] Parameters
  • fun – a function with no arguments or

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29

  • key – a string. key [e. g. “a”] or key-symbol [e. g. “space”]

Bind fun to key-press event of key if key is given, or to any key-press-event if no key is given. Remark. in order to be able to register key-events, TurtleScreen must have focus. [See method . ]

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
5

turtle. title[fun , btn=1 , add=None]turtle. onscreenclick[fun , btn=1 , add=None] Parameters
  • fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas

  • btn – number of the mouse-button, defaults to 1 [left mouse button]

  • add –

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46 or
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    47 – if
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46, a new binding will be added, otherwise it will replace a former binding

Bind fun to mouse-click events on this screen. If fun is

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29, existing bindings are removed

Example for a TurtleScreen instance named

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
06 and a Turtle instance named
>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
8

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
6

Ghi chú

This TurtleScreen method is available as a global function only under the name

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
32. The global function
>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
33 is another one derived from the Turtle method
>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
33

turtle. ontimer[fun , t=0] Parameters
  • fun – a function with no arguments

  • t – a number >= 0

Install a timer that calls fun after t milliseconds

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
7

turtle. mainloop[]turtle. done[]

Starts event loop - calling Tkinter’s mainloop function. Must be the last statement in a turtle graphics program. Must not be used if a script is run from within IDLE in -n mode [No subprocess] - for interactive use of turtle graphics

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
8

Phương thức nhập liệu

turtle. textinput[title , prompt] Parameters
  • title – string

  • prompt – string

Bật lên một cửa sổ hộp thoại để nhập chuỗi. Parameter title is the title of the dialog window, prompt is a text mostly describing what information to input. Trả lại đầu vào chuỗi. Nếu hộp thoại bị hủy, hãy quay lại

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29

>>> turtle.position[]
[0.00,240.00]
>>> turtle.setx[10]
>>> turtle.position[]
[10.00,240.00]
9

turtle. numinput[title , prompt , default=None , minval=None , maxval=None] Parameters
  • title – string

  • prompt – string

  • default – number [optional]

  • minval – number [optional]

  • maxval – number [optional]

Pop up a dialog window for input of a number. title is the title of the dialog window, prompt is a text mostly describing what numerical information to input. default. default value, minval. minimum value for input, maxval. maximum value for input. The number input must be in the range minval . maxval if these are given. If not, a hint is issued and the dialog remains open for correction. Return the number input. If the dialog is canceled, return

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]
0

Cài đặt và phương pháp đặc biệt

turtle. mode[mode=None] Parameters

mode – one of the strings “standard”, “logo” or “world”

Set turtle mode [“standard”, “logo” or “world”] and perform reset. If mode is not given, current mode is returned

Mode “standard” is compatible with old . Mode “logo” is compatible with most Logo turtle graphics. Mode “world” uses user-defined “world coordinates”. Attention. in this mode angles appear distorted if

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
38 unit-ratio doesn’t equal 1

Mode

Initial turtle heading

positive angles

“standard”

to the right [east]

counterclockwise

“logo”

upward [north]

clockwise

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]
1

turtle. colormode[cmode=None] Parameters

cmode – one of the values 1. 0 or 255

Return the colormode or set it to 1. 0 or 255. Subsequently r, g, b values of color triples have to be in the range 0. *cmode*

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]
2

turtle. getcanvas[]

Return the Canvas of this TurtleScreen. Useful for insiders who know what to do with a Tkinter Canvas

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]
3

turtle. getshapes[]

Return a list of names of all currently available turtle shapes

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]
4

turtle. register_shape[name , shape=None]turtle. addshape[name , shape=None]

There are three different ways to call this function

  1. name is the name of a gif-file and shape is

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29. Install the corresponding image shape

    >>> turtle.position[]
    [0.00,40.00]
    >>> turtle.sety[-10]
    >>> turtle.position[]
    [0.00,-10.00]
    
    5

    Ghi chú

    Image shapes do not rotate when turning the turtle, so they do not display the heading of the turtle

  2. name is an arbitrary string and shape is a tuple of pairs of coordinates. Install the corresponding polygon shape

    >>> turtle.position[]
    [0.00,40.00]
    >>> turtle.sety[-10]
    >>> turtle.position[]
    [0.00,-10.00]
    
    6

  3. name is an arbitrary string and shape is a [compound] object. Install the corresponding compound shape

Add a turtle shape to TurtleScreen’s shapelist. Only thusly registered shapes can be used by issuing the command

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
41

turtle. turtles[]

Return the list of turtles on the screen

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]
7

turtle. window_height[]

Return the height of the turtle window

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]
8

turtle. window_width[]

Return the width of the turtle window

>>> turtle.position[]
[0.00,40.00]
>>> turtle.sety[-10]
>>> turtle.position[]
[0.00,-10.00]
9

Methods specific to Screen, not inherited from TurtleScreen

turtle. bye[]

Shut the turtlegraphics window

turtle. exit title[]

Bind

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
18 method to mouse clicks on the Screen

If the value “using_IDLE” in the configuration dictionary is

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
47 [default value], also enter mainloop. Remark. If IDLE with the
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
3 switch [no subprocess] is used, this value should be set to
>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
46 in
>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
46. In this case IDLE’s own mainloop is active also for the client script

turtle. setup[width=_CFG['width'] , height=_CFG['height'] , startx=_CFG['leftright'] , starty=_CFG['topbottom']]

Set the size and position of the main window. Default values of arguments are stored in the configuration dictionary and can be changed via a

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
46 file

Parameters
  • width – if an integer, a size in pixels, if a float, a fraction of the screen; default is 50% of screen

  • height – if an integer, the height in pixels, if a float, a fraction of the screen; default is 75% of screen

  • startx – if positive, starting position in pixels from the left edge of the screen, if negative from the right edge, if

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29, center window horizontally

  • starty – if positive, starting position in pixels from the top edge of the screen, if negative from the bottom edge, if

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    29, center window vertically

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
0

turtle. title[titlestring] Parameters

titlestring – a string that is shown in the titlebar of the turtle graphics window

Set title of turtle window to titlestring

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
1

Public classes

class turtle. RawTurtle[canvas]lớp . turtle.RawPen[canvas] Parameters

canvas – a

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
6, a or a

Create a turtle. The turtle has all methods described above as “methods of Turtle/RawTurtle”

class turtle. Turtle

Lớp con của RawTurtle, có cùng giao diện nhưng vẽ trên một đối tượng mặc định được tạo tự động khi cần lần đầu tiên

class turtle. TurtleScreen[cv] Parameters

cv – một

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
6

Cung cấp các phương pháp định hướng màn hình như

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
55, v.v. được mô tả ở trên

lớp rùa. Màn hình

Lớp con của TurtleScreen, với

lớp rùa. ScrolledCanvas[chính] Tham số

master – một số tiện ích Tkinter để chứa ScrolledCanvas, tôi. e. một Tkinter-canvas có thanh cuộn được thêm vào

Được sử dụng bởi lớp Screen, do đó tự động cung cấp ScrolledCanvas làm sân chơi cho rùa

lớp rùa. Hình dạng[loại_ , dữ liệu]Parameters

type_ – một trong các chuỗi “polygon”, “image”, “compound”

Hình dạng mô hình cấu trúc dữ liệu. Cặp

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
56 phải tuân theo thông số kỹ thuật này

loại_

dữ liệu

“đa giác”

một đa giác-tuple, tôi. e. một bộ các cặp tọa độ

"hình ảnh"

một hình ảnh [ở dạng này chỉ được sử dụng trong nội bộ. ]

"hợp chất"

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
29 [một hình ghép phải được dựng bằng phương pháp này]

thêm thành phần[nhiều , điền, outline=None]Parameters
  • poly – một đa giác, i. e. một bộ các cặp số

  • tô màu – một màu poly sẽ được lấp đầy

  • phác thảo - một màu cho đường viền của poly [nếu có]

Thí dụ

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
2

Thấy

lớp rùa. Vec2D[x , y]

Lớp vectơ hai chiều, được sử dụng làm lớp trợ giúp để triển khai đồ họa con rùa. Cũng có thể hữu ích cho các chương trình đồ họa rùa. Xuất phát từ bộ, vì vậy một vectơ là một bộ

Cung cấp [cho vectơ a, b, số k]

  • >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    59 phép cộng véc tơ

  • >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    60 phép trừ véc tơ

  • >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    61 sản phẩm bên trong

  • Phép nhân

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    62 và
    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    63 với vô hướng

  • >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    64 giá trị tuyệt đối của a

  • >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    65 vòng quay

Trợ giúp và cấu hình

Cách sử dụng trợ giúp

Các phương thức công khai của các lớp Màn hình và Rùa được ghi lại rộng rãi thông qua các tài liệu. Vì vậy, chúng có thể được sử dụng làm trợ giúp trực tuyến thông qua các tiện ích trợ giúp của Python

  • Khi sử dụng IDLE, chú giải công cụ hiển thị chữ ký và dòng đầu tiên của chuỗi tài liệu được nhập trong lệnh gọi hàm/phương thức

  • Gọi các phương thức hoặc hàm hiển thị các chuỗi tài liệu

    >>> turtle.setheading[90]
    >>> turtle.heading[]
    90.0
    
    3

  • Các tài liệu của các chức năng bắt nguồn từ các phương thức có dạng được sửa đổi

    >>> turtle.setheading[90]
    >>> turtle.heading[]
    90.0
    
    4

Các chuỗi tài liệu đã sửa đổi này được tạo tự động cùng với các định nghĩa hàm bắt nguồn từ các phương thức tại thời điểm nhập

Dịch tài liệu sang các ngôn ngữ khác nhau

Có một tiện ích để tạo một từ điển, các khóa là tên phương thức và giá trị của chúng là chuỗi tài liệu của các phương thức công khai của các lớp Màn hình và Con rùa

rùa. write_docstringdict[filename='turtle_docstringdict'] Parameters

filename – a string, used as filename

Create and write docstring-dictionary to a Python script with the given filename. This function has to be called explicitly [it is not used by the turtle graphics classes]. The docstring dictionary will be written to the Python script

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
67. It is intended to serve as a template for translation of the docstrings into different languages

If you [or your students] want to use with online help in your native language, you have to translate the docstrings and save the resulting file as e. g.

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
69

If you have an appropriate entry in your

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
46 file this dictionary will be read in at import time and will replace the original English docstrings

At the time of this writing there are docstring dictionaries in German and in Italian. [Requests please to glingl @ aon . at. ]

How to configure Screen and Turtles

The built-in default configuration mimics the appearance and behaviour of the old turtle module in order to retain best possible compatibility with it

If you want to use a different configuration which better reflects the features of this module or which better fits to your needs, e. g. for use in a classroom, you can prepare a configuration file

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
46 which will be read at import time and modify the configuration according to its settings

The built in configuration would correspond to the following turtle. cfg

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
5

Short explanation of selected entries

  • The first four lines correspond to the arguments of the

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    72 method

  • Line 5 and 6 correspond to the arguments of the method

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    73

  • shape can be any of the built-in shapes, e. g. arrow, turtle, etc. For more info try

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    74

  • If you want to use no fillcolor [i. e. make the turtle transparent], you have to write

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    75 [but all nonempty strings must not have quotes in the cfg-file]

  • If you want to reflect the turtle its state, you have to use

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    76

  • If you set e. g.

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    77 the docstringdict
    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    78 will be loaded at import time [if present on the import path, e. g. in the same directory as ]

  • The entries exampleturtle and examplescreen define the names of these objects as they occur in the docstrings. The transformation of method-docstrings to function-docstrings will delete these names from the docstrings

  • using_IDLE. Set this to

    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46 if you regularly work with IDLE and its
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    3 switch [“no subprocess”]. This will prevent to enter the mainloop

There can be a

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
46 file in the directory where is stored and an additional one in the current working directory. The latter will override the settings of the first one

The

>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
85 directory contains a
>>> turtle.heading[]
22.0
>>> turtle.right[45]
>>> turtle.heading[]
337.0
46 file. You can study it as an example and see its effects when running the demos [preferably not from within the demo-viewer]

— Demo scripts

The package includes a set of demo scripts. Có thể chạy và xem các tập lệnh này bằng trình xem demo được cung cấp như sau

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
6

Alternatively, you can run the demo scripts individually. For example,

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
7

The package directory contains

  • A demo viewer

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    90 which can be used to view the sourcecode of the scripts and run them at the same time

  • Multiple scripts demonstrating different features of the module. Examples can be accessed via the Examples menu. They can also be run standalone

  • A

    >>> turtle.heading[]
    22.0
    >>> turtle.right[45]
    >>> turtle.heading[]
    337.0
    
    46 file which serves as an example of how to write and use such files

The demo scripts are

Tên

Description

Features

bytedesign

complex classical turtle graphics pattern

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
96, trì hoãn,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
97

chaos

biểu đồ động lực học Verhulst, cho thấy rằng các tính toán của máy tính đôi khi có thể tạo ra kết quả trái với mong đợi thông thường

tọa độ thế giới

cái đồng hồ

đồng hồ analog hiển thị thời gian của máy tính của bạn

rùa như kim đồng hồ, hẹn giờ

máy pha màu

thử nghiệm với r, g, b

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
79

rừng

3 cây theo chiều rộng

ngẫu nhiên hóa

đường cong fractal

Đường cong Hilbert & Koch

đệ quy

cây bồ đề

dân tộc học [kolams Ấn Độ]

Hệ thống chữ L

min_hanoi

Tháp Hà Nội

Rùa Chữ Nhật dạng đĩa Hà Nội [hình dáng, kích thước]

nim

chơi game nim cổ điển với ba đống gậy trên máy tính

rùa như nimsticks, điều khiển sự kiện [chuột, bàn phím]

sơn

chương trình vẽ siêu tối giản

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
77

hòa bình

tiểu học

rùa. xuất hiện và hoạt hình

hoa hồng

lát gạch định kỳ với diều và phi tiêu

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
29

hành_tinh_và_mặt_trăng

mô phỏng hệ trọng lực

hình ghép,

>>> turtle.position[]
[0.00,0.00]
>>> turtle.backward[30]
>>> turtle.position[]
[-30.00,0.00]
31

round_dance

rùa nhảy múa quay theo cặp theo hướng ngược lại

hình ghép, nhân bản shapesize, tilt, get_shapepoly, cập nhật

sorting_animate

trình diễn trực quan các phương pháp sắp xếp khác nhau

căn chỉnh đơn giản, ngẫu nhiên

cây

cây đầu tiên có chiều rộng [đồ họa] [sử dụng trình tạo]

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
83

two_canvases

Thiết kế đơn giản

rùa trên hai bức tranh

wikipedia

một mẫu từ bài viết trên wikipedia về đồ họa con rùa

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
83,
>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
32

yinyang

một ví dụ cơ bản khác

>>> turtle.position[]
[0.00,0.00]
>>> turtle.forward[25]
>>> turtle.position[]
[25.00,0.00]
>>> turtle.forward[-75]
>>> turtle.position[]
[-50.00,0.00]
27

Chúc vui vẻ

Những thay đổi kể từ Python 2. 6

  • Các phương pháp

    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    03,
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    04 và
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    05 đã bị loại bỏ. Các phương thức với các tên và chức năng này hiện chỉ khả dụng dưới dạng các phương thức của
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.forward[25]
    >>> turtle.position[]
    [25.00,0.00]
    >>> turtle.forward[-75]
    >>> turtle.position[]
    [-50.00,0.00]
    
    07. Các chức năng bắt nguồn từ những vẫn có sẵn. [Thực tế đã có trong Python 2. 6 các phương thức này chỉ đơn thuần là bản sao của các phương thức
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    5/
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.forward[25]
    >>> turtle.position[]
    [25.00,0.00]
    >>> turtle.forward[-75]
    >>> turtle.position[]
    [-50.00,0.00]
    
    07 tương ứng. ]

  • Phương pháp

    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    09 đã bị loại bỏ. Hành vi của
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.forward[25]
    >>> turtle.position[]
    [25.00,0.00]
    >>> turtle.forward[-75]
    >>> turtle.position[]
    [-50.00,0.00]
    
    57 và
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.forward[25]
    >>> turtle.position[]
    [25.00,0.00]
    >>> turtle.forward[-75]
    >>> turtle.position[]
    [-50.00,0.00]
    
    58 đã thay đổi đôi chút. bây giờ mọi quá trình điền phải được hoàn thành với một cuộc gọi
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.forward[25]
    >>> turtle.position[]
    [25.00,0.00]
    >>> turtle.forward[-75]
    >>> turtle.position[]
    [-50.00,0.00]
    
    58

  • Một phương thức

    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    13 đã được thêm vào. Nó trả về một giá trị boolean.
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    46 nếu quy trình chiết rót đang được tiến hành, nếu không thì
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    47. Hành vi này tương ứng với lệnh gọi
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    16 không có đối số trong Python 2. 6

Các thay đổi kể từ Python 3. 0

  • Các phương thức

    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    17,
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    18 và
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    19 đã được thêm vào. Do đó, hiện có đầy đủ các phép biến đổi tuyến tính thông thường để biến đổi hình con rùa.
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    20 đã được tăng cường chức năng. bây giờ nó có thể được sử dụng để lấy hoặc đặt góc nghiêng.
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    21 không được dùng nữa

  • Phương thức

    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    22 đã được thêm vào như một phần bổ sung cho
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    23, trên thực tế, phương thức này liên kết các hành động với sự kiện phát hành khóa. Theo đó, cái sau có bí danh.
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    24

  • Phương pháp

    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    25 đã được thêm vào. Vì vậy, khi chỉ làm việc với các đối tượng Màn hình và Rùa, người ta không được nhập thêm
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.backward[30]
    >>> turtle.position[]
    [-30.00,0.00]
    
    05 nữa

  • Hai phương thức nhập liệu đã được thêm vào

    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    27 và
    >>> turtle.heading[]
    22.0
    >>> turtle.left[45]
    >>> turtle.heading[]
    67.0
    
    28. Các hộp thoại đầu vào bật lên này và trả về các chuỗi và số tương ứng

Chủ Đề