“Turtle” là một tính năng của trăn giống như một bảng vẽ, cho phép bạn ra lệnh cho một chú rùa vẽ lên đó
Bạn có thể sử dụng các chức năng như
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.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.setheading[90] >>> turtle.heading[] 90.08 là sự triển khai lại mở rộng của mô-đun cùng tên từ bản phân phối tiêu chuẩn Python cho đến phiên bản Python 2. 5
Nó cố gắng giữ những ưu điểm của mô-đun rùa cũ và tương thích [gần như] 100% với nó. Điều này có nghĩa là ngay từ đầu phải cho phép người lập trình học sử dụng tất cả các lệnh, lớp và phương thức một cách tương tác khi sử dụng mô-đun từ bên trong IDLE chạy với công tắc
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.03
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
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04 cho đồ họa bên dưới, 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
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
5 định nghĩa cửa sổ đồ họa là sân chơi cho rùa vẽ. Phương thức khởi tạo của nó cần một đối số là>>> 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>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
7. Nó nên được sử dụng khi>>> turtle.setheading[90] >>> turtle.heading[] 90.0
8 được sử dụng như một phần của một số ứng dụngHàm
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
9 trả về một đối tượng đơn lẻ của lớp con>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
5. Chức năng này nên được sử dụng khi>>> turtle.setheading[90] >>> turtle.heading[] 90.0
8 được sử dụng như một công cụ độc lập để thực hiện đồ 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
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
502 [bí danh.>>> turtle.setheading[90] >>> turtle.heading[] 90.0
503] định nghĩa các đối tượng Rùa vẽ trên một>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
5. 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ẽCó nguồn gốc từ RawTurtle là phân lớp
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
505 [bí danh.>>> turtle.setheading[90] >>> turtle.heading[] 90.0
506], dựa trên “đối tượng”>>> turtle.setheading[90] >>> turtle.heading[] 90.0
507 đượ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
>>> turtle.setheading[90] >>> turtle.heading[] 90.0507 và
>>> turtle.setheading[90] >>> turtle.heading[] 90.0505. 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ẽ>>> turtle.setheading[90] >>> turtle.heading[] 90.0510.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0511
>>> turtle.setheading[90] >>> turtle.heading[] 90.0512.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0513.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0514
>>> turtle.setheading[90] >>> turtle.heading[] 90.0515.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0516
>>> turtle.setheading[90] >>> turtle.heading[] 90.0517.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0518
>>> turtle.setheading[90] >>> turtle.heading[] 90.0519.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0520.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0521
>>> turtle.setheading[90] >>> turtle.heading[] 90.0522
>>> turtle.setheading[90] >>> turtle.heading[] 90.0523
>>> turtle.setheading[90] >>> turtle.heading[] 90.0524.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0525
>>> turtle.setheading[90] >>> turtle.heading[] 90.0526
>>> turtle.setheading[90] >>> turtle.heading[] 90.0527
>>> turtle.setheading[90] >>> turtle.heading[] 90.0528
>>> turtle.setheading[90] >>> turtle.heading[] 90.0529
>>> turtle.setheading[90] >>> turtle.heading[] 90.0530
>>> turtle.setheading[90] >>> turtle.heading[] 90.0531
>>> turtle.setheading[90] >>> turtle.heading[] 90.0532
>>> turtle.setheading[90] >>> turtle.heading[] 90.0533Cho biết trạng thái của Rùa
>>> turtle.setheading[90] >>> turtle.heading[] 90.0534.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0535
>>> turtle.setheading[90] >>> turtle.heading[] 90.0536
>>> turtle.setheading[90] >>> turtle.heading[] 90.0537
>>> turtle.setheading[90] >>> turtle.heading[] 90.0538
>>> turtle.setheading[90] >>> turtle.heading[] 90.0539
>>> turtle.setheading[90] >>> turtle.heading[] 90.0540Cài đặt và đo lường
>>> turtle.setheading[90] >>> turtle.heading[] 90.0541
>>> turtle.setheading[90] >>> turtle.heading[] 90.0542Điều khiển bút Trạng thái vẽ
>>> turtle.setheading[90] >>> turtle.heading[] 90.0543.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0544.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0545
>>> turtle.setheading[90] >>> turtle.heading[] 90.0546.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0547.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0548
>>> turtle.setheading[90] >>> turtle.heading[] 90.0549.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0550
>>> turtle.setheading[90] >>> turtle.heading[] 90.0551
>>> turtle.setheading[90] >>> turtle.heading[] 90.0552Kiểm soát màu sắc
>>> turtle.setheading[90] >>> turtle.heading[] 90.0553
>>> turtle.setheading[90] >>> turtle.heading[] 90.0554
>>> turtle.setheading[90] >>> turtle.heading[] 90.0555đổ đầy
>>> turtle.setheading[90] >>> turtle.heading[] 90.0556
>>> turtle.setheading[90] >>> turtle.heading[] 90.0557
>>> turtle.setheading[90] >>> turtle.heading[] 90.0558Kiểm soát bản vẽ nhiều hơn
>>> turtle.setheading[90] >>> turtle.heading[] 90.0559
>>> turtle.setheading[90] >>> turtle.heading[] 90.0560
>>> turtle.setheading[90] >>> turtle.heading[] 90.0561Trạng thái rùaKhả năng hiển thị
>>> turtle.setheading[90] >>> turtle.heading[] 90.0562.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0563
>>> turtle.setheading[90] >>> turtle.heading[] 90.0564.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0565
>>> turtle.setheading[90] >>> turtle.heading[] 90.0566Appearance
>>> turtle.setheading[90] >>> turtle.heading[] 90.0567
>>> turtle.setheading[90] >>> turtle.heading[] 90.0568
>>> turtle.setheading[90] >>> turtle.heading[] 90.0569.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0570
>>> turtle.setheading[90] >>> turtle.heading[] 90.0571
>>> turtle.setheading[90] >>> turtle.heading[] 90.0572
>>> turtle.setheading[90] >>> turtle.heading[] 90.0573
>>> turtle.setheading[90] >>> turtle.heading[] 90.0574
>>> turtle.setheading[90] >>> turtle.heading[] 90.0575
>>> turtle.setheading[90] >>> turtle.heading[] 90.0576Using events
>>> turtle.setheading[90] >>> turtle.heading[] 90.0577
>>> turtle.setheading[90] >>> turtle.heading[] 90.0578
>>> turtle.setheading[90] >>> turtle.heading[] 90.0579Special Turtle methods
>>> turtle.setheading[90] >>> turtle.heading[] 90.0580
>>> turtle.setheading[90] >>> turtle.heading[] 90.0581
>>> turtle.setheading[90] >>> turtle.heading[] 90.0582
>>> turtle.setheading[90] >>> turtle.heading[] 90.0583
>>> turtle.setheading[90] >>> turtle.heading[] 90.0584.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0585
>>> turtle.setheading[90] >>> turtle.heading[] 90.0586
>>> turtle.setheading[90] >>> turtle.heading[] 90.0587
>>> turtle.setheading[90] >>> turtle.heading[] 90.0588
Methods of TurtleScreen/Screen¶
Window control>>> turtle.setheading[90] >>> turtle.heading[] 90.0589
>>> turtle.setheading[90] >>> turtle.heading[] 90.0590
>>> turtle.setheading[90] >>> turtle.heading[] 90.0591
>>> turtle.setheading[90] >>> turtle.heading[] 90.0592
>>> turtle.setheading[90] >>> turtle.heading[] 90.0593
>>> turtle.setheading[90] >>> turtle.heading[] 90.0594Animation control
>>> turtle.setheading[90] >>> turtle.heading[] 90.0595
>>> turtle.setheading[90] >>> turtle.heading[] 90.0596
>>> turtle.setheading[90] >>> turtle.heading[] 90.0597Using screen events
>>> turtle.setheading[90] >>> turtle.heading[] 90.0598
>>> turtle.setheading[90] >>> turtle.heading[] 90.0599 .
>>> turtle.setheading[90] >>> turtle.heading[] 90.01300
>>> turtle.setheading[90] >>> turtle.heading[] 90.01301
>>> turtle.setheading[90] >>> turtle.heading[] 90.0577 .
>>> turtle.setheading[90] >>> turtle.heading[] 90.01303
>>> turtle.setheading[90] >>> turtle.heading[] 90.01304
>>> turtle.setheading[90] >>> turtle.heading[] 90.01305 .
>>> turtle.setheading[90] >>> turtle.heading[] 90.01306Settings and special methods
>>> turtle.setheading[90] >>> turtle.heading[] 90.01307
>>> turtle.setheading[90] >>> turtle.heading[] 90.01308
>>> turtle.setheading[90] >>> turtle.heading[] 90.01309
>>> turtle.setheading[90] >>> turtle.heading[] 90.01310
>>> turtle.setheading[90] >>> turtle.heading[] 90.01311 .
>>> turtle.setheading[90] >>> turtle.heading[] 90.01312
>>> turtle.setheading[90] >>> turtle.heading[] 90.01313
>>> turtle.setheading[90] >>> turtle.heading[] 90.01314
>>> turtle.setheading[90] >>> turtle.heading[] 90.01315Input methods
>>> turtle.setheading[90] >>> turtle.heading[] 90.01316
>>> turtle.setheading[90] >>> turtle.heading[] 90.01317Methods specific to Screen
>>> turtle.setheading[90] >>> turtle.heading[] 90.01318
>>> turtle.setheading[90] >>> turtle.heading[] 90.01319
>>> turtle.setheading[90] >>> turtle.heading[] 90.01320
>>> turtle.setheading[90] >>> turtle.heading[] 90.01321
Methods of RawTurtle/Turtle and corresponding functions¶
Most of the examples in this section refer to a Turtle instance called
>>> turtle.setheading[90] >>> turtle.heading[] 90.08
Turtle motion¶
turtle. forward[distance] ¶ turtle. fd[distance] ¶Parametersdistance – a number [integer or float]
Move the turtle forward by the specified distance, in the direction the turtle is headed
>>> turtle.setheading[90] >>> turtle.heading[] 90.05turtle. back[distance] ¶ turtle. bk[distance] ¶ turtle. backward[distance] ¶Parameters
distance – a number
Move the turtle backward by distance, opposite to the direction the turtle is headed. Do not change the turtle’s heading
>>> turtle.setheading[90] >>> turtle.heading[] 90.013turtle. right[angle] ¶ turtle. rt[angle] ¶Parameters
angle – a number [integer or float]
Turn turtle right by angle units. [Units are by default degrees, but can be set via the
>>> turtle.setheading[90] >>> turtle.heading[] 90.0541 and
>>> turtle.setheading[90] >>> turtle.heading[] 90.0542 functions. ] Định hướng góc phụ thuộc vào chế độ con rùa, xem
>>> turtle.setheading[90] >>> turtle.heading[] 90.01307
>>> turtle.setheading[90] >>> turtle.heading[] 90.041rùa. trái[góc] ¶ . turtle.lt[góc] ¶
angle – a number [integer or 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 đặt thông qua các chức năng
>>> turtle.setheading[90] >>> turtle.heading[] 90.0541 và
>>> turtle.setheading[90] >>> turtle.heading[] 90.0542. ] Định hướng góc phụ thuộc vào chế độ con rùa, xem
>>> turtle.setheading[90] >>> turtle.heading[] 90.01307
>>> turtle.setheading[90] >>> turtle.heading[] 90.045rù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.setheading[90] >>> turtle.heading[] 90.0
1329
Nếu y là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, x phải là một cặp tọa độ hoặc một
>>> turtle.setheading[90] >>> turtle.heading[] 90.01331 [e. g. như được trả về bởi
>>> turtle.setheading[90] >>> turtle.heading[] 90.0535]
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
>>> turtle.setheading[90] >>> turtle.heading[] 90.050rùa. setx[x] ¶
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.setheading[90] >>> turtle.heading[] 90.051rùa. bộ[y] ¶
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.setheading[90] >>> turtle.heading[] 90.052rùa. tiêu đề[to_angle] ¶ . turtle.seth[to_angle] ¶
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 - south
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
>>> turtle.setheading[90] >>> turtle.heading[] 90.01307]
>>> 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ố
extent – a number [or
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1329]các bước – một số nguyên [hoặc
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1329]
Vẽ đường tròn có bán kính cho trước. The center is radius units left of the turtle; extent – an angle – determines which part of the circle is drawn. 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 độ
As the circle is approximated by an inscribed regular polygon, steps determines the number of steps to use. If not given, it will be calculated automatically. Có thể được sử dụng để vẽ đa giác thông thường
>>> turtle.setheading[90] >>> turtle.heading[] 90.050rùa. chấm[kích thước=Không, *color]¶Parameters
size – an integer >= 1 [if given]
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.setheading[90] >>> turtle.heading[] 90.051turtle. đó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.setheading[90] >>> turtle.heading[] 90.01336
>>> turtle.setheading[90] >>> turtle.heading[] 90.052rùa. clearstamp[stampid] ¶Parameters
stampid – an integer, must be return value of previous
>>> turtle.setheading[90] >>> turtle.heading[] 90.0529 call
Delete stamp with given stampid
>>> turtle.setheading[90] >>> turtle.heading[] 90.053turtle. dấu xóa[n=Không]¶Parameters
n – một số nguyên [hoặc
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329]
Delete all or first/last n of turtle’s stamps. Nếu n là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, 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.setheading[90] >>> turtle.heading[] 90.054rùa. hoàn tác[] ¶
Hoàn tác [nhiều lần] [các] hành động rùa cuối cùng. Number of available undo actions is determined by the size of the undobuffer
>>> turtle.setheading[90] >>> turtle.heading[] 90.055turtle. speed[speed=None] ¶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]
Set the turtle’s speed to an integer value in the range 0. 10. If no argument is given, return current speed
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
“fast”. 10
“normal”. 6
"chậm". 3
“slowest”. 1
Speeds from 1 to 10 enforce increasingly faster animation of line drawing and turtle turning
Attention. speed = 0 means that no animation takes place. forward/back makes turtle jump and likewise left/right make the turtle turn instantly
>>> turtle.setheading[90] >>> turtle.heading[] 90.056
Tell Turtle’s state¶
turtle. position[] ¶ turtle. pos[] ¶Return the turtle’s current location [x,y] [as a
>>> turtle.setheading[90] >>> turtle.heading[] 90.01331 vector]
>>> turtle.setheading[90] >>> turtle.heading[] 90.057turtle. towards[x , y=None] ¶Parameters
x – a number or a pair/vector of numbers or a turtle instance
y – a number if x is a number, else
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1329
Return the angle between the line from turtle position to position specified by [x,y], the vector or the other turtle. This depends on the turtle’s start orientation which depends on the mode - “standard”/”world” or “logo”
>>> turtle.setheading[90] >>> turtle.heading[] 90.058turtle. xcor[] ¶
Return the turtle’s x coordinate
>>> turtle.setheading[90] >>> turtle.heading[] 90.059turtle. ycor[] ¶
Return the turtle’s y coordinate
>>> turtle.setheading[90] >>> turtle.heading[] 90.0130turtle. heading[] ¶
Trả về tiêu đề hiện tại của rùa [giá trị tùy thuộc vào chế độ rùa, xem
>>> turtle.setheading[90] >>> turtle.heading[] 90.01307]
>>> turtle.setheading[90] >>> turtle.heading[] 90.0131turtle. distance[x , y=None] ¶Parameters
x – a number or a pair/vector of numbers or a turtle instance
y – a number if x is a number, else
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1329
Return the distance from the turtle to [x,y], the given vector, or the given other turtle, in turtle step units
>>> turtle.setheading[90] >>> turtle.heading[] 90.0132
Settings for measurement¶
turtle. degrees[fullcircle=360. 0] ¶Parametersfullcircle – a number
Set angle measurement units, i. e. set number of “degrees” for a full circle. Default value is 360 degrees
>>> turtle.setheading[90] >>> turtle.heading[] 90.0133turtle. radians[] ¶
Set the angle measurement units to radians. Equivalent to
>>> turtle.setheading[90] >>> turtle.heading[] 90.01344
>>> turtle.setheading[90] >>> turtle.heading[] 90.0134
Điều khiển bút¶
Drawing state¶
turtle. pendown[] ¶ turtle. pd[] ¶ turtle. xuống[] ¶Kéo bút xuống – vẽ khi di chuyển
rùa. penup[] ¶ turtle. 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ó]¶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.setheading[90] >>> turtle.heading[] 90.0135rù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
“pendown”. Đúng sai
“màu bút”. chuỗi màu hoặc bộ màu
“fillcolor”. chuỗi màu hoặc bộ màu
“bù”. số dương
“speed”. 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". [positive number, positive number]
"đề cương". số dương
“tilt”. con số
Từ điển này có thể được sử dụng làm đối số cho lệnh gọi tiếp theo tới
>>> turtle.setheading[90] >>> turtle.heading[] 90.0551 để khôi phục trạng thái bút cũ. Moreover one or more of these attributes can be provided as keyword-arguments. Đ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.setheading[90] >>> turtle.heading[] 90.0136rùa. ngừng hoạt động[] ¶
Trả lại
>>> turtle.setheading[90] >>> turtle.heading[] 90.01346 nếu bút xuống,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01347 nếu bút lên
>>> turtle.setheading[90] >>> turtle.heading[] 90.0137
Color control¶
rùa. bút màu[*args]¶Trả lại hoặc đặt màu bút
Four input formats are allowed
>>> turtle.setheading[90] >>> turtle.heading[] 90.0554
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.setheading[90] >>> turtle.heading[] 90.01349
Set pencolor to colorstring, which is a Tk color specification string, such as
>>> turtle.setheading[90] >>> turtle.heading[] 90.01350,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01351, or
>>> turtle.setheading[90] >>> turtle.heading[] 90.01352
>>> turtle.setheading[90] >>> turtle.heading[] 90.01353
Đặ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.setheading[90] >>> turtle.heading[] 90.01308]
>>> turtle.setheading[90] >>> turtle.heading[] 90.01355
Đặ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.setheading[90] >>> turtle.heading[] 90.0138rùa. màu tô[*args]¶
Trả lại hoặc đặt màu tô
Four input formats are allowed
>>> turtle.setheading[90] >>> turtle.heading[] 90.0555
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.setheading[90] >>> turtle.heading[] 90.01357
Set fillcolor to colorstring, which is a Tk color specification string, such as
>>> turtle.setheading[90] >>> turtle.heading[] 90.01350,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01351, or
>>> turtle.setheading[90] >>> turtle.heading[] 90.01352
>>> turtle.setheading[90] >>> turtle.heading[] 90.01361
Đặ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.setheading[90] >>> turtle.heading[] 90.01308]
>>> turtle.setheading[90] >>> turtle.heading[] 90.01363
Đặt màu tô thành màu RGB được biểu thị bằng r, g và b. Each of r, g, and b must be in the range 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.setheading[90] >>> turtle.heading[] 90.0139rù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.setheading[90] >>> turtle.heading[] 90.0553
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 như được trả về bởi
>>> turtle.setheading[90] >>> turtle.heading[] 90.0554 và
>>> turtle.setheading[90] >>> turtle.heading[] 90.0555
>>> turtle.setheading[90] >>> turtle.heading[] 90.01367,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01368,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01369
Đầu vào như trong
>>> turtle.setheading[90] >>> turtle.heading[] 90.0554, đặt cả hai, màu tô và màu bút, thành giá trị đã cho
>>> turtle.setheading[90] >>> turtle.heading[] 90.01371,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01372
Tương đương với
>>> turtle.setheading[90] >>> turtle.heading[] 90.01373 và
>>> turtle.setheading[90] >>> turtle.heading[] 90.01374 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.setheading[90] >>> turtle.heading[] 90.0410
Xem thêm. Screen method
>>> turtle.setheading[90] >>> turtle.heading[] 90.01308
Đổ đầy¶
rùa. điền[] ¶Return fillstate [
>>> turtle.setheading[90] >>> turtle.heading[] 90.01346 if filling,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01347 else]
>>> turtle.setheading[90] >>> turtle.heading[] 90.0411rùa. begin_fill[] ¶
Được gọi ngay trước khi vẽ một hình cần tô
turtle. end_fill[] ¶Tô màu cho hình được vẽ sau lần gọi cuối cùng tới
>>> turtle.setheading[90] >>> turtle.heading[] 90.0557
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.setheading[90] >>> turtle.heading[] 90.0412
Kiểm soát bản vẽ nhiều hơn¶
rùa. reset[] ¶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.setheading[90] >>> turtle.heading[] 90.0413rù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']]¶Parametersarg – đố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ữ, kiểu 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.setheading[90] >>> turtle.heading[] 90.01347
>>> turtle.setheading[90] >>> turtle.heading[] 90.0414
Trạng thái con rùa¶
Visibility¶
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.setheading[90] >>> turtle.heading[] 90.0415rùa. rùa[] ¶ rùa. st[] ¶
Làm cho con rùa có thể nhìn thấy
>>> turtle.setheading[90] >>> turtle.heading[] 90.0416rùa. hiển thị[] ¶
Trả lại
>>> turtle.setheading[90] >>> turtle.heading[] 90.01346 nếu Rùa được hiển thị,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01347 nếu nó bị ẩn
>>> turtle.setheading[90] >>> turtle.heading[] 90.0417
Vẻ 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. “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.setheading[90] >>> turtle.heading[] 90.01311
>>> turtle.setheading[90] >>> turtle.heading[] 90.0418rù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
“user”. đ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
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
569“noresize”. không có sự thích nghi nào về ngoại hình của con rùa diễn ra
>>> turtle.setheading[90] >>> turtle.heading[] 90.01384 được gọi bởi
>>> turtle.setheading[90] >>> turtle.heading[] 90.0569 khi được sử dụng với các đối số
>>> turtle.setheading[90] >>> turtle.heading[] 90.0419rù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.setheading[90] >>> turtle.heading[] 90.0450rù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.setheading[90] >>> turtle.heading[] 90.0451rùa. độ nghiêng[góc] ¶
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.setheading[90] >>> turtle.heading[] 90.0452rùa. góc nghiêng[góc] ¶
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.setheading[90] >>> turtle.heading[] 90.0453
Không dùng nữa kể từ phiên bản 3. 1
rùa. nghiêng[góc=Không có]¶Parametersgóc – một số [tùy chọn]
Đặt hoặc trả về 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. return the current tilt-angle, i. e. góc giữa hướng của hình con rùa và hướng của con rùa [hướng di chuyển của nó]
>>> turtle.setheading[90] >>> turtle.heading[] 90.0454rùa. shapetransform[t11=Không, t12=None, t21=None, t22=None]¶Parameters
t11 – một số [tùy chọn]
t12 – một số [tùy chọn]
t21 – một số [tùy chọn]
t12 – một số [tùy chọn]
Đặt hoặc trả về ma trận biến đổi hiện tại của hình con rùa
Nếu không có phần tử nào của ma trận được đưa ra, hãy trả về ma trận biến đổi dưới dạng một bộ gồm 4 phần tử. Mặt khác, đặt các phần tử đã cho và biến đổi hình con rùa theo ma trận bao gồm hàng đầu tiên t11, t12 và hàng thứ hai t21, t22. Định thức t11 * t22 - t12 * t21 không được bằng 0, nếu không sẽ xảy ra lỗi. Chỉnh sửa stretchfactor, shearfactor và tiltangle theo ma trận đã cho
>>> turtle.setheading[90] >>> turtle.heading[] 90.0455rùa. get_shapepoly[] ¶
Trả về đa giác hình dạng hiện tại dưới dạng bộ cặp tọa độ. Điều này có thể được sử dụng để xác định một hình dạng mới hoặc các thành phần của một hình dạng ghép
>>> turtle.setheading[90] >>> turtle.heading[] 90.0456
Sử dụng sự kiện¶
rùa. title[vui , btn=1, add=None]Parametersfun – một hàm có hai đối số sẽ được gọi với tọa độ của điểm được nhấp trên khung vẽ
btn – số nút chuột, mặc định là 1 [nút chuột trái]
thêm –
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346 hoặc>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1347 – nếu là>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346, một ràng buộc mới sẽ được thêm vào, nếu không nó sẽ thay thế một ràng buộc cũ
Liên kết thú vị với các sự kiện nhấp chuột trên con rùa này. Nếu niềm vui là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, các ràng buộc hiện có sẽ bị xóa. Ví dụ cho con rùa vô danh, tôi. e. cách thủ tục
>>> turtle.setheading[90] >>> turtle.heading[] 90.0457rùa. ra mắt[vui , btn=1, add=None]¶Parameters
fun – một hàm có hai đối số sẽ được gọi với tọa độ của điểm được nhấp trên khung vẽ
btn – số nút chuột, mặc định là 1 [nút chuột trái]
thêm –
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346 hoặc>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1347 – nếu là>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346, một ràng buộc mới sẽ được thêm vào, nếu không nó sẽ thay thế một ràng buộc cũ
Liên kết thú vị với các sự kiện nhả nút chuột trên con rùa này. Nếu niềm vui là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, các ràng buộc hiện có sẽ bị xóa
>>> turtle.setheading[90] >>> turtle.heading[] 90.0458rùa. ondrag[vui , btn=1, add=None]¶Parameters
fun – một hàm có hai đối số sẽ được gọi với tọa độ của điểm được nhấp trên khung vẽ
btn – số nút chuột, mặc định là 1 [nút chuột trái]
thêm –
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346 hoặc>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1347 – nếu là>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346, một ràng buộc mới sẽ được thêm vào, nếu không nó sẽ thay thế một ràng buộc cũ
Liên kết thú vị với các sự kiện di chuyển chuột trên con rùa này. Nếu niềm vui là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, các ràng buộc hiện có sẽ bị xóa
Nhận xét. Mỗi chuỗi sự kiện di chuyển chuột trên một con rùa được bắt đầu bằng một sự kiện nhấp chuột trên con rùa đó
>>> turtle.setheading[90] >>> turtle.heading[] 90.0459
Sau đó, nhấp và kéo Rùa sẽ di chuyển nó trên màn hình do đó tạo ra các hình vẽ tay [nếu bút bị hỏng]
Phương pháp rùa đặc biệt¶
rùa. begin_poly[] ¶Bắt đầu ghi các đỉnh của một đa giác. Vị trí con rùa hiện tại là đỉnh đầu tiên của đa giác
rùa. end_poly[] ¶Dừng ghi các đỉnh của một đa giác. Vị trí con rùa hiện tại là đỉnh cuối cùng của đa giác. Điều này sẽ được kết nối với đỉnh đầu tiên
rùa. get_poly[] ¶Trả lại đa giác được ghi cuối cùng
>>> turtle.setheading[90] >>> turtle.heading[] 90.0500rùa. nhân bản[] ¶
Tạo và trả về một bản sao của con rùa với cùng vị trí, tiêu đề và thuộc tính của con rùa
>>> turtle.setheading[90] >>> turtle.heading[] 90.0501rùa. con rùa[] ¶ con rùa. getpen[] ¶
Trả lại chính đối tượng Rùa. Chỉ sử dụng hợp lý. như một chức năng để trả về "rùa ẩn danh"
>>> turtle.setheading[90] >>> turtle.heading[] 90.0502rùa. nhận màn hình[] ¶
Trả lại đối tượng
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.05 mà con rùa đang vẽ. Các phương thức TurtleScreen sau đó có thể được gọi cho đối tượng đó
>>> turtle.setheading[90] >>> turtle.heading[] 90.0503rùa. setundobuffer[kích thước] ¶
size – một số nguyên hoặc
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329
Đặt hoặc vô hiệu hóa bộ đệm. Nếu kích thước là một số nguyên, một bộ hoàn tác trống có kích thước đã cho sẽ được cài đặt. size đưa ra số lượng hành động rùa tối đa có thể được hoàn tác bằng phương thức/hàm
>>> turtle.setheading[90] >>> turtle.heading[] 90.0532. Nếu kích thước là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, bộ hoàn tác bị vô hiệu hóa
>>> turtle.setheading[90] >>> turtle.heading[] 90.0504rùa. các mục hoàn tác bộ đệm[] ¶
Trả về số mục nhập trong bộ hoàn tác
>>> turtle.setheading[90] >>> turtle.heading[] 90.0505
Các hình ghép¶
Để sử dụng các hình con rùa phức hợp, bao gồm một số đa giác có màu khác nhau, bạn phải sử dụng lớp trợ giúp
>>> turtle.setheading[90] >>> turtle.heading[] 90.04102 một cách rõ ràng như được mô tả bên dưới
Tạo một đối tượng Shape rỗng kiểu “compound”
Thêm bao nhiêu thành phần vào đối tượng này nếu muốn, sử dụng phương thức
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4103Ví dụ
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
506Bây giờ hãy thêm Hình dạng vào danh sách hình dạng của Màn hình và sử dụng nó
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
507
Ghi chú
Lớp
>>> turtle.setheading[90] >>> turtle.heading[] 90.04102 được sử dụng nội bộ bởi phương thức
>>> turtle.setheading[90] >>> turtle.heading[] 90.01311 theo nhiều cách khác nhau. Người lập trình ứng dụng chỉ phải xử lý lớp Hình dạng khi sử dụng các hình dạng phức hợp như được hiển thị ở trên
Các phương thức của TurtleScreen/Screen và các chức năng tương ứng¶
Hầu hết các ví dụ trong phần này đề cập đến một phiên bản TurtleScreen có tên là
>>> turtle.setheading[90] >>> turtle.heading[] 90.04106
Điều khiển cửa sổ¶
rùa. bgcolor[*args]¶Parametersargs – một chuỗi màu hoặc ba số trong phạm vi 0. colormode hoặc một bộ 3 số như vậy
Đặt hoặc trả về màu nền của TurtleScreen
>>> turtle.setheading[90] >>> turtle.heading[] 90.0508rùa. bgpic[picname=Không có]¶Parameters
picname – một chuỗi, tên của tệp gif hoặc
>>> turtle.setheading[90] >>> turtle.heading[] 90.04107 hoặc
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329
Đặt hình nền hoặc trả về tên của hình nền hiện tại. Nếu picname là tên tệp, hãy đặt hình ảnh tương ứng làm nền. Nếu picname là
>>> turtle.setheading[90] >>> turtle.heading[] 90.04107, hãy xóa hình nền, nếu có. Nếu picname là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, hãy trả lại tên tệp của ảnh nền hiện tại
>>> turtle.setheading[90] >>> turtle.heading[] 90.0509rùa. xóa[]
Ghi chú
Phương thức TurtleScreen này chỉ khả dụng dưới dạng hàm toàn cầu dưới tên
>>> turtle.setheading[90] >>> turtle.heading[] 90.04111. Hàm toàn cục
>>> turtle.setheading[90] >>> turtle.heading[] 90.04112 là một hàm khác bắt nguồn từ phương thức Rùa
>>> turtle.setheading[90] >>> turtle.heading[] 90.04112rù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. nền trắng, không có hình nền, không có ràng buộc sự kiện và theo dõi trên
rùa. đặt lại[]Ghi chú
Phương thức TurtleScreen này chỉ khả dụng dưới dạng hàm toàn cầu dưới tên
>>> turtle.setheading[90] >>> turtle.heading[] 90.04114. Hàm toàn cục
>>> turtle.setheading[90] >>> turtle.heading[] 90.04115 là một hàm khác bắt nguồn từ phương thức Rùa
>>> turtle.setheading[90] >>> turtle.heading[] 90.04115rùa. đặt lại màn hình[] ¶
Đặt lại tất cả Rùa trên Màn hình về trạng thái ban đầu
rùa. kích thước màn hình[canvwidth=Không có, canvheight=None, bg=None]¶Parameterscanvwidth – số nguyên dương, chiều rộng mới của canvas tính bằng pixel
canvheight – số nguyên dương, chiều cao mới của canvas tính bằng pixel
bg – chuỗi màu hoặc bộ màu, màu nền mới
Nếu không có đối số nào được đưa ra, hãy trả về giá trị hiện tại [canvaswidth, canvasheight]. Khác thay đổi kích thước canvas mà rùa đang vẽ trên đó. Không thay đổi cửa sổ bản vẽ. Để quan sát các phần ẩn của canvas, hãy sử dụng thanh cuộn. Với phương pháp này, người ta có thể hiển thị các phần của bản vẽ nằm ngoài canvas trước đó.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0510
e. g. để tìm kiếm một con rùa trốn thoát nhầm ;-]
rùa. tọa độ setworld[llx , lly, urx, ury]¶Parametersllx – một số, tọa độ x của góc dưới bên trái của canvas
lly – một số, tọa độ y của góc dưới bên trái của canvas
urx – một số, tọa độ x của góc trên bên phải của canvas
ury – một số, tọa độ y của góc trên bên phải của canvas
Thiết lập hệ tọa độ do người dùng định nghĩa và chuyển sang chế độ “thế giới” nếu cần. Điều này thực hiện một
>>> turtle.setheading[90] >>> turtle.heading[] 90.04117. Nếu chế độ “thế giới” đã hoạt động, tất cả các bản vẽ được vẽ lại theo tọa độ mới
CHÚ Ý. trong các góc của hệ tọa độ do người dùng xác định có thể bị biến dạng
>>> turtle.setheading[90] >>> turtle.heading[] 90.0511
Điều khiển hoạt ảnh¶
rùa. độ trễ[độ trễ=Không có]¶Parametersđộ trễ – số nguyên dương
Đặt hoặc trả về độ trễ bản vẽ tính bằng mili giây. [Đây là khoảng thời gian xấp xỉ giữa hai lần cập nhật canvas liên tiếp. ] Độ trễ vẽ càng lâu, hoạt ảnh càng chậm
Đối số tùy chọn
>>> turtle.setheading[90] >>> turtle.heading[] 90.0512rùa. trình theo dõi[n=Không có, delay=None]¶Parameters
n – số nguyên không âm
độ trễ – số nguyên không âm
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. ] 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
>>> turtle.setheading[90] >>> turtle.heading[] 90.0595]
>>> turtle.setheading[90] >>> turtle.heading[] 90.0513rùa. cập nhật[] ¶
Thực hiện cập nhật TurtleScreen. Được sử dụng khi tắt trình theo dõi
Xem thêm phương pháp RawTurtle/Turtle
>>> turtle.setheading[90] >>> turtle.heading[] 90.0533
Sử dụng các sự kiện trên màn hình¶
rùa. nghe này[xdummy=Không, ydummy=None]¶Đặt trọng tâm vào TurtleScreen [để thu thập các sự kiện quan trọng]. Các đối số giả được cung cấp để có thể chuyển
>>> turtle.setheading[90] >>> turtle.heading[] 90.0598 sang phương thức titlerùa. onkey[vui , key . ]¶turtle.onkeyrelease[thú vị , phím]¶Parameters
fun – một hàm không có đối số hoặc
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1329chìa khóa - một chuỗi. chìa khóa [e. g. “a”] hoặc phím-ký hiệu [e. g. "không gian"]
Liên kết thú vị với sự kiện phát hành khóa của khóa. Nếu niềm vui là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, các ràng buộc sự kiện sẽ bị xóa. Nhận xét. để có thể đăng ký các sự kiện chính, TurtleScreen phải có tiêu điểm. [Xem phương pháp
>>> turtle.setheading[90] >>> turtle.heading[] 90.0598. ]
>>> turtle.setheading[90] >>> turtle.heading[] 90.0514rùa. nhấn phím[vui , phím=None]¶Parameters
fun – một hàm không có đối số hoặc
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1329chìa khóa - một chuỗi. chìa khóa [e. g. “a”] hoặc phím-ký hiệu [e. g. "không gian"]
Liên kết niềm vui với sự kiện nhấn phím của phím nếu phím được cung cấp hoặc với bất kỳ sự kiện nhấn phím nào nếu không có phím nào được cung cấp. Nhận xét. để có thể đăng ký các sự kiện chính, TurtleScreen phải có tiêu điểm. [Xem phương pháp
>>> turtle.setheading[90] >>> turtle.heading[] 90.0598. ]
>>> turtle.setheading[90] >>> turtle.heading[] 90.0515rùa. title[vui , btn . =1, add=None]¶turtle.nhấp chuột trên màn hình[thú vị , btn=1, add=None]¶Parameters
fun – một hàm có hai đối số sẽ được gọi với tọa độ của điểm được nhấp trên khung vẽ
btn – số nút chuột, mặc định là 1 [nút chuột trái]
thêm –
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346 hoặc>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1347 – nếu là>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346, một ràng buộc mới sẽ được thêm vào, nếu không nó sẽ thay thế một ràng buộc cũ
Liên kết thú vị với các sự kiện nhấp chuột trên màn hình này. Nếu niềm vui là
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329, các ràng buộc hiện có sẽ bị xóa
Ví dụ về phiên bản TurtleScreen có tên là
>>> turtle.setheading[90] >>> turtle.heading[] 90.04106 và phiên bản Rùa có tên là
>>> turtle.setheading[90] >>> turtle.heading[] 90.08
>>> turtle.setheading[90] >>> turtle.heading[] 90.0516
Ghi chú
Phương thức TurtleScreen này chỉ khả dụng dưới dạng hàm toàn cục dưới tên
>>> turtle.setheading[90] >>> turtle.heading[] 90.04132. Hàm toàn cục
>>> turtle.setheading[90] >>> turtle.heading[] 90.04133 là một hàm khác bắt nguồn từ phương thức Rùa
>>> turtle.setheading[90] >>> turtle.heading[] 90.04133rùa. đúng giờ[vui , t=0]¶Parameters
fun – một hàm không có đối số
t – một số >= 0
Cài đặt bộ hẹn giờ gọi vui sau t mili giây
>>> turtle.setheading[90] >>> turtle.heading[] 90.0517rùa. vòng lặp chính[] ¶ rùa. xong[] ¶
Bắt đầu vòng lặp sự kiện - gọi hàm mainloop của Tkinter. Phải là câu lệnh cuối cùng trong chương trình đồ họa con rùa. Không được sử dụng nếu tập lệnh được chạy từ bên trong IDLE ở chế độ -n [Không có quy trình phụ] - để sử dụng tương tác đồ họa con rùa
>>> turtle.setheading[90] >>> turtle.heading[] 90.0518
Phương thức nhập liệu¶
rùa. văn bản nhập[tiêu đề , nhắc]¶Parameterstiêu đề - chuỗi
dấu nhắc - chuỗi
Bật lên một cửa sổ hộp thoại để nhập chuỗi. 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. Trả lại đầu vào chuỗi. Nếu hộp thoại bị hủy, hãy trả lại
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329
>>> turtle.setheading[90] >>> turtle.heading[] 90.0519rùa. số[tiêu đề , nhắc, default=None, minval=None, maxval=None]¶Parameters
tiêu đề - chuỗi
dấu nhắc - chuỗi
mặc định – số [tùy chọn]
minval – số [tùy chọn]
maxval – số [tùy chọn]
Bật lên một cửa sổ hộp thoại để nhập số. tiêu đề 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 số cần nhập. mặc định. giá trị mặc định, minval. giá trị tối thiểu cho đầu vào, maxval. giá trị tối đa cho đầu vào. Đầu vào số phải nằm trong phạm vi minval. maxval nếu chúng được đưa ra. Nếu không, một gợi ý sẽ được đưa ra và hộp thoại vẫn mở để chỉnh sửa. Trả về số đầu vào. Nếu hộp thoại bị hủy, hãy trả lại
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329
>>> turtle.setheading[90] >>> turtle.heading[] 90.0520
Cài đặt và phương pháp đặc biệt¶
rùa. chế độ[chế độ=Không có]¶Parameterschế độ – một trong các chuỗi “tiêu chuẩn”, “logo” hoặc “thế giới”
Đặt chế độ rùa [“tiêu chuẩn”, “logo” hoặc “thế giới”] và thực hiện đặt lại. Nếu chế độ không được cung cấp, chế độ hiện tại được trả về
Chế độ “tiêu chuẩn” tương thích với
>>> turtle.setheading[90] >>> turtle.heading[] 90.08 cũ. Chế độ “logo” tương thích với hầu hết đồ họa Logo rùa. Chế độ “thế giới” sử dụng “tọa độ thế giới” do người dùng xác định. Chú ý. ở chế độ này, các góc có vẻ bị biến dạng nếu tỷ lệ đơn vị của
>>> turtle.setheading[90] >>> turtle.heading[] 90.04138 không bằng 1
Cách thức
tiêu đề rùa ban đầu
góc dương
"Tiêu chuẩn"
bên phải [phía đông]
ngược chiều kim đồng hồ
"Logo"
hướng lên trên [bắc]
theo chiều kim đồng hồ
>>> turtle.setheading[90] >>> turtle.heading[] 90.0521rùa. colormode[cmode=None] ¶Parameters
cmode – one of the values 1. 0 hoặc 255
Return the colormode or set it to 1. 0 or 255. Sau đó, các giá trị r, g, b của bộ ba màu phải nằm trong khoảng 0. *cmode*
>>> turtle.setheading[90] >>> turtle.heading[] 90.0522turtle. getcanvas[] ¶
Return the Canvas of this TurtleScreen. Useful for insiders who know what to do with a Tkinter Canvas
>>> turtle.setheading[90] >>> turtle.heading[] 90.0523turtle. getshapes[] ¶
Return a list of names of all currently available turtle shapes
>>> turtle.setheading[90] >>> turtle.heading[] 90.0524
There are three different ways to call this function
tên là tên của tệp gif và hình dạng là
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1329. Install the corresponding image shape>>> turtle.setheading[90] >>> turtle.heading[] 90.0
525Ghi 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.setheading[90] >>> turtle.heading[] 90.0
526name is an arbitrary string and shape is a [compound]
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4102 object. Install the corresponding compound shape
Thêm hình con rùa vào danh sách hình dạng của TurtleScreen. Only thusly registered shapes can be used by issuing the command
>>> turtle.setheading[90] >>> turtle.heading[] 90.04141turtle. turtles[] ¶
Return the list of turtles on the screen
>>> turtle.setheading[90] >>> turtle.heading[] 90.0527turtle. window_height[] ¶
Return the height of the turtle window
>>> turtle.setheading[90] >>> turtle.heading[] 90.0528rùa. window_width[] ¶
Return the width of the turtle window
>>> turtle.setheading[90] >>> turtle.heading[] 90.0529
Methods specific to Screen, not inherited from TurtleScreen¶
turtle. bye[] ¶Shut the turtlegraphics window
rùa. exit title[] ¶Ràng buộc phương thức
>>> turtle.setheading[90] >>> turtle.heading[] 90.01318 để nhấp chuột trên Màn hình
If the value “using_IDLE” in the configuration dictionary is
>>> turtle.setheading[90] >>> turtle.heading[] 90.01347 [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.setheading[90] >>> turtle.heading[] 90.01346 in
>>> turtle.setheading[90] >>> turtle.heading[] 90.04146. 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.setheading[90] >>> turtle.heading[] 90.04146 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.setheading[90] >>> turtle.heading[] 90.0
1329, center window horizontallystarty – if positive, starting position in pixels from the top edge of the screen, if negative from the bottom edge, if
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1329, center window vertically
>>> turtle.setheading[90] >>> turtle.heading[] 90.00turtle. tiêu đề[chuỗi tiêu đề] ¶
titlestring – a string that is shown in the titlebar of the turtle graphics window
Đặt tiêu đề của cửa sổ rùa thành chuỗi tiêu đề
>>> turtle.setheading[90] >>> turtle.heading[] 90.01
Public 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
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.07 or a
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.05
Create a turtle. Rùa có tất cả các phương pháp được mô tả ở trên là “phương pháp của Rùa/RawTurtle”
class turtle. Turtle ¶Subclass of RawTurtle, has the same interface but draws on a default
>>> turtle.setheading[90] >>> turtle.heading[] 90.0507 object created automatically when needed for the first timeclass turtle. TurtleScreen[cv] ¶
cv – a
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.06
Provides screen oriented methods like
>>> turtle.setheading[90] >>> turtle.heading[] 90.04155 etc. that are described aboveclass turtle. Screen ¶
Subclass of TurtleScreen, with four methods added .
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.setheading[90] >>> turtle.heading[] 90.04156 must follow this specification
type_
data
“polygon”
a polygon-tuple, i. e. a tuple of pairs of coordinates
“image”
an image [in this form only used internally. ]
"hợp chất"
>>> turtle.setheading[90] >>> turtle.heading[] 90.01329 [a compound shape has to be constructed using the
>>> turtle.setheading[90] >>> turtle.heading[] 90.04103 method]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.02
See Compound shapes .
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.setheading[90] >>> turtle.heading[] 90.0
4159 phép cộng véc tơ>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4160 phép trừ véc tơ>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4161 sản phẩm bên trongPhép nhân
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4162 và>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4163 với vô hướng>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4164 giá trị tuyệt đối của axoay vòng
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4165
Trợ giúp và cấu hình¶
Cách sử dụng trợ giúp¶
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
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4166 on methods or functions displays the docstrings>>> turtle.setheading[90] >>> turtle.heading[] 90.0
3Cá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
These 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.setheading[90] >>> turtle.heading[] 90.04167. Nó được dùng làm khuôn mẫu để dịch các chuỗi tài liệu sang các ngôn ngữ khác nhau
If you [or your students] want to use
>>> turtle.setheading[90] >>> turtle.heading[] 90.08 with online help in your native language, you have to translate the docstrings and save the resulting file as e. g.
>>> turtle.setheading[90] >>> turtle.heading[] 90.04169
If you have an appropriate entry in your
>>> turtle.setheading[90] >>> turtle.heading[] 90.04146 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.setheading[90] >>> turtle.heading[] 90.04146 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.05
Short explanation of selected entries
The first four lines correspond to the arguments of the
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4172 methodLine 5 and 6 correspond to the arguments of the method
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4173shape can be any of the built-in shapes, e. g. arrow, turtle, etc. For more info try
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4174If you want to use no fillcolor [i. e. make the turtle transparent], you have to write
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4175 [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.setheading[90] >>> turtle.heading[] 90.0
4176If you set e. g.
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4177 the docstringdict>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4178 will be loaded at import time [if present on the import path, e. g. in the same directory as>>> turtle.setheading[90] >>> turtle.heading[] 90.0
8]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.setheading[90] >>> turtle.heading[] 90.0
1346 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>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1319 to enter the mainloop
There can be a
>>> turtle.setheading[90] >>> turtle.heading[] 90.04146 file in the directory where
>>> turtle.setheading[90] >>> turtle.heading[] 90.08 is stored and an additional one in the current working directory. The latter will override the settings of the first one
The
>>> turtle.setheading[90] >>> turtle.heading[] 90.04185 directory contains a
>>> turtle.setheading[90] >>> turtle.heading[] 90.04146 file. You can study it as an example and see its effects when running the demos [preferably not from within the demo-viewer]
>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
4187 — Demo scripts¶
The
>>> turtle.setheading[90] >>> turtle.heading[] 90.04187 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.06
Alternatively, you can run the demo scripts individually. For example,
>>> turtle.setheading[90] >>> turtle.heading[] 90.07
The
>>> turtle.setheading[90] >>> turtle.heading[] 90.04187 package directory contains
A demo viewer
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4190 which can be used to view the sourcecode of the scripts and run them at the same timeMultiple scripts demonstrating different features of the
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
8 module. Examples can be accessed via the Examples menu. They can also be run standaloneA
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4146 file which serves as an example of how to write and use such files
The demo scripts are
Name
Description
Đặc trưng
bytedesign
complex classical turtle graphics pattern
>>> turtle.setheading[90] >>> turtle.heading[] 90.0596, delay,
>>> turtle.setheading[90] >>> turtle.heading[] 90.0597
chaos
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
turtles as clock’s hands, ontimer
colormixer
experiment with r, g, b
>>> turtle.setheading[90] >>> turtle.heading[] 90.0579
forest
3 breadth-first trees
randomization
fractalcurves
Hilbert & Koch curves
recursion
lindenmayer
ethnomathematics [indian kolams]
L-System
minimal_hanoi
Towers of Hanoi
Rectangular Turtles as Hanoi discs [shape, shapesize]
nim
play the classical nim game with three heaps of sticks against the computer
rùa như nimsticks, điều khiển sự kiện [chuột, bàn phím]
paint
super minimalistic drawing program
>>> turtle.setheading[90] >>> turtle.heading[] 90.0577
peace
elementary
turtle. appearance and animation
penrose
aperiodic tiling with kites and darts
>>> turtle.setheading[90] >>> turtle.heading[] 90.0529
planet_and_moon
simulation of gravitational system
hình dạng ghép,
>>> turtle.setheading[90] >>> turtle.heading[] 90.01331
round_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
a [graphical] breadth first tree [using generators]
>>> turtle.setheading[90] >>> turtle.heading[] 90.0583
two_canvases
simple design
turtles on two canvases
wikipedia
a pattern from the wikipedia article on turtle graphics
>>> turtle.setheading[90] >>> turtle.heading[] 90.0583,
>>> turtle.setheading[90] >>> turtle.heading[] 90.0532
yinyang
another elementary example
>>> turtle.setheading[90] >>> turtle.heading[] 90.0527
Have fun
Changes since Python 2. 6¶
The methods
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4503,>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4504 and>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4505 have been eliminated. Methods with these names and functionality are now available only as methods of>>> turtle.setheading[90] >>> turtle.heading[] 90.0
507. The functions derived from these remain available. [In fact already in 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.setheading[90] >>> turtle.heading[] 90.0
507 tương ứng. ]The method
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4509 has been eliminated. The behaviour of>>> turtle.setheading[90] >>> turtle.heading[] 90.0
557 and>>> turtle.setheading[90] >>> turtle.heading[] 90.0
558 have changed slightly. now every filling-process must be completed with an>>> turtle.setheading[90] >>> turtle.heading[] 90.0
558 callA method
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4513 has been added. It returns a boolean value.>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1346 if a filling process is under way,>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1347 otherwise. This behaviour corresponds to a>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4516 call without arguments in Python 2. 6
Changes since Python 3. 0¶
The methods
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4517,>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4518 and>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4519 have been added. Thus the full range of regular linear transforms is now available for transforming turtle shapes.>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4520 has been enhanced in functionality. it now can be used to get or set the tiltangle.>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4521 has been deprecatedThe method
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4522 has been added as a complement to>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4523 which in fact binds actions to the keyrelease event. Accordingly the latter has got an alias.>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4524The method
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4525 has been added. So when working only with Screen and Turtle objects one must not additionally import>>> turtle.setheading[90] >>> turtle.heading[] 90.0
1305 anymoreHai phương thức nhập liệu đã được thêm vào
>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4527 và>>> turtle.setheading[90] >>> turtle.heading[] 90.0
4528. These popup input dialogs and return strings and numbers respectively