-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-138845: Correct turtle module documentation misconceptions #138882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
F0RRZZ
wants to merge
4
commits into
python:main
Choose a base branch
from
F0RRZZ:issue-138845
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,9 +524,17 @@ Turtle motion | |
|
||
:param angle: a number (integer or float) | ||
|
||
Turn turtle right by *angle* units. (Units are by default degrees, but | ||
can be set via the :func:`degrees` and :func:`radians` functions.) Angle | ||
orientation depends on the turtle mode, see :func:`mode`. | ||
Turn turtle right by *angle* units. | ||
|
||
The unit of measurement is controlled by :func:`degrees` and | ||
:func:`radians`: | ||
|
||
* By default, 360.0 units form a full circle (degrees). | ||
* After calling :func:`radians`, ``2*math.pi`` units form a full circle. | ||
* Custom values can be set with :func:`degrees`. | ||
|
||
Orientation of the turn depends in the current turtle mode, | ||
see :func:`mode`. | ||
|
||
.. doctest:: | ||
:skipif: _tkinter is None | ||
|
@@ -549,9 +557,17 @@ Turtle motion | |
|
||
:param angle: a number (integer or float) | ||
|
||
Turn turtle left by *angle* units. (Units are by default degrees, but | ||
can be set via the :func:`degrees` and :func:`radians` functions.) Angle | ||
orientation depends on the turtle mode, see :func:`mode`. | ||
Turn turtle left by *angle* units. | ||
|
||
The unit of measurement is controlled by :func:`degrees` and | ||
:func:`radians`: | ||
|
||
* By default, 360.0 units form a full circle (degrees). | ||
* After calling :func:`radians`, ``2*math.pi`` units form a full circle. | ||
* Custom values can be set with :func:`degrees`. | ||
|
||
Orientation of the turn depends in the current turtle mode, | ||
see :func:`mode`. | ||
|
||
.. doctest:: | ||
:skipif: _tkinter is None | ||
|
@@ -1008,10 +1024,16 @@ Settings for measurement | |
|
||
.. function:: degrees(fullcircle=360.0) | ||
|
||
:param fullcircle: a number | ||
:param fullcircle: a number representing units for a full circle | ||
|
||
Set angle measurement units so that a full circle is *fullcircle* | ||
units. The default value is ``360.0`` (i.e. conventional degrees). | ||
|
||
Set angle measurement units, i.e. set number of "degrees" for a full circle. | ||
Default value is 360 degrees. | ||
.. seealso:: | ||
:func:`radians` | ||
:func:`mode` | ||
:func:`left` | ||
:func:`right` | ||
|
||
.. doctest:: | ||
:skipif: _tkinter is None | ||
|
@@ -1030,11 +1052,29 @@ Settings for measurement | |
>>> turtle.heading() | ||
90.0 | ||
|
||
>>> # Change angle measurement unit to radians (where a full circle | ||
>>> # equals 2π radians, so 90 degrees becomes π/2 radians) | ||
>>> import math | ||
>>> turtle.degrees(2*math.pi) | ||
>>> turtle.heading() | ||
1.5707963267948966 | ||
>>> turtle.degrees(360) | ||
>>> turtle.heading() | ||
90.0 | ||
|
||
|
||
.. function:: radians() | ||
|
||
Set the angle measurement units to radians. Equivalent to | ||
``degrees(2*math.pi)``. | ||
Set the angle measurement unit to radians. | ||
|
||
Equivalent to:: | ||
|
||
degrees(2*math.pi) | ||
|
||
After this call, one full circle correspond to | ||
``2*math.pi`` units. | ||
|
||
.. seealso:: :func:`degrees`, :func:`left`, :func:`right` | ||
|
||
.. doctest:: | ||
:skipif: _tkinter is None | ||
|
@@ -1356,8 +1396,27 @@ More drawing control | |
|
||
.. function:: reset() | ||
|
||
Delete the turtle's drawings from the screen, re-center the turtle and set | ||
variables to the default values. | ||
Delete the turtle's drawings from the screen. Move the turtle | ||
to position ``(0, 0)``, set its heading to the default | ||
(facing east in standard mode) and restore the following state | ||
variables to their initial values: | ||
|
||
* position: ``(0, 0)`` | ||
* heading: ``0`` (east) | ||
|
||
* pen state: down (drawing) | ||
* pensize: ``1`` | ||
* pencolor: black | ||
* fillcolor: white | ||
* speed: ``3`` | ||
* turtle visibility: shown | ||
* shape size: ``(1.0, 1.0)`` (no stretch) | ||
* shape shear: ``0.0`` (no shear) | ||
* shape tilt: ``0.0`` (no tilt) | ||
|
||
.. note:: | ||
The angle unit is **not reset** to degrees. If | ||
:func:`radians` was used before :func:`reset`, | ||
the unit remains radians. | ||
|
||
.. doctest:: | ||
:skipif: _tkinter is None | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1580,7 +1580,7 @@ def reset(self): | |
Will be overwritten by parent class | ||
""" | ||
self._position = Vec2D(0.0, 0.0) | ||
self._orient = TNavigator.START_ORIENTATION[self._mode] | ||
self._orient = TNavigator.START_ORIENTATION[self._mode] | ||
|
||
def _setmode(self, mode=None): | ||
"""Set turtle-mode to 'standard', 'world' or 'logo'. | ||
|
@@ -1612,9 +1612,8 @@ def degrees(self, fullcircle=360.0): | |
Optional argument: | ||
fullcircle - a number | ||
|
||
Set angle measurement units, i. e. set number | ||
of 'degrees' for a full circle. Default value is | ||
360 degrees. | ||
Set angle measurement units so that a full circle is *fullcircle* | ||
units. The default value is `360.0` (i.e. conventional degrees). | ||
|
||
Example (for a Turtle instance named turtle): | ||
>>> turtle.left(90) | ||
|
@@ -1627,12 +1626,20 @@ def degrees(self, fullcircle=360.0): | |
>>> turtle.heading() | ||
100 | ||
|
||
Change angle measurement unit to radians (where a full circle | ||
equals 2π radians, so 90 degrees becomes π/2 radians) | ||
>>> turtle.degrees(2*math.pi) | ||
>>> turtle.heading() | ||
1.5707963267948966 | ||
|
||
""" | ||
self._setDegreesPerAU(fullcircle) | ||
|
||
def radians(self): | ||
""" Set the angle measurement units to radians. | ||
|
||
Equivalent to calling `degrees(2*math.pi)` | ||
|
||
No arguments. | ||
|
||
Example (for a Turtle instance named turtle): | ||
|
@@ -1716,9 +1723,17 @@ def right(self, angle): | |
Argument: | ||
angle -- a number (integer or float) | ||
|
||
Turn turtle right by angle units. (Units are by default degrees, | ||
but can be set via the degrees() and radians() functions.) | ||
Angle orientation depends on mode. (See this.) | ||
Turn turtle right by *angle* units. | ||
|
||
The unit of measurement is controlled by `degrees()` and | ||
`radians()`: | ||
|
||
* By default, 360.0 units form a full circle (degrees). | ||
* After calling `radians()`, ``2*math.pi`` units form a full circle. | ||
* Custom values can be set with `degrees(fullcircle)`. | ||
|
||
Orientation of the turn depends in the current turtle mode, | ||
see function `mode()`. | ||
|
||
Example (for a Turtle instance named turtle): | ||
>>> turtle.heading() | ||
|
@@ -1737,9 +1752,17 @@ def left(self, angle): | |
Argument: | ||
angle -- a number (integer or float) | ||
|
||
Turn turtle left by angle units. (Units are by default degrees, | ||
but can be set via the degrees() and radians() functions.) | ||
Angle orientation depends on mode. (See this.) | ||
Turn turtle left by *angle* units. | ||
|
||
The unit of measurement is controlled by `degrees()` and | ||
`radians()`: | ||
|
||
* By default, 360.0 units form a full circle (degrees). | ||
* After calling `radians()`, ``2*math.pi`` units form a full circle. | ||
* Custom values can be set with `degrees(fullcircle)`. | ||
|
||
Orientation of the turn depends in the current turtle mode, | ||
see function `mode()`. | ||
|
||
Example (for a Turtle instance named turtle): | ||
>>> turtle.heading() | ||
|
@@ -2622,8 +2645,27 @@ def reset(self): | |
|
||
No argument. | ||
|
||
Delete the turtle's drawings from the screen, re-center the turtle | ||
and set variables to the default values. | ||
Delete the turtle's drawings from the screen. Move the turtle | ||
to position `(0, 0)`, set its heading to the default | ||
(facing east in standard mode) and restore the following state | ||
variables to their initial values: | ||
|
||
- position: `(0, 0)` | ||
- heading: `0` (east) | ||
|
||
- pen state: down (drawing) | ||
- pensize: `1` | ||
- pencolor: black | ||
- fillcolor: white | ||
- speed: `3` | ||
- turtle visibility: shown | ||
- shape size: `(1.0, 1.0)` (no stretch) | ||
- shape shear: `0.0` (no shear) | ||
- shape tilt: `0.0` (no tilt) | ||
|
||
Note: | ||
The angle unit is **not reset** to degrees. If | ||
`radians()` was used before `reset()`, | ||
the unit remains radians. | ||
|
||
Example (for a Turtle instance named turtle): | ||
>>> turtle.position() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these parentheses are unnecessary.
Maybe, you could say
set its heading to 0 and...