Trong gói turtle
khi bạn chạy chương trình với lệnh rùa, một cửa sổ đặc biệt sẽ mở ra nơi diễn ra quá trình vẽ
Mã rùa ví dụ để vẽ một ngôi sao
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. Mã để vẽ ngôi sao trên.from turtle import * color['red', 'yellow'] begin_fill[] while True: forward[200] left[170] if abs[pos[]] < 1: break end_fill[] done[]
Hoàn thành tài liệu tham khảo rùa
Dưới đây là bảng mô tả các lệnh rùa cần thiết để bắt đầuĐể xem toàn bộ các lệnh turtle
, hãy truy cập Python 3 chính thức. 1 trang rùa
Lệnh rùa
Các lệnh thường được sử dụng có sẵn trongturtle
được đưa ra bên dưới. Nhấp vào bất kỳ lệnh nào để tìm hiểu thêm về nóđộ[]
Đặt phương thức nhập góc thành độ. Tất cả các đầu vào góc sau đây được coi là thước đo độ. Đây là thiết lập mặc địnhradian[]
Đặt phương thức nhập góc thành radian. Tất cả các đầu vào góc sau đây được coi là các biện pháp radiancài lại[]
Đặt lại mọi thứ về giá trị mặc định và xóa canvas. Sau khi gọi đếnreset
, khung vẽ sẽ ở trạng thái chính xác như khi lệnh nhập được gọi. bạn sẽ có một khung trống để con rùa [màu đen với phần tô được đặt thành không tô] chỉ về bên phải ở giữa [tiêu đề = 0. 0]thông thoáng[]
Xóa toàn bộ canvas và vẽ lại con rùa. Không di chuyển con rùatrình theo dõi [n=Không, độ trễ=Không]
Bật/tắt hoạt ảnh con rùa và đặt độ trễ cho các bản vẽ cập nhậtNếu số nguyên n không âm được cung cấp, chỉ mỗi lần cập nhật màn hình thông thường thứ n được thực hiện. Có thể được sử dụng để tăng tốc độ vẽ đồ họa phức tạp. Khi được gọi mà không có đối số, trả về giá trị hiện được lưu trữ của n. Đối số thứ hai đặt giá trị độ trễ [xem độ trễ[]]
Tắt con rùa làm cho con rùa biến mất và vẽ nhanh hơn RẤT NHIỀU. Các lệnh vẽ vẫn được thực thi mà không có con rùa và các đường vẫn được vẽ khi con rùa di chuyển. Sử dụng up
và turtle
0 để bật và tắt tính năng vẽ hoặc chỉ sử dụng các chức năng turtle
1, turtle
2 hoặc turtle
3 để di chuyển mà không cần vẽ
Rùa là một tính năng đặc biệt trong python chứa thư viện đồ họa. Trong bài viết này, chúng ta sẽ tìm hiểu cách Nhận tọa độ màn hình trong Python Turtle.
Turtle có nhiều chức năng tích hợp sẵn để tạo chương trình này chúng ta sử dụng như sau
nhập rùa -> Đây là thư viện python cho phép chúng tôi truy cập thư viện rùa
Turtle[]–> Phương thức này được sử dụng để tạo đối tượng
onscreenclick[functionname,1] –> Đây là hàm rùa gửi tọa độ đến chức năng;
Đồ 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.09, 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.00, 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.01, 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.03Mô-đ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
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.06 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ụngHà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
[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à phân lớp [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 “trường hợp” đượ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đổ đầyKiểm soát bản vẽ nhiều hơnTrạng thái rùaKhả năng hiển thị.
.
Vẻ bề ngoài.
Sử dụng các sự kiệnPhươ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 hìnhSử 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ệuCác phương pháp dành riêng cho Màn hìnhCá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.08chuyể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.0rù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.0rù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]29Nế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.0rù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.0rù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]0rù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]1rù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ả về 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]2rù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]3rùa. dấu xóa[n=Không]Parametersn – 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]4rù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]5rùa. tốc độ[tốc độ=Không]Parameterstố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]6Cho 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]7rù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]29Trả 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]8rù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]9rù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]0rù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]1rù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]29Trả 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]2Cà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]3rù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. pensize[chiều rộng=Không có . ]turtle.chiều rộng[chiều rộng=Không có]Parameterschiề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]5rù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]6rù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]7Kiể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]54Trả 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]8rù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]55Trả 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]9rù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]53Trả 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]69Cá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]72Tươ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ụngNế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.00Xem 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.01rùa. begin_fill[]To be called just before drawing a shape to be filled
turtle. end_fill[]Fill the shape drawn after the last call to
Whether or not overlap regions for self-intersecting polygons or multiple shapes are filled depends on the operating system graphics, type of overlap, and number of overlaps. For example, the Turtle star above may be either all yellow or have some white regions
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.02Kiểm soát bản vẽ nhiều hơn
turtle. reset[]Delete the turtle’s drawings from the screen, re-center the turtle and set variables to the default values
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.03turtle. clear[]Delete the turtle’s drawings from the screen. Do not move turtle. State and position of the turtle as well as drawings of other turtles are not affected
turtle. write[arg , move=False , align='left' , font=['Arial', 8, 'normal']] Parameters
arg – object to be written to the TurtleScreen
move – True/False
align – one of the strings “left”, “center” or right”
font – a triple [fontname, fontsize, fonttype]
Write text - the string representation of arg - at the current turtle position according to align [“left”, “center” or “right”] and with the given font. If move is true, the pen is moved to the bottom-right corner of the text. By default, move is
>>> 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.04bang con rùa
Hiển thị
turtle. con rùa ẩn nấp[]con rùa. ht[]Làm cho con rùa vô hình. It’s a good idea to do this while you’re in the middle of doing some complex drawing, because hiding the turtle speeds up the drawing observably
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.05turtle. showturtle[]turtle. st[]Làm cho con rùa có thể nhìn thấy
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.06turtle. 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.07Vẻ bề ngoài
rùa. hình dạng[tên=Không có]Parameterstê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. “arrow”, “turtle”, “circle”, “square”, “triangle”, “classic”. To learn about how to deal with shapes see Screen method
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.08turtle. resizemode[rmode=None] Parametersrmode – one of the strings “auto”, “user”, “noresize”
Set resizemode to one of the values. “auto”, “user”, “noresize”. If rmode is not given, return current resizemode. Different resizemodes have the following effects
“auto”. adapts the appearance of the turtle corresponding to the value of pensize
“user”. adapts the appearance of the turtle according to the values of stretchfactor and outlinewidth [outline], which are set by
“noresize”. no adaption of the turtle’s appearance takes place
>>> turtle.position[] [0.00,0.00] >>> turtle.backward[30] >>> turtle.position[] [-30.00,0.00]84 is called by when used with arguments>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.09turtle. shapesize[stretch_wid=None , stretch_len=None , outline=None]turtle. turtlesize[stretch_wid=None , stretch_len=None , outline=None] Parameters
stretch_wid – positive number
stretch_len – positive number
outline – positive number
Return or set the pen’s attributes x/y-stretchfactors and/or outline. Set resizemode to “user”. If and only if resizemode is set to “user”, the turtle will be displayed stretched according to its stretchfactors. stretch_wid is stretchfactor perpendicular to its orientation, stretch_len is stretchfactor in direction of its orientation, outline determines the width of the shapes’s outline
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.00turtle. shearfactor[shear=None] Parametersshear – number [optional]
Đặt hoặc trả lại shearfactor hiện tại. Shear the turtleshape according to the given shearfactor shear, which is the tangent of the shear angle. Do not change the turtle’s heading [direction of movement]. If shear is not given. return the current shearfactor, i. e. the tangent of the shear angle, by which lines parallel to the heading of the turtle are sheared
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.01turtle. tilt[angle] Parametersangle – a number
Rotate the turtleshape by angle from its current tilt-angle, but do not change the turtle’s heading [direction of movement]
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.02turtle. settiltangle[angle] Parametersangle – a number
Rotate the turtleshape to point in the direction specified by angle, regardless of its current tilt-angle. Do not change the turtle’s heading [direction of movement]
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.03Deprecated since version 3. 1
turtle. tiltangle[angle=None] Parametersangle – a number [optional]
Set or return the current tilt-angle. If angle is given, rotate the turtleshape to point in the direction specified by angle, regardless of its current tilt-angle. Do not change the turtle’s heading [direction of movement]. If angle is not given. return the current tilt-angle, 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.04turtle. 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.05turtle. 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.06Sử 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 bindingBind 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.07turtle. 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 bindingBind 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.08turtle. 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 bindingBind 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 removedRemark. 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.09Subsequently, 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]0turtle. 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]1turtle. 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]2turtle. nhận màn hình[]Return the object the turtle is drawing on. Các phương thức TurtleScreen sau đó có thể được gọi cho đối tượng đó
>>> 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]3turtle. setundobuffer[size] Parameterssize – an integer or
>>> turtle.position[] [0.00,0.00] >>> turtle.backward[30] >>> turtle.position[] [-30.00,0.00]29Set 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]4turtle. undobufferentries[]Trả về số mục nhập trong bộ hoàn tác
>>> 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]5Compound shapes
To use compound turtle shapes, which consist of several polygons of different color, you must use the helper class explicitly as described below
Create an empty Shape object of type “compound”
Add as many components to this object as desired, using the
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.003 methodFor 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]6Now 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]7Ghi 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.006Kiểm soát cửa sổ
turtle. bgcolor[*args] Parametersargs – 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]8turtle. bgpic[picname=None] Parameterspicname – a string, name of a gif-file or
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.007, or>>> turtle.position[] [0.00,0.00] >>> turtle.backward[30] >>> turtle.position[] [-30.00,0.00]29Set background image or return name of current backgroundimage. If picname is a filename, set the corresponding image as background. If picname is
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.007, delete background image, if present. If picname is>>> turtle.position[] [0.00,0.00] >>> turtle.backward[30] >>> turtle.position[] [-30.00,0.00]29, return the filename of the current backgroundimage>>> 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]9turtle. clear[]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.011. The global function>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.012 is a different one derived from the Turtle method>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.012turtle. clearscreen[]Delete all drawings and all turtles from the TurtleScreen. Reset the now empty TurtleScreen to its initial state. white background, no background image, no event bindings and tracing on
turtle. reset[]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.014. The global function>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.015 is another one derived from the Turtle method>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.015turtle. 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
Nếu không có đối số nào được đưa ra, hãy trả về giá trị hiện tại [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]0e. 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.017. If mode “world” is already active, all drawings are redrawn according to the new coordinatesATTENTION. in user-defined coordinate systems angles may appear distorted
>>> turtle.position[] [0.00,240.00] >>> turtle.setx[10] >>> turtle.position[] [10.00,240.00]1kiểm soát hoạt hình
turtle. độ trễ[độ trễ=Không có]Parametersdelay – 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]2turtle. tracer[n=None , delay=None] Parameters
n – nonnegative integer
delay – nonnegative integer
Bật/tắt hoạt hình rùa và đặt độ trễ cho bản vẽ cập nhật. Nếu n được cung cấp, chỉ mỗi lần cập nhật màn hình thông thường thứ n thực sự được thực hiện. [Có thể được sử dụng để tăng tốc độ vẽ đồ họa phức tạp. ] 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]3turtle. update[]Perform a TurtleScreen update. Được sử dụng khi tắt trình theo dõi
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]29key – 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]4turtle. 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]29key – 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]5turtle. 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 bindingBind 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 removedExample for a TurtleScreen instance named
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.006 and a Turtle instance named>>> turtle.setheading[90] >>> turtle.heading[] 90.08>>> turtle.position[] [0.00,240.00] >>> turtle.setx[10] >>> turtle.position[] [10.00,240.00]6Ghi chú
This TurtleScreen method is available as a global function only under the name
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.032. The global function>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.033 is another one derived from the Turtle method>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.033turtle. 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]7turtle. 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]8Phương thức nhập liệu
turtle. textinput[title , prompt] Parameters
title – string
prompt – string
Pop up a dialog window for input of a string. Tiêu đề tham số là tiêu đề của cửa sổ hộp thoại, dấu nhắc là văn bản chủ yếu mô tả thông tin cần nhập. Return the string 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,240.00] >>> turtle.setx[10] >>> turtle.position[] [10.00,240.00]9turtle. 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]0Cài đặt và phương pháp đặc biệt
turtle. mode[mode=None] Parametersmode – 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.038 unit-ratio doesn’t equal 1Mode
Initial turtle heading
positive angles
“standard”
to the right [east]
counterclockwise
“logo”
upward [north]
theo chiều kim đồng hồ
>>> turtle.position[] [0.00,40.00] >>> turtle.sety[-10] >>> turtle.position[] [0.00,-10.00]1rùa. colormode[cmode=None] Parameterscmode – 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]2turtle. getcanvas[]Trả lại Canvas của TurtleScreen này. 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]3turtle. getshapes[]Trả về danh sách tên của tất cả các hình con rùa hiện có
>>> turtle.position[] [0.00,40.00] >>> turtle.sety[-10] >>> turtle.position[] [0.00,-10.00]4turtle. register_shape[name , shape=None]turtle. addshape[name , shape=None]There are three different ways to call this function
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]5Ghi chú
Image shapes do not rotate when turning the turtle, so they do not display the heading of the turtle
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]6name 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.041turtle. turtles[]Return the list of turtles on the screen
>>> turtle.position[] [0.00,40.00] >>> turtle.sety[-10] >>> turtle.position[] [0.00,-10.00]7turtle. window_height[]Return the height of the turtle window
>>> turtle.position[] [0.00,40.00] >>> turtle.sety[-10] >>> turtle.position[] [0.00,-10.00]8turtle. window_width[]Return the width of the turtle window
>>> turtle.position[] [0.00,40.00] >>> turtle.sety[-10] >>> turtle.position[] [0.00,-10.00]9Methods specific to Screen, not inherited from TurtleScreen
turtle. bye[]Shut the turtlegraphics window
turtle. exit title[]Ràng buộc phương pháp
>>> turtle.position[] [0.00,0.00] >>> turtle.backward[30] >>> turtle.position[] [-30.00,0.00]18 để nhấp chuột trên Màn hìnhIf 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.03 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.046. In this case IDLE’s own mainloop is active also for the client scriptturtle. 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.046 fileParameters
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 horizontallystarty – 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.00turtle. title[titlestring] Parameterstitlestring – 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.01Public classes
class turtle. RawTurtle[canvas]class turtle. RawPen[canvas] Parameterscanvas – a
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.06, a or aCreate a turtle. The turtle has all methods described above as “methods of Turtle/RawTurtle”
class turtle. TurtleSubclass of RawTurtle, has the same interface but draws on a default object created automatically when needed for the first time
class turtle. TurtleScreen[cv] Parameterscv – a
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.06Provides screen oriented methods like
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.055 etc. that are described aboveclass turtle. ScreenSubclass of TurtleScreen, with
class turtle. ScrolledCanvas[master] Parametersmaster – some Tkinter widget to contain the ScrolledCanvas, i. e. a Tkinter-canvas with scrollbars added
Đượ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
class turtle. Shape[type_ , data] Parameterstype_ – one of the strings “polygon”, “image”, “compound”
Data structure modeling shapes. The pair
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.056 must follow this specificationtype_
data
“polygon”
a polygon-tuple, i. e. a tuple of pairs of coordinates
"hình ảnh"
một hình ảnh [ở dạng này chỉ được sử dụng trong nội bộ. ]
“compound”
>>> 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]addcomponent[poly , fill , outline=None] Parameters
poly – a polygon, i. e. a tuple of pairs of numbers
fill – a color the poly will be filled with
outline – a color for the poly’s outline [if given]
Example
>>> turtle.setheading[90] >>> turtle.heading[] 90.02See
class turtle. Vec2D[x , y]A two-dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs too. Derived from tuple, so a vector is a tuple
Provides [for a, b vectors, k number]
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.059 vector addition >>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.060 vector subtraction >>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.061 inner product >>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.062 and>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.063 multiplication with scalar >>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.064 absolute value of a >>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.065 rotationHelp and configuration
How to use help
The public methods of the Screen and Turtle classes are documented extensively via docstrings. So these can be used as online-help via the Python help facilities
When using IDLE, tooltips show the signatures and first lines of the docstrings of typed in function-/method calls
Calling on methods or functions displays the docstrings
>>> turtle.setheading[90] >>> turtle.heading[] 90.03The docstrings of the functions which are derived from methods have a modified form
>>> turtle.setheading[90] >>> turtle.heading[] 90.04These modified docstrings are created automatically together with the function definitions that are derived from the methods at import time
Translation of docstrings into different languages
There is a utility to create a dictionary the keys of which are the method names and the values of which are the docstrings of the public methods of the classes Screen and Turtle
turtle. write_docstringdict[filename='turtle_docstringdict'] Parametersfilename – 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.067. It is intended to serve as a template for translation of the docstrings into different languagesIf 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.069If you have an appropriate entry in your
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.046 file this dictionary will be read in at import time and will replace the original English docstringsAt 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.046 which will be read at import time and modify the configuration according to its settingsThe built in configuration would correspond to the following turtle. cfg
>>> turtle.setheading[90] >>> turtle.heading[] 90.05Short explanation of selected entries
The first four lines correspond to the arguments of the
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.072 methodLine 5 and 6 correspond to the arguments of the method
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.073hình dạng có thể là bất kỳ hình dạng tích hợp nào, e. g. arrow, turtle, etc. For more info try
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.074If 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.075 [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.076If you set e. g.
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.077 the docstringdict>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.078 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.03 switch [“no subprocess”]. This will prevent to enter the mainloopThere can be a
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.046 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 oneThe
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.085 directory contains a>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.046 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. These scripts can be run and viewed using the supplied demo viewer as follows
>>> turtle.setheading[90] >>> turtle.heading[] 90.06Alternatively, you can run the demo scripts individually. For example,
>>> turtle.setheading[90] >>> turtle.heading[] 90.07The package directory contains
A demo viewer
>>> turtle.heading[] 22.0 >>> turtle.right[45] >>> turtle.heading[] 337.090 which can be used to view the sourcecode of the scripts and run them at the same timeMultiple 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.046 file which serves as an example of how to write and use such filesThe demo scripts are
Name
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]97chaos
graphs Verhulst dynamics, shows that computer’s computations can generate results sometimes against the common sense expectations
world coordinates
clock
analog clock showing time of your computer
rùa như kim đồng hồ, hẹn giờ
colormixer
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]79rừng
3 cây theo chiều rộng
randomization
đườ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
super minimalistic drawing program
>>> turtle.position[] [0.00,0.00] >>> turtle.forward[25] >>> turtle.position[] [25.00,0.00] >>> turtle.forward[-75] >>> turtle.position[] [-50.00,0.00]77peace
tiểu học
turtle. appearance and animation
penrose
aperiodic tiling with kites and darts
>>> turtle.position[] [0.00,0.00] >>> turtle.forward[25] >>> turtle.position[] [25.00,0.00] >>> turtle.forward[-75] >>> turtle.position[] [-50.00,0.00]29planet_and_moon
simulation of gravitational system
compound shapes,
>>> turtle.position[] [0.00,0.00] >>> turtle.backward[30] >>> turtle.position[] [-30.00,0.00]31round_dance
dancing turtles rotating pairwise in opposite direction
compound shapes, clone shapesize, tilt, get_shapepoly, update
sorting_animate
visual demonstration of different sorting methods
simple alignment, randomization
tree
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]83two_canvases
simple design
turtles on two canvases
wikipedia
a pattern from the wikipedia article on turtle graphics
>>> 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]32yinyang
another elementary example
>>> turtle.position[] [0.00,0.00] >>> turtle.forward[25] >>> turtle.position[] [25.00,0.00] >>> turtle.forward[-75] >>> turtle.position[] [-50.00,0.00]27Have fun
Changes since Python 2. 6
Các phương pháp
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.003,>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.004 và>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.005 đã bị loại bỏ. Methods with these names and functionality are now available only as methods of>>> 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. The functions derived from these remain available. [In fact already in Python 2. 6 these methods were merely duplications of the corresponding>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.05/>>> 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-methods. ]Phương pháp
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.009 đã 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 quy trình điền phải được hoàn thành bằng lệnh 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]58Một phương pháp
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.013 đã đượ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.016 không có đối số trong Python 2. 6Các thay đổi kể từ Python 3. 0
Các phương pháp
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.017,>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.018 và>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.019 đã đượ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.020 đã đượ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.021 không được dùng nữaPhương thức
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.022 đã được thêm vào như một phần bổ sung cho>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.023, 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.024Phương pháp
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.025 đã đượ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ữaHai phương thức nhập liệu đã được thêm vào
>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.027 và>>> turtle.heading[] 22.0 >>> turtle.left[45] >>> turtle.heading[] 67.028. 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 ứngLàm thế nào chúng ta có thể kiểm tra vị trí của con rùa?
Kiểm tra và đặt lại vị trí con rùa . Ngoài ra, bạn có thể kiểm tra vị trí rùa với các thuộc tính xcor và ycor và sử dụng setx, sety và setxy để đặt lại các vị trí này.POS[] trong Python là gì?
Hàm pos tìm kiếm một nhóm các ký tự, được biểu thị bằng một chuỗi con, trong một chuỗi_nguồn . Hàm trả về vị trí bắt đầu xuất hiện đầu tiên của chuỗi con.XCOR[] là gì?
xcor[] Hàm này được sử dụng để trả về tọa độ x của rùa về vị trí hiện tại của rùa . Nó không yêu cầu bất kỳ đối số.