Compare commits
91 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b7cc0a51f | ||
|
|
bbe12f008c | ||
|
|
3446470fa1 | ||
|
|
4d945fe51a | ||
|
|
8ee4425a0d | ||
|
|
5da667ae32 | ||
|
|
cb4511ae61 | ||
|
|
5aaa6abd75 | ||
|
|
b94d548cd1 | ||
|
|
63a6ffbf91 | ||
|
|
277983a836 | ||
|
|
49d941a3f2 | ||
| 614e9e2b4f | |||
|
|
591b805474 | ||
|
|
96222c3429 | ||
|
|
e921f796f1 | ||
|
|
06de267b3a | ||
|
|
bc7315d4b6 | ||
|
|
f2ae512e0e | ||
|
|
0c57fd42dc | ||
|
|
ebd591df45 | ||
|
|
eeac41fe02 | ||
|
|
057d7fd9fa | ||
|
|
5a170cb7b1 | ||
|
|
17a80d38a7 | ||
|
|
9d09f16bb2 | ||
|
|
d4477d1126 | ||
|
|
f632227871 | ||
|
|
d4a599a928 | ||
|
|
f03cfc7fa1 | ||
|
|
53d222e3f5 | ||
|
|
93ea97b2c8 | ||
|
|
751760ebd7 | ||
|
|
a30359b9d8 | ||
|
|
141d80ce8f | ||
|
|
012c3b3a9c | ||
|
|
614b602f8d | ||
|
|
480352b7b9 | ||
|
|
d70d57abca | ||
|
|
2ab650e364 | ||
|
|
0ac3837b82 | ||
|
|
a9a5385902 | ||
|
|
689c01102c | ||
|
|
298f6de310 | ||
|
|
f97bae7826 | ||
|
|
4bdae92772 | ||
|
|
4fb06f4482 | ||
|
|
332a947519 | ||
|
|
b7b438657e | ||
|
|
47f94f2aa8 | ||
|
|
12e4ec2756 | ||
|
|
87ee248a95 | ||
|
|
c146d6bb77 | ||
|
|
5acb2d0585 | ||
|
|
017591b4d4 | ||
|
|
8c3267999c | ||
|
|
cf9a11aac8 | ||
|
|
0161017036 | ||
|
|
b197cd6135 | ||
|
|
30c0988eb6 | ||
|
|
9f23b464df | ||
|
|
6f672a2351 | ||
|
|
2a993cbc38 | ||
|
|
79828c040f | ||
|
|
d1e81525cd | ||
|
|
463058218d | ||
|
|
be87a2c4e5 | ||
|
|
6e6270800b | ||
|
|
4cedbc39d3 | ||
|
|
1a5e4b0448 | ||
|
|
6df5a460dd | ||
|
|
7f8109fd9d | ||
|
|
a51d60d572 | ||
|
|
c3a0d4150c | ||
|
|
8ccecc57b7 | ||
|
|
de4b5821e2 | ||
|
|
0335851da3 | ||
|
|
5a5ef0efe4 | ||
|
|
28047a70f2 | ||
|
|
37e173e89d | ||
|
|
cb3d4b5652 | ||
|
|
2dab785f8f | ||
|
|
051c51dc9f | ||
|
|
7ce5a9a3a5 | ||
|
|
d6549f1829 | ||
|
|
b37b26f25d | ||
|
|
457bd3845d | ||
|
|
41470b253d | ||
|
|
4ebb440c82 | ||
|
|
15e766f51e | ||
|
|
488c3c3295 |
38 changed files with 655 additions and 900 deletions
11
.gitattributes
vendored
Normal file
11
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
.py text eol=lf
|
||||||
|
.rst text eol=lf
|
||||||
|
.txt text eol=lf
|
||||||
|
.yaml text eol=lf
|
||||||
|
.toml text eol=lf
|
||||||
|
.license text eol=lf
|
||||||
|
.md text eol=lf
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
Thank you for contributing! Before you submit a pull request, please read the following.
|
Thank you for contributing! Before you submit a pull request, please read the following.
|
||||||
|
|
||||||
Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html
|
Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html
|
||||||
|
|
||||||
If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs
|
If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs
|
||||||
|
|
||||||
|
|
|
||||||
65
.github/workflows/build.yml
vendored
65
.github/workflows/build.yml
vendored
|
|
@ -10,66 +10,5 @@ jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Dump GitHub context
|
- name: Run Build CI workflow
|
||||||
env:
|
uses: adafruit/workflows-circuitpython-libs/build@main
|
||||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
|
||||||
run: echo "$GITHUB_CONTEXT"
|
|
||||||
- name: Translate Repo Name For Build Tools filename_prefix
|
|
||||||
id: repo-name
|
|
||||||
run: |
|
|
||||||
echo ::set-output name=repo-name::$(
|
|
||||||
echo ${{ github.repository }} |
|
|
||||||
awk -F '\/' '{ print tolower($2) }' |
|
|
||||||
tr '_' '-'
|
|
||||||
)
|
|
||||||
- name: Set up Python 3.7
|
|
||||||
uses: actions/setup-python@v1
|
|
||||||
with:
|
|
||||||
python-version: 3.7
|
|
||||||
- name: Versions
|
|
||||||
run: |
|
|
||||||
python3 --version
|
|
||||||
- name: Checkout Current Repo
|
|
||||||
uses: actions/checkout@v1
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- name: Checkout tools repo
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
repository: adafruit/actions-ci-circuitpython-libs
|
|
||||||
path: actions-ci
|
|
||||||
- name: Install dependencies
|
|
||||||
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
|
|
||||||
run: |
|
|
||||||
source actions-ci/install.sh
|
|
||||||
- name: Pip install Sphinx, pre-commit
|
|
||||||
run: |
|
|
||||||
pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit
|
|
||||||
- name: Library version
|
|
||||||
run: git describe --dirty --always --tags
|
|
||||||
- name: Pre-commit hooks
|
|
||||||
run: |
|
|
||||||
pre-commit run --all-files
|
|
||||||
- name: Build assets
|
|
||||||
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
|
|
||||||
- name: Archive bundles
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: bundles
|
|
||||||
path: ${{ github.workspace }}/bundles/
|
|
||||||
- name: Build docs
|
|
||||||
working-directory: docs
|
|
||||||
run: sphinx-build -E -W -b html . _build/html
|
|
||||||
- name: Check For setup.py
|
|
||||||
id: need-pypi
|
|
||||||
run: |
|
|
||||||
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
|
|
||||||
- name: Build Python package
|
|
||||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
|
||||||
run: |
|
|
||||||
pip install --upgrade setuptools wheel twine readme_renderer testresources
|
|
||||||
python setup.py sdist
|
|
||||||
python setup.py bdist_wheel --universal
|
|
||||||
twine check dist/*
|
|
||||||
- name: Setup problem matchers
|
|
||||||
uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1
|
|
||||||
|
|
|
||||||
85
.github/workflows/release.yml
vendored
85
.github/workflows/release.yml
vendored
|
|
@ -1,85 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
name: Release Actions
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
upload-release-assets:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Dump GitHub context
|
|
||||||
env:
|
|
||||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
|
||||||
run: echo "$GITHUB_CONTEXT"
|
|
||||||
- name: Translate Repo Name For Build Tools filename_prefix
|
|
||||||
id: repo-name
|
|
||||||
run: |
|
|
||||||
echo ::set-output name=repo-name::$(
|
|
||||||
echo ${{ github.repository }} |
|
|
||||||
awk -F '\/' '{ print tolower($2) }' |
|
|
||||||
tr '_' '-'
|
|
||||||
)
|
|
||||||
- name: Set up Python 3.6
|
|
||||||
uses: actions/setup-python@v1
|
|
||||||
with:
|
|
||||||
python-version: 3.6
|
|
||||||
- name: Versions
|
|
||||||
run: |
|
|
||||||
python3 --version
|
|
||||||
- name: Checkout Current Repo
|
|
||||||
uses: actions/checkout@v1
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- name: Checkout tools repo
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
repository: adafruit/actions-ci-circuitpython-libs
|
|
||||||
path: actions-ci
|
|
||||||
- name: Install deps
|
|
||||||
run: |
|
|
||||||
source actions-ci/install.sh
|
|
||||||
- name: Build assets
|
|
||||||
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
|
|
||||||
- name: Upload Release Assets
|
|
||||||
# the 'official' actions version does not yet support dynamically
|
|
||||||
# supplying asset names to upload. @csexton's version chosen based on
|
|
||||||
# discussion in the issue below, as its the simplest to implement and
|
|
||||||
# allows for selecting files with a pattern.
|
|
||||||
# https://github.com/actions/upload-release-asset/issues/4
|
|
||||||
#uses: actions/upload-release-asset@v1.0.1
|
|
||||||
uses: csexton/release-asset-action@master
|
|
||||||
with:
|
|
||||||
pattern: "bundles/*"
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
upload-pypi:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Check For setup.py
|
|
||||||
id: need-pypi
|
|
||||||
run: |
|
|
||||||
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
|
|
||||||
- name: Set up Python
|
|
||||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
|
||||||
uses: actions/setup-python@v1
|
|
||||||
with:
|
|
||||||
python-version: '3.x'
|
|
||||||
- name: Install dependencies
|
|
||||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install setuptools wheel twine
|
|
||||||
- name: Build and publish
|
|
||||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
|
||||||
env:
|
|
||||||
TWINE_USERNAME: ${{ secrets.pypi_username }}
|
|
||||||
TWINE_PASSWORD: ${{ secrets.pypi_password }}
|
|
||||||
run: |
|
|
||||||
python setup.py sdist
|
|
||||||
twine upload dist/*
|
|
||||||
19
.github/workflows/release_gh.yml
vendored
Normal file
19
.github/workflows/release_gh.yml
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
name: GitHub Release Actions
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
upload-release-assets:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Run GitHub Release CI workflow
|
||||||
|
uses: adafruit/workflows-circuitpython-libs/release-gh@main
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
upload-url: ${{ github.event.release.upload_url }}
|
||||||
19
.github/workflows/release_pypi.yml
vendored
Normal file
19
.github/workflows/release_pypi.yml
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
name: PyPI Release Actions
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
upload-release-assets:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Run PyPI Release CI workflow
|
||||||
|
uses: adafruit/workflows-circuitpython-libs/release-pypi@main
|
||||||
|
with:
|
||||||
|
pypi-username: ${{ secrets.pypi_username }}
|
||||||
|
pypi-password: ${{ secrets.pypi_password }}
|
||||||
55
.gitignore
vendored
55
.gitignore
vendored
|
|
@ -1,15 +1,54 @@
|
||||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
# Do not include files and directories created by your personal work environment, such as the IDE
|
||||||
|
# you use, except for those already listed here. Pull requests including changes to this file will
|
||||||
|
# not be accepted.
|
||||||
|
|
||||||
|
# This .gitignore file contains rules for files generated by working with CircuitPython libraries,
|
||||||
|
# including building Sphinx, testing with pip, and creating a virual environment, as well as the
|
||||||
|
# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs.
|
||||||
|
|
||||||
|
# If you find that there are files being generated on your machine that should not be included in
|
||||||
|
# your git commit, you should create a .gitignore_global file on your computer to include the
|
||||||
|
# files created by your personal setup. To do so, follow the two steps below.
|
||||||
|
|
||||||
|
# First, create a file called .gitignore_global somewhere convenient for you, and add rules for
|
||||||
|
# the files you want to exclude from git commits.
|
||||||
|
|
||||||
|
# Second, configure Git to use the exclude file for all Git repositories by running the
|
||||||
|
# following via commandline, replacing "path/to/your/" with the actual path to your newly created
|
||||||
|
# .gitignore_global file:
|
||||||
|
# git config --global core.excludesfile path/to/your/.gitignore_global
|
||||||
|
|
||||||
|
# CircuitPython-specific files
|
||||||
*.mpy
|
*.mpy
|
||||||
.idea
|
|
||||||
|
# Python-specific files
|
||||||
__pycache__
|
__pycache__
|
||||||
_build
|
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|
||||||
|
# Sphinx build-specific files
|
||||||
|
_build
|
||||||
|
|
||||||
|
# MyPy-specific type-checking files
|
||||||
|
.mypy_cache
|
||||||
|
|
||||||
|
# pip install files
|
||||||
|
/build/
|
||||||
|
|
||||||
|
# This file results from running `pip -e install .` in a local repository
|
||||||
|
*.egg-info
|
||||||
|
|
||||||
|
# Virtual environment-specific files
|
||||||
.env
|
.env
|
||||||
bundles
|
.venv
|
||||||
|
|
||||||
|
# MacOS-specific files
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
.eggs
|
|
||||||
dist
|
# IDE-specific files
|
||||||
**/*.egg-info
|
.idea
|
||||||
|
.vscode
|
||||||
|
*~
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,21 @@
|
||||||
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
|
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/python/black
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: 20.8b1
|
rev: v4.5.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: check-yaml
|
||||||
- repo: https://github.com/fsfe/reuse-tool
|
- id: end-of-file-fixer
|
||||||
rev: v0.12.1
|
- id: trailing-whitespace
|
||||||
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
|
rev: v0.3.4
|
||||||
hooks:
|
hooks:
|
||||||
- id: reuse
|
- id: ruff-format
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- id: ruff
|
||||||
rev: v2.3.0
|
args: ["--fix"]
|
||||||
|
- repo: https://github.com/fsfe/reuse-tool
|
||||||
|
rev: v3.0.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-yaml
|
- id: reuse
|
||||||
- id: end-of-file-fixer
|
|
||||||
- id: trailing-whitespace
|
|
||||||
- repo: https://github.com/pycqa/pylint
|
|
||||||
rev: v2.11.1
|
|
||||||
hooks:
|
|
||||||
- id: pylint
|
|
||||||
name: pylint (library code)
|
|
||||||
types: [python]
|
|
||||||
args:
|
|
||||||
- --disable=consider-using-f-string
|
|
||||||
exclude: "^(docs/|examples/|tests/|setup.py$)"
|
|
||||||
- id: pylint
|
|
||||||
name: pylint (example code)
|
|
||||||
description: Run pylint rules on "examples/*.py" files
|
|
||||||
types: [python]
|
|
||||||
files: "^examples/"
|
|
||||||
args:
|
|
||||||
- --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code
|
|
||||||
- id: pylint
|
|
||||||
name: pylint (test code)
|
|
||||||
description: Run pylint rules on "tests/*.py" files
|
|
||||||
types: [python]
|
|
||||||
files: "^tests/"
|
|
||||||
args:
|
|
||||||
- --disable=missing-docstring,consider-using-f-string,duplicate-code
|
|
||||||
|
|
|
||||||
436
.pylintrc
436
.pylintrc
|
|
@ -1,436 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
||||||
|
|
||||||
[MASTER]
|
|
||||||
|
|
||||||
# A comma-separated list of package or module names from where C extensions may
|
|
||||||
# be loaded. Extensions are loading into the active Python interpreter and may
|
|
||||||
# run arbitrary code
|
|
||||||
extension-pkg-whitelist=
|
|
||||||
|
|
||||||
# Add files or directories to the blacklist. They should be base names, not
|
|
||||||
# paths.
|
|
||||||
ignore=CVS
|
|
||||||
|
|
||||||
# Add files or directories matching the regex patterns to the blacklist. The
|
|
||||||
# regex matches against base names, not paths.
|
|
||||||
ignore-patterns=
|
|
||||||
|
|
||||||
# Python code to execute, usually for sys.path manipulation such as
|
|
||||||
# pygtk.require().
|
|
||||||
#init-hook=
|
|
||||||
|
|
||||||
# Use multiple processes to speed up Pylint.
|
|
||||||
jobs=1
|
|
||||||
|
|
||||||
# List of plugins (as comma separated values of python modules names) to load,
|
|
||||||
# usually to register additional checkers.
|
|
||||||
load-plugins=
|
|
||||||
|
|
||||||
# Pickle collected data for later comparisons.
|
|
||||||
persistent=yes
|
|
||||||
|
|
||||||
# Specify a configuration file.
|
|
||||||
#rcfile=
|
|
||||||
|
|
||||||
# Allow loading of arbitrary C extensions. Extensions are imported into the
|
|
||||||
# active Python interpreter and may run arbitrary code.
|
|
||||||
unsafe-load-any-extension=no
|
|
||||||
|
|
||||||
|
|
||||||
[MESSAGES CONTROL]
|
|
||||||
|
|
||||||
# Only show warnings with the listed confidence levels. Leave empty to show
|
|
||||||
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
|
|
||||||
confidence=
|
|
||||||
|
|
||||||
# Disable the message, report, category or checker with the given id(s). You
|
|
||||||
# can either give multiple identifiers separated by comma (,) or put this
|
|
||||||
# option multiple times (only on the command line, not in the configuration
|
|
||||||
# file where it should appear only once).You can also use "--disable=all" to
|
|
||||||
# disable everything first and then reenable specific checks. For example, if
|
|
||||||
# you want to run only the similarities checker, you can use "--disable=all
|
|
||||||
# --enable=similarities". If you want to run only the classes checker, but have
|
|
||||||
# no Warning level messages displayed, use"--disable=all --enable=classes
|
|
||||||
# --disable=W"
|
|
||||||
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
|
|
||||||
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
|
|
||||||
|
|
||||||
# Enable the message, report, category or checker with the given id(s). You can
|
|
||||||
# either give multiple identifier separated by comma (,) or put this option
|
|
||||||
# multiple time (only on the command line, not in the configuration file where
|
|
||||||
# it should appear only once). See also the "--disable" option for examples.
|
|
||||||
enable=
|
|
||||||
|
|
||||||
|
|
||||||
[REPORTS]
|
|
||||||
|
|
||||||
# Python expression which should return a note less than 10 (10 is the highest
|
|
||||||
# note). You have access to the variables errors warning, statement which
|
|
||||||
# respectively contain the number of errors / warnings messages and the total
|
|
||||||
# number of statements analyzed. This is used by the global evaluation report
|
|
||||||
# (RP0004).
|
|
||||||
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
|
|
||||||
|
|
||||||
# Template used to display messages. This is a python new-style format string
|
|
||||||
# used to format the message information. See doc for all details
|
|
||||||
#msg-template=
|
|
||||||
|
|
||||||
# Set the output format. Available formats are text, parseable, colorized, json
|
|
||||||
# and msvs (visual studio).You can also give a reporter class, eg
|
|
||||||
# mypackage.mymodule.MyReporterClass.
|
|
||||||
output-format=text
|
|
||||||
|
|
||||||
# Tells whether to display a full report or only the messages
|
|
||||||
reports=no
|
|
||||||
|
|
||||||
# Activate the evaluation score.
|
|
||||||
score=yes
|
|
||||||
|
|
||||||
|
|
||||||
[REFACTORING]
|
|
||||||
|
|
||||||
# Maximum number of nested blocks for function / method body
|
|
||||||
max-nested-blocks=5
|
|
||||||
|
|
||||||
|
|
||||||
[LOGGING]
|
|
||||||
|
|
||||||
# Logging modules to check that the string format arguments are in logging
|
|
||||||
# function parameter format
|
|
||||||
logging-modules=logging
|
|
||||||
|
|
||||||
|
|
||||||
[SPELLING]
|
|
||||||
|
|
||||||
# Spelling dictionary name. Available dictionaries: none. To make it working
|
|
||||||
# install python-enchant package.
|
|
||||||
spelling-dict=
|
|
||||||
|
|
||||||
# List of comma separated words that should not be checked.
|
|
||||||
spelling-ignore-words=
|
|
||||||
|
|
||||||
# A path to a file that contains private dictionary; one word per line.
|
|
||||||
spelling-private-dict-file=
|
|
||||||
|
|
||||||
# Tells whether to store unknown words to indicated private dictionary in
|
|
||||||
# --spelling-private-dict-file option instead of raising a message.
|
|
||||||
spelling-store-unknown-words=no
|
|
||||||
|
|
||||||
|
|
||||||
[MISCELLANEOUS]
|
|
||||||
|
|
||||||
# List of note tags to take in consideration, separated by a comma.
|
|
||||||
# notes=FIXME,XXX,TODO
|
|
||||||
notes=FIXME,XXX
|
|
||||||
|
|
||||||
|
|
||||||
[TYPECHECK]
|
|
||||||
|
|
||||||
# List of decorators that produce context managers, such as
|
|
||||||
# contextlib.contextmanager. Add to this list to register other decorators that
|
|
||||||
# produce valid context managers.
|
|
||||||
contextmanager-decorators=contextlib.contextmanager
|
|
||||||
|
|
||||||
# List of members which are set dynamically and missed by pylint inference
|
|
||||||
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
|
||||||
# expressions are accepted.
|
|
||||||
generated-members=
|
|
||||||
|
|
||||||
# Tells whether missing members accessed in mixin class should be ignored. A
|
|
||||||
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
|
||||||
ignore-mixin-members=yes
|
|
||||||
|
|
||||||
# This flag controls whether pylint should warn about no-member and similar
|
|
||||||
# checks whenever an opaque object is returned when inferring. The inference
|
|
||||||
# can return multiple potential results while evaluating a Python object, but
|
|
||||||
# some branches might not be evaluated, which results in partial inference. In
|
|
||||||
# that case, it might be useful to still emit no-member and other checks for
|
|
||||||
# the rest of the inferred objects.
|
|
||||||
ignore-on-opaque-inference=yes
|
|
||||||
|
|
||||||
# List of class names for which member attributes should not be checked (useful
|
|
||||||
# for classes with dynamically set attributes). This supports the use of
|
|
||||||
# qualified names.
|
|
||||||
ignored-classes=optparse.Values,thread._local,_thread._local
|
|
||||||
|
|
||||||
# List of module names for which member attributes should not be checked
|
|
||||||
# (useful for modules/projects where namespaces are manipulated during runtime
|
|
||||||
# and thus existing member attributes cannot be deduced by static analysis. It
|
|
||||||
# supports qualified module names, as well as Unix pattern matching.
|
|
||||||
ignored-modules=board
|
|
||||||
|
|
||||||
# Show a hint with possible names when a member name was not found. The aspect
|
|
||||||
# of finding the hint is based on edit distance.
|
|
||||||
missing-member-hint=yes
|
|
||||||
|
|
||||||
# The minimum edit distance a name should have in order to be considered a
|
|
||||||
# similar match for a missing member name.
|
|
||||||
missing-member-hint-distance=1
|
|
||||||
|
|
||||||
# The total number of similar names that should be taken in consideration when
|
|
||||||
# showing a hint for a missing member.
|
|
||||||
missing-member-max-choices=1
|
|
||||||
|
|
||||||
|
|
||||||
[VARIABLES]
|
|
||||||
|
|
||||||
# List of additional names supposed to be defined in builtins. Remember that
|
|
||||||
# you should avoid to define new builtins when possible.
|
|
||||||
additional-builtins=
|
|
||||||
|
|
||||||
# Tells whether unused global variables should be treated as a violation.
|
|
||||||
allow-global-unused-variables=yes
|
|
||||||
|
|
||||||
# List of strings which can identify a callback function by name. A callback
|
|
||||||
# name must start or end with one of those strings.
|
|
||||||
callbacks=cb_,_cb
|
|
||||||
|
|
||||||
# A regular expression matching the name of dummy variables (i.e. expectedly
|
|
||||||
# not used).
|
|
||||||
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
|
|
||||||
|
|
||||||
# Argument names that match this expression will be ignored. Default to name
|
|
||||||
# with leading underscore
|
|
||||||
ignored-argument-names=_.*|^ignored_|^unused_
|
|
||||||
|
|
||||||
# Tells whether we should check for unused import in __init__ files.
|
|
||||||
init-import=no
|
|
||||||
|
|
||||||
# List of qualified module names which can have objects that can redefine
|
|
||||||
# builtins.
|
|
||||||
redefining-builtins-modules=six.moves,future.builtins
|
|
||||||
|
|
||||||
|
|
||||||
[FORMAT]
|
|
||||||
|
|
||||||
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
|
|
||||||
# expected-line-ending-format=
|
|
||||||
expected-line-ending-format=LF
|
|
||||||
|
|
||||||
# Regexp for a line that is allowed to be longer than the limit.
|
|
||||||
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
|
||||||
|
|
||||||
# Number of spaces of indent required inside a hanging or continued line.
|
|
||||||
indent-after-paren=4
|
|
||||||
|
|
||||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
|
||||||
# tab).
|
|
||||||
indent-string=' '
|
|
||||||
|
|
||||||
# Maximum number of characters on a single line.
|
|
||||||
max-line-length=100
|
|
||||||
|
|
||||||
# Maximum number of lines in a module
|
|
||||||
max-module-lines=1000
|
|
||||||
|
|
||||||
# List of optional constructs for which whitespace checking is disabled. `dict-
|
|
||||||
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
|
|
||||||
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
|
|
||||||
# `empty-line` allows space-only lines.
|
|
||||||
no-space-check=trailing-comma,dict-separator
|
|
||||||
|
|
||||||
# Allow the body of a class to be on the same line as the declaration if body
|
|
||||||
# contains single statement.
|
|
||||||
single-line-class-stmt=no
|
|
||||||
|
|
||||||
# Allow the body of an if to be on the same line as the test if there is no
|
|
||||||
# else.
|
|
||||||
single-line-if-stmt=no
|
|
||||||
|
|
||||||
|
|
||||||
[SIMILARITIES]
|
|
||||||
|
|
||||||
# Ignore comments when computing similarities.
|
|
||||||
ignore-comments=yes
|
|
||||||
|
|
||||||
# Ignore docstrings when computing similarities.
|
|
||||||
ignore-docstrings=yes
|
|
||||||
|
|
||||||
# Ignore imports when computing similarities.
|
|
||||||
ignore-imports=yes
|
|
||||||
|
|
||||||
# Minimum lines number of a similarity.
|
|
||||||
min-similarity-lines=4
|
|
||||||
|
|
||||||
|
|
||||||
[BASIC]
|
|
||||||
|
|
||||||
# Naming hint for argument names
|
|
||||||
argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Regular expression matching correct argument names
|
|
||||||
argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Naming hint for attribute names
|
|
||||||
attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Regular expression matching correct attribute names
|
|
||||||
attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Bad variable names which should always be refused, separated by a comma
|
|
||||||
bad-names=foo,bar,baz,toto,tutu,tata
|
|
||||||
|
|
||||||
# Naming hint for class attribute names
|
|
||||||
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
|
||||||
|
|
||||||
# Regular expression matching correct class attribute names
|
|
||||||
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
|
||||||
|
|
||||||
# Naming hint for class names
|
|
||||||
# class-name-hint=[A-Z_][a-zA-Z0-9]+$
|
|
||||||
class-name-hint=[A-Z_][a-zA-Z0-9_]+$
|
|
||||||
|
|
||||||
# Regular expression matching correct class names
|
|
||||||
# class-rgx=[A-Z_][a-zA-Z0-9]+$
|
|
||||||
class-rgx=[A-Z_][a-zA-Z0-9_]+$
|
|
||||||
|
|
||||||
# Naming hint for constant names
|
|
||||||
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
|
||||||
|
|
||||||
# Regular expression matching correct constant names
|
|
||||||
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
|
||||||
|
|
||||||
# Minimum line length for functions/classes that require docstrings, shorter
|
|
||||||
# ones are exempt.
|
|
||||||
docstring-min-length=-1
|
|
||||||
|
|
||||||
# Naming hint for function names
|
|
||||||
function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Regular expression matching correct function names
|
|
||||||
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Good variable names which should always be accepted, separated by a comma
|
|
||||||
# good-names=i,j,k,ex,Run,_
|
|
||||||
good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_
|
|
||||||
|
|
||||||
# Include a hint for the correct naming format with invalid-name
|
|
||||||
include-naming-hint=no
|
|
||||||
|
|
||||||
# Naming hint for inline iteration names
|
|
||||||
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
|
|
||||||
|
|
||||||
# Regular expression matching correct inline iteration names
|
|
||||||
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
|
||||||
|
|
||||||
# Naming hint for method names
|
|
||||||
method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Regular expression matching correct method names
|
|
||||||
method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Naming hint for module names
|
|
||||||
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
|
||||||
|
|
||||||
# Regular expression matching correct module names
|
|
||||||
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
|
||||||
|
|
||||||
# Colon-delimited sets of names that determine each other's naming style when
|
|
||||||
# the name regexes allow several styles.
|
|
||||||
name-group=
|
|
||||||
|
|
||||||
# Regular expression which should only match function or class names that do
|
|
||||||
# not require a docstring.
|
|
||||||
no-docstring-rgx=^_
|
|
||||||
|
|
||||||
# List of decorators that produce properties, such as abc.abstractproperty. Add
|
|
||||||
# to this list to register other decorators that produce valid properties.
|
|
||||||
property-classes=abc.abstractproperty
|
|
||||||
|
|
||||||
# Naming hint for variable names
|
|
||||||
variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Regular expression matching correct variable names
|
|
||||||
variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
|
|
||||||
[IMPORTS]
|
|
||||||
|
|
||||||
# Allow wildcard imports from modules that define __all__.
|
|
||||||
allow-wildcard-with-all=no
|
|
||||||
|
|
||||||
# Analyse import fallback blocks. This can be used to support both Python 2 and
|
|
||||||
# 3 compatible code, which means that the block might have code that exists
|
|
||||||
# only in one or another interpreter, leading to false positives when analysed.
|
|
||||||
analyse-fallback-blocks=no
|
|
||||||
|
|
||||||
# Deprecated modules which should not be used, separated by a comma
|
|
||||||
deprecated-modules=optparse,tkinter.tix
|
|
||||||
|
|
||||||
# Create a graph of external dependencies in the given file (report RP0402 must
|
|
||||||
# not be disabled)
|
|
||||||
ext-import-graph=
|
|
||||||
|
|
||||||
# Create a graph of every (i.e. internal and external) dependencies in the
|
|
||||||
# given file (report RP0402 must not be disabled)
|
|
||||||
import-graph=
|
|
||||||
|
|
||||||
# Create a graph of internal dependencies in the given file (report RP0402 must
|
|
||||||
# not be disabled)
|
|
||||||
int-import-graph=
|
|
||||||
|
|
||||||
# Force import order to recognize a module as part of the standard
|
|
||||||
# compatibility libraries.
|
|
||||||
known-standard-library=
|
|
||||||
|
|
||||||
# Force import order to recognize a module as part of a third party library.
|
|
||||||
known-third-party=enchant
|
|
||||||
|
|
||||||
|
|
||||||
[CLASSES]
|
|
||||||
|
|
||||||
# List of method names used to declare (i.e. assign) instance attributes.
|
|
||||||
defining-attr-methods=__init__,__new__,setUp
|
|
||||||
|
|
||||||
# List of member names, which should be excluded from the protected access
|
|
||||||
# warning.
|
|
||||||
exclude-protected=_asdict,_fields,_replace,_source,_make
|
|
||||||
|
|
||||||
# List of valid names for the first argument in a class method.
|
|
||||||
valid-classmethod-first-arg=cls
|
|
||||||
|
|
||||||
# List of valid names for the first argument in a metaclass class method.
|
|
||||||
valid-metaclass-classmethod-first-arg=mcs
|
|
||||||
|
|
||||||
|
|
||||||
[DESIGN]
|
|
||||||
|
|
||||||
# Maximum number of arguments for function / method
|
|
||||||
max-args=5
|
|
||||||
|
|
||||||
# Maximum number of attributes for a class (see R0902).
|
|
||||||
# max-attributes=7
|
|
||||||
max-attributes=11
|
|
||||||
|
|
||||||
# Maximum number of boolean expressions in a if statement
|
|
||||||
max-bool-expr=5
|
|
||||||
|
|
||||||
# Maximum number of branch for function / method body
|
|
||||||
max-branches=12
|
|
||||||
|
|
||||||
# Maximum number of locals for function / method body
|
|
||||||
max-locals=15
|
|
||||||
|
|
||||||
# Maximum number of parents for a class (see R0901).
|
|
||||||
max-parents=7
|
|
||||||
|
|
||||||
# Maximum number of public methods for a class (see R0904).
|
|
||||||
max-public-methods=20
|
|
||||||
|
|
||||||
# Maximum number of return / yield for function / method body
|
|
||||||
max-returns=6
|
|
||||||
|
|
||||||
# Maximum number of statements in function / method body
|
|
||||||
max-statements=50
|
|
||||||
|
|
||||||
# Minimum number of public methods for a class (see R0903).
|
|
||||||
min-public-methods=1
|
|
||||||
|
|
||||||
|
|
||||||
[EXCEPTIONS]
|
|
||||||
|
|
||||||
# Exceptions that will emit a warning when being caught. Defaults to
|
|
||||||
# "Exception"
|
|
||||||
overgeneral-exceptions=Exception
|
|
||||||
22
.readthedocs.yaml
Normal file
22
.readthedocs.yaml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
# Read the Docs configuration file
|
||||||
|
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||||
|
|
||||||
|
# Required
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
sphinx:
|
||||||
|
configuration: docs/conf.py
|
||||||
|
|
||||||
|
build:
|
||||||
|
os: ubuntu-lts-latest
|
||||||
|
tools:
|
||||||
|
python: "3"
|
||||||
|
|
||||||
|
python:
|
||||||
|
install:
|
||||||
|
- requirements: docs/requirements.txt
|
||||||
|
- requirements: requirements.txt
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
||||||
|
|
||||||
python:
|
|
||||||
version: 3
|
|
||||||
requirements_file: docs/requirements.txt
|
|
||||||
21
README.rst
21
README.rst
|
|
@ -2,10 +2,10 @@ Introduction
|
||||||
============
|
============
|
||||||
|
|
||||||
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-turtle/badge/?version=latest
|
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-turtle/badge/?version=latest
|
||||||
:target: https://circuitpython.readthedocs.io/projects/turtle/en/latest/
|
:target: https://docs.circuitpython.org/projects/turtle/en/latest/
|
||||||
:alt: Documentation Status
|
:alt: Documentation Status
|
||||||
|
|
||||||
.. image:: https://img.shields.io/discord/327254708534116352.svg
|
.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg
|
||||||
:target: https://adafru.it/discord
|
:target: https://adafru.it/discord
|
||||||
:alt: Discord
|
:alt: Discord
|
||||||
|
|
||||||
|
|
@ -13,6 +13,10 @@ Introduction
|
||||||
:target: https://github.com/adafruit/Adafruit_CircuitPython_turtle/actions/
|
:target: https://github.com/adafruit/Adafruit_CircuitPython_turtle/actions/
|
||||||
:alt: Build Status
|
:alt: Build Status
|
||||||
|
|
||||||
|
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
|
||||||
|
:target: https://github.com/astral-sh/ruff
|
||||||
|
:alt: Code Style: Ruff
|
||||||
|
|
||||||
Turtle graphics library for CircuitPython and displayio
|
Turtle graphics library for CircuitPython and displayio
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -48,8 +52,8 @@ To install in a virtual environment in your current project:
|
||||||
.. code-block:: shell
|
.. code-block:: shell
|
||||||
|
|
||||||
mkdir project-name && cd project-name
|
mkdir project-name && cd project-name
|
||||||
python3 -m venv .env
|
python3 -m venv .venv
|
||||||
source .env/bin/activate
|
source .venv/bin/activate
|
||||||
pip3 install adafruit-circuitpython-turtle
|
pip3 install adafruit-circuitpython-turtle
|
||||||
|
|
||||||
Usage Example
|
Usage Example
|
||||||
|
|
@ -84,7 +88,9 @@ Usage Example
|
||||||
Documentation
|
Documentation
|
||||||
=============
|
=============
|
||||||
|
|
||||||
API documentation for this library can be found on `Read the Docs <https://circuitpython.readthedocs.io/projects/turtle/en/latest/>`_.
|
API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/turtle/en/latest/>`_.
|
||||||
|
|
||||||
|
For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
|
||||||
|
|
||||||
Contributing
|
Contributing
|
||||||
============
|
============
|
||||||
|
|
@ -92,8 +98,3 @@ Contributing
|
||||||
Contributions are welcome! Please read our `Code of Conduct
|
Contributions are welcome! Please read our `Code of Conduct
|
||||||
<https://github.com/adafruit/Adafruit_CircuitPython_turtle/blob/main/CODE_OF_CONDUCT.md>`_
|
<https://github.com/adafruit/Adafruit_CircuitPython_turtle/blob/main/CODE_OF_CONDUCT.md>`_
|
||||||
before contributing to help this project stay welcoming.
|
before contributing to help this project stay welcoming.
|
||||||
|
|
||||||
Documentation
|
|
||||||
=============
|
|
||||||
|
|
||||||
For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
|
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,24 @@ Implementation Notes
|
||||||
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
|
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
# pylint:disable=too-many-public-methods, too-many-instance-attributes, invalid-name
|
# pylint:disable=too-many-public-methods, too-many-instance-attributes, invalid-name
|
||||||
# pylint:disable=too-few-public-methods, too-many-lines, too-many-arguments
|
# pylint:disable=too-few-public-methods, too-many-lines, too-many-arguments
|
||||||
|
|
||||||
import gc
|
import gc
|
||||||
import math
|
import math
|
||||||
import time
|
import time
|
||||||
import board
|
|
||||||
import displayio
|
import displayio
|
||||||
|
|
||||||
__version__ = "0.0.0-auto.0"
|
try:
|
||||||
|
from typing import List, Optional, Tuple, Union
|
||||||
|
|
||||||
|
import busdisplay
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
__version__ = "0.0.0+auto.0"
|
||||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_turtle.git"
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_turtle.git"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -41,21 +49,84 @@ class Color:
|
||||||
"""Standard colors"""
|
"""Standard colors"""
|
||||||
|
|
||||||
WHITE = 0xFFFFFF
|
WHITE = 0xFFFFFF
|
||||||
|
"""0xFFFFFF
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
BLACK = 0x000000
|
BLACK = 0x000000
|
||||||
|
"""0x000000
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
RED = 0xFF0000
|
RED = 0xFF0000
|
||||||
|
"""0xFF0000
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
ORANGE = 0xFFA500
|
ORANGE = 0xFFA500
|
||||||
|
"""0xFFA500
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
YELLOW = 0xFFEE00
|
YELLOW = 0xFFEE00
|
||||||
|
"""0xFFEE00
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
GREEN = 0x00C000
|
GREEN = 0x00C000
|
||||||
|
"""0x00C000
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
BLUE = 0x0000FF
|
BLUE = 0x0000FF
|
||||||
|
"""0x0000FF
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
PURPLE = 0x8040C0
|
PURPLE = 0x8040C0
|
||||||
|
"""0x8040C0
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
PINK = 0xFF40C0
|
PINK = 0xFF40C0
|
||||||
|
"""0xFF40C0
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
LIGHT_GRAY = 0xAAAAAA
|
LIGHT_GRAY = 0xAAAAAA
|
||||||
|
"""0xAAAAAA
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
GRAY = 0x444444
|
GRAY = 0x444444
|
||||||
|
"""0x444444
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
BROWN = 0xCA801D
|
BROWN = 0xCA801D
|
||||||
|
"""0xCA801D
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
DARK_GREEN = 0x008700
|
DARK_GREEN = 0x008700
|
||||||
|
"""0x008700
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
TURQUOISE = 0x00C0C0
|
TURQUOISE = 0x00C0C0
|
||||||
|
"""0x00C0C0
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
DARK_BLUE = 0x0000AA
|
DARK_BLUE = 0x0000AA
|
||||||
|
"""0x0000AA
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
DARK_RED = 0x800000
|
DARK_RED = 0x800000
|
||||||
|
"""0x800000
|
||||||
|
|
||||||
|
:meta hide-value:"""
|
||||||
|
|
||||||
colors = (
|
colors = (
|
||||||
BLACK,
|
BLACK,
|
||||||
|
|
@ -76,11 +147,11 @@ class Color:
|
||||||
DARK_RED,
|
DARK_RED,
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Vec2D(tuple):
|
class Vec2D:
|
||||||
"""A 2 dimensional vector class, used as a helper class
|
"""A 2 dimensional vector class, used as a helper class
|
||||||
for implementing turtle graphics.
|
for implementing turtle graphics.
|
||||||
May be useful for turtle graphics programs also.
|
May be useful for turtle graphics programs also.
|
||||||
|
|
@ -94,32 +165,35 @@ class Vec2D(tuple):
|
||||||
# k*a and a*k multiplication with scalar
|
# k*a and a*k multiplication with scalar
|
||||||
# |a| absolute value of a
|
# |a| absolute value of a
|
||||||
# a.rotate(angle) rotation
|
# a.rotate(angle) rotation
|
||||||
def __init__(self, x, y):
|
def __init__(self, x: float, y: float) -> None:
|
||||||
super().__init__((x, y))
|
self.values = (x, y)
|
||||||
|
|
||||||
def __add__(self, other):
|
def __getitem__(self, index: int) -> float:
|
||||||
|
return self.values[index]
|
||||||
|
|
||||||
|
def __add__(self, other: Vec2D) -> Vec2D:
|
||||||
return Vec2D(self[0] + other[0], self[1] + other[1])
|
return Vec2D(self[0] + other[0], self[1] + other[1])
|
||||||
|
|
||||||
def __mul__(self, other):
|
def __mul__(self, other: Union[float, Vec2D]) -> Union[float, Vec2D]:
|
||||||
if isinstance(other, Vec2D):
|
if isinstance(other, Vec2D):
|
||||||
return self[0] * other[0] + self[1] * other[1]
|
return self[0] * other[0] + self[1] * other[1]
|
||||||
return Vec2D(self[0] * other, self[1] * other)
|
return Vec2D(self[0] * other, self[1] * other)
|
||||||
|
|
||||||
def __rmul__(self, other):
|
def __rmul__(self, other: float) -> Optional[Vec2D]:
|
||||||
if isinstance(other, (float, int)):
|
if isinstance(other, (float, int)):
|
||||||
return Vec2D(self[0] * other, self[1] * other)
|
return Vec2D(self[0] * other, self[1] * other)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __sub__(self, other):
|
def __sub__(self, other: Vec2D) -> Vec2D:
|
||||||
return Vec2D(self[0] - other[0], self[1] - other[1])
|
return Vec2D(self[0] - other[0], self[1] - other[1])
|
||||||
|
|
||||||
def __neg__(self):
|
def __neg__(self) -> Vec2D:
|
||||||
return Vec2D(-self[0], -self[1])
|
return Vec2D(-self[0], -self[1])
|
||||||
|
|
||||||
def __abs__(self):
|
def __abs__(self) -> float:
|
||||||
return (self[0] ** 2 + self[1] ** 2) ** 0.5
|
return (self[0] ** 2 + self[1] ** 2) ** 0.5
|
||||||
|
|
||||||
def rotate(self, angle):
|
def rotate(self, angle: float) -> Vec2D:
|
||||||
"""Rotate self counterclockwise by angle.
|
"""Rotate self counterclockwise by angle.
|
||||||
|
|
||||||
:param angle: how much to rotate
|
:param angle: how much to rotate
|
||||||
|
|
@ -130,44 +204,42 @@ class Vec2D(tuple):
|
||||||
c, s = math.cos(angle), math.sin(angle)
|
c, s = math.cos(angle), math.sin(angle)
|
||||||
return Vec2D(self[0] * c + perp[0] * s, self[1] * c + perp[1] * s)
|
return Vec2D(self[0] * c + perp[0] * s, self[1] * c + perp[1] * s)
|
||||||
|
|
||||||
def __getnewargs__(self):
|
def __getnewargs__(self) -> Tuple[float, float]:
|
||||||
return (self[0], self[1])
|
return (self[0], self[1])
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self) -> str:
|
||||||
return "({:.2f},{:.2f})".format(self[0], self[1])
|
return f"({self[0]:.2f},{self[1]:.2f})"
|
||||||
|
|
||||||
|
|
||||||
class turtle:
|
class turtle:
|
||||||
"""A Turtle that can be given commands to draw."""
|
"""A Turtle that can be given commands to draw."""
|
||||||
|
|
||||||
# pylint:disable=too-many-statements
|
def __init__(self, display: Optional[busdisplay.BusDisplay] = None, scale: float = 1) -> None:
|
||||||
def __init__(self, display=None, scale=1):
|
|
||||||
|
|
||||||
if display:
|
if display:
|
||||||
self._display = display
|
self._display = display
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
import board
|
||||||
|
|
||||||
self._display = board.DISPLAY
|
self._display = board.DISPLAY
|
||||||
except AttributeError as err:
|
except AttributeError as err:
|
||||||
raise RuntimeError(
|
raise RuntimeError("No display available. One must be provided.") from err
|
||||||
"No display available. One must be provided."
|
|
||||||
) from err
|
|
||||||
|
|
||||||
self._w = self._display.width
|
self._w: int = self._display.width
|
||||||
self._h = self._display.height
|
self._h: int = self._display.height
|
||||||
self._x = self._w // (2 * scale)
|
self._x = self._w // (2 * scale)
|
||||||
self._y = self._h // (2 * scale)
|
self._y = self._h // (2 * scale)
|
||||||
self._speed = 6
|
self._speed = 6
|
||||||
self._heading = 0
|
self._heading: float = 0
|
||||||
self._logomode = True
|
|
||||||
self._fullcircle = 360.0
|
self._fullcircle = 360.0
|
||||||
self._degreesPerAU = 1.0
|
self._degreesPerAU = 1.0
|
||||||
self._angleOrient = 1
|
self._logomode = False
|
||||||
self._angleOffset = 0
|
self._angleOrient = -1
|
||||||
|
self._angleOffset: float = self._fullcircle / 4
|
||||||
self._bg_color = 0
|
self._bg_color = 0
|
||||||
|
|
||||||
self._splash = displayio.Group()
|
self._splash: displayio.Group = displayio.Group()
|
||||||
self._bgscale = 1
|
self._bgscale: int = 1
|
||||||
if self._w == self._h:
|
if self._w == self._h:
|
||||||
i = 1
|
i = 1
|
||||||
while self._bgscale == 1:
|
while self._bgscale == 1:
|
||||||
|
|
@ -191,7 +263,7 @@ class turtle:
|
||||||
# group to add background pictures (and/or user-defined stuff)
|
# group to add background pictures (and/or user-defined stuff)
|
||||||
self._bg_addon_group = displayio.Group()
|
self._bg_addon_group = displayio.Group()
|
||||||
self._splash.append(self._bg_addon_group)
|
self._splash.append(self._bg_addon_group)
|
||||||
self._fg_scale = scale
|
self._fg_scale: int = int(scale)
|
||||||
self._w = self._w // self._fg_scale
|
self._w = self._w // self._fg_scale
|
||||||
self._h = self._h // self._fg_scale
|
self._h = self._h // self._fg_scale
|
||||||
self._fg_bitmap = displayio.Bitmap(self._w, self._h, len(Color.colors))
|
self._fg_bitmap = displayio.Bitmap(self._w, self._h, len(Color.colors))
|
||||||
|
|
@ -236,47 +308,46 @@ class turtle:
|
||||||
self._turtle_pic = None
|
self._turtle_pic = None
|
||||||
self._turtle_odb = None
|
self._turtle_odb = None
|
||||||
self._turtle_alt_sprite = None
|
self._turtle_alt_sprite = None
|
||||||
|
self._turtle_x = self._x
|
||||||
|
self._turtle_y = self._y
|
||||||
self._drawturtle()
|
self._drawturtle()
|
||||||
self._stamps = {}
|
self._stamps = {}
|
||||||
self._turtle_odb_use = 0
|
self._turtle_odb_use = 0
|
||||||
self._turtle_odb_file = None
|
self._turtle_odb_file = None
|
||||||
self._odb_tilegrid = None
|
self._odb_tilegrid = None
|
||||||
gc.collect()
|
gc.collect()
|
||||||
self._display.show(self._splash)
|
self._display.root_group = self._splash
|
||||||
|
|
||||||
# pylint:enable=too-many-statements
|
# pylint:enable=too-many-statements
|
||||||
|
|
||||||
def _drawturtle(self):
|
def _drawturtle(self) -> None:
|
||||||
if self._turtle_pic is None:
|
if self._turtle_pic is None:
|
||||||
self._turtle_sprite.x = int(self._x - 4)
|
self._turtle_sprite.x = int(self._turtle_x - 4)
|
||||||
self._turtle_sprite.y = int(self._y - 4)
|
self._turtle_sprite.y = int(self._turtle_y - 4)
|
||||||
|
elif self._turtle_odb is not None:
|
||||||
|
self._turtle_alt_sprite.x = int(self._turtle_x - self._turtle_odb.width // 2)
|
||||||
|
self._turtle_alt_sprite.y = int(self._turtle_y - self._turtle_odb.height // 2)
|
||||||
else:
|
else:
|
||||||
if self._turtle_odb is not None:
|
self._turtle_alt_sprite.x = int(self._turtle_x - self._turtle_pic[0] // 2)
|
||||||
self._turtle_alt_sprite.x = int(self._x - self._turtle_odb.width // 2)
|
self._turtle_alt_sprite.y = int(self._turtle_y - self._turtle_pic[1] // 2)
|
||||||
self._turtle_alt_sprite.y = int(self._y - self._turtle_odb.height // 2)
|
|
||||||
else:
|
|
||||||
self._turtle_alt_sprite.x = int(self._x - self._turtle_pic[0] // 2)
|
|
||||||
self._turtle_alt_sprite.y = int(self._y - self._turtle_pic[1] // 2)
|
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Move and draw
|
# Move and draw
|
||||||
|
|
||||||
def forward(self, distance):
|
def forward(self, distance: float) -> None:
|
||||||
"""Move the turtle forward by the specified distance, in the direction the turtle is headed.
|
"""Move the turtle forward by the specified distance, in the direction the turtle is headed.
|
||||||
|
|
||||||
:param distance: how far to move (integer or float)
|
:param distance: how far to move (integer or float)
|
||||||
"""
|
"""
|
||||||
p = self.pos()
|
p = self.pos()
|
||||||
angle = (
|
angle = (self._angleOffset + self._angleOrient * self._heading) % self._fullcircle
|
||||||
self._angleOffset + self._angleOrient * self._heading
|
|
||||||
) % self._fullcircle
|
|
||||||
x1 = p[0] + math.sin(math.radians(angle)) * distance
|
x1 = p[0] + math.sin(math.radians(angle)) * distance
|
||||||
y1 = p[1] + math.cos(math.radians(angle)) * distance
|
y1 = p[1] + math.cos(math.radians(angle)) * distance
|
||||||
self.goto(x1, y1)
|
self.goto(x1, y1)
|
||||||
|
|
||||||
fd = forward
|
fd = forward
|
||||||
|
|
||||||
def backward(self, distance):
|
def backward(self, distance: float) -> None:
|
||||||
"""Move the turtle backward by distance, opposite to the direction the turtle is headed.
|
"""Move the turtle backward by distance, opposite to the direction the turtle is headed.
|
||||||
Does not change the turtle's heading.
|
Does not change the turtle's heading.
|
||||||
|
|
||||||
|
|
@ -288,7 +359,7 @@ class turtle:
|
||||||
bk = backward
|
bk = backward
|
||||||
back = backward
|
back = backward
|
||||||
|
|
||||||
def right(self, angle):
|
def right(self, angle: float) -> None:
|
||||||
"""Turn turtle right by angle units. (Units are by default degrees,
|
"""Turn turtle right by angle units. (Units are by default degrees,
|
||||||
but can be set via the degrees() and radians() functions.)
|
but can be set via the degrees() and radians() functions.)
|
||||||
Angle orientation depends on the turtle mode, see mode().
|
Angle orientation depends on the turtle mode, see mode().
|
||||||
|
|
@ -302,7 +373,7 @@ class turtle:
|
||||||
|
|
||||||
rt = right
|
rt = right
|
||||||
|
|
||||||
def left(self, angle):
|
def left(self, angle: float) -> None:
|
||||||
"""Turn turtle left by angle units. (Units are by default degrees,
|
"""Turn turtle left by angle units. (Units are by default degrees,
|
||||||
but can be set via the degrees() and radians() functions.)
|
but can be set via the degrees() and radians() functions.)
|
||||||
Angle orientation depends on the turtle mode, see mode().
|
Angle orientation depends on the turtle mode, see mode().
|
||||||
|
|
@ -317,7 +388,9 @@ class turtle:
|
||||||
lt = left
|
lt = left
|
||||||
|
|
||||||
# pylint:disable=too-many-branches,too-many-statements
|
# pylint:disable=too-many-branches,too-many-statements
|
||||||
def goto(self, x1, y1=None):
|
def goto(
|
||||||
|
self, x1: Union[float, Vec2D, Tuple[float, float]], y1: Optional[float] = None
|
||||||
|
) -> None:
|
||||||
"""If y1 is None, x1 must be a pair of coordinates or an (x, y) tuple
|
"""If y1 is None, x1 must be a pair of coordinates or an (x, y) tuple
|
||||||
|
|
||||||
Move turtle to an absolute position. If the pen is down, draw line.
|
Move turtle to an absolute position. If the pen is down, draw line.
|
||||||
|
|
@ -326,35 +399,38 @@ class turtle:
|
||||||
:param x1: a number or a pair of numbers
|
:param x1: a number or a pair of numbers
|
||||||
:param y1: a number or None
|
:param y1: a number or None
|
||||||
"""
|
"""
|
||||||
if y1 is None:
|
yn: float = x1[1] if y1 is None else y1 # type: ignore
|
||||||
y1 = x1[1]
|
xn: float = x1[0] if y1 is None else x1 # type: ignore
|
||||||
x1 = x1[0]
|
xn += self._w // 2
|
||||||
x1 += self._w // 2
|
yn = self._h // 2 - yn
|
||||||
y1 = self._h // 2 - y1
|
|
||||||
x0 = self._x
|
|
||||||
y0 = self._y
|
|
||||||
if not self.isdown():
|
if not self.isdown():
|
||||||
self._x = x1 # woot, we just skip ahead
|
self._x = xn # woot, we just skip ahead
|
||||||
self._y = y1
|
self._y = yn
|
||||||
self._drawturtle()
|
self._drawturtle()
|
||||||
return
|
return
|
||||||
steep = abs(y1 - y0) > abs(x1 - x0)
|
|
||||||
|
self._do_draw_line(round(self._x), round(self._y), round(xn), round(yn))
|
||||||
|
self._x = xn
|
||||||
|
self._y = yn
|
||||||
|
|
||||||
|
def _do_draw_line(self, x0: int, y0: int, xn: int, yn: int):
|
||||||
|
steep = abs(yn - y0) > abs(xn - x0)
|
||||||
rev = False
|
rev = False
|
||||||
dx = x1 - x0
|
dx = xn - x0
|
||||||
|
|
||||||
if steep:
|
if steep:
|
||||||
x0, y0 = y0, x0
|
x0, y0 = y0, x0
|
||||||
x1, y1 = y1, x1
|
xn, yn = yn, xn
|
||||||
dx = x1 - x0
|
dx = xn - x0
|
||||||
|
|
||||||
if x0 > x1:
|
if x0 > xn:
|
||||||
rev = True
|
rev = True
|
||||||
dx = x0 - x1
|
dx = x0 - xn
|
||||||
|
|
||||||
dy = abs(y1 - y0)
|
dy = abs(yn - y0)
|
||||||
err = dx / 2
|
err = dx / 2
|
||||||
ystep = -1
|
ystep = -1
|
||||||
if y0 < y1:
|
if y0 < yn:
|
||||||
ystep = 1
|
ystep = 1
|
||||||
step = 1
|
step = 1
|
||||||
if self._speed > 0:
|
if self._speed > 0:
|
||||||
|
|
@ -362,21 +438,21 @@ class turtle:
|
||||||
else:
|
else:
|
||||||
ts = 0
|
ts = 0
|
||||||
|
|
||||||
while (not rev and x0 <= x1) or (rev and x1 <= x0):
|
while (not rev and x0 <= xn) or (rev and xn <= x0):
|
||||||
if steep:
|
if steep:
|
||||||
try:
|
try:
|
||||||
self._plot(int(y0), int(x0), self._pencolor)
|
self._plot(int(y0), int(x0), self._pencolor)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
self._x = y0
|
self._turtle_x = y0
|
||||||
self._y = x0
|
self._turtle_y = x0
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self._plot(int(x0), int(y0), self._pencolor)
|
self._plot(int(x0), int(y0), self._pencolor)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
self._x = x0
|
self._turtle_x = x0
|
||||||
self._y = y0
|
self._turtle_y = y0
|
||||||
if self._speed > 0:
|
if self._speed > 0:
|
||||||
if step >= self._speed:
|
if step >= self._speed:
|
||||||
# mark the step
|
# mark the step
|
||||||
|
|
@ -397,9 +473,10 @@ class turtle:
|
||||||
|
|
||||||
setpos = goto
|
setpos = goto
|
||||||
setposition = goto
|
setposition = goto
|
||||||
|
|
||||||
# pylint:enable=too-many-branches,too-many-statements
|
# pylint:enable=too-many-branches,too-many-statements
|
||||||
|
|
||||||
def setx(self, x):
|
def setx(self, x: float) -> None:
|
||||||
"""Set the turtle's first coordinate to x, leave second coordinate
|
"""Set the turtle's first coordinate to x, leave second coordinate
|
||||||
unchanged.
|
unchanged.
|
||||||
|
|
||||||
|
|
@ -408,7 +485,7 @@ class turtle:
|
||||||
"""
|
"""
|
||||||
self.goto(x, self.pos()[1])
|
self.goto(x, self.pos()[1])
|
||||||
|
|
||||||
def sety(self, y):
|
def sety(self, y: float) -> None:
|
||||||
"""Set the turtle's second coordinate to y, leave first coordinate
|
"""Set the turtle's second coordinate to y, leave first coordinate
|
||||||
unchanged.
|
unchanged.
|
||||||
|
|
||||||
|
|
@ -417,7 +494,7 @@ class turtle:
|
||||||
"""
|
"""
|
||||||
self.goto(self.pos()[0], y)
|
self.goto(self.pos()[0], y)
|
||||||
|
|
||||||
def setheading(self, to_angle):
|
def setheading(self, to_angle: float) -> None:
|
||||||
"""Set the orientation of the turtle to to_angle. Here are some common
|
"""Set the orientation of the turtle to to_angle. Here are some common
|
||||||
directions in degrees:
|
directions in degrees:
|
||||||
|
|
||||||
|
|
@ -437,7 +514,7 @@ class turtle:
|
||||||
|
|
||||||
seth = setheading
|
seth = setheading
|
||||||
|
|
||||||
def home(self):
|
def home(self) -> None:
|
||||||
"""Move turtle to the origin - coordinates (0,0) - and set its heading
|
"""Move turtle to the origin - coordinates (0,0) - and set its heading
|
||||||
to its start-orientation
|
to its start-orientation
|
||||||
(which depends on the mode, see mode()).
|
(which depends on the mode, see mode()).
|
||||||
|
|
@ -446,7 +523,7 @@ class turtle:
|
||||||
self.goto(0, 0)
|
self.goto(0, 0)
|
||||||
|
|
||||||
# pylint:disable=too-many-locals, too-many-statements, too-many-branches
|
# pylint:disable=too-many-locals, too-many-statements, too-many-branches
|
||||||
def _plot(self, x, y, c):
|
def _plot(self, x: float, y: float, c: int) -> None:
|
||||||
if self._pensize == 1:
|
if self._pensize == 1:
|
||||||
try:
|
try:
|
||||||
self._fg_bitmap[int(x), int(y)] = c
|
self._fg_bitmap[int(x), int(y)] = c
|
||||||
|
|
@ -454,9 +531,7 @@ class turtle:
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
r = self._pensize // 2 + 1
|
r = self._pensize // 2 + 1
|
||||||
angle = (
|
angle = (self._angleOffset + self._angleOrient * self._heading - 90) % self._fullcircle
|
||||||
self._angleOffset + self._angleOrient * self._heading - 90
|
|
||||||
) % self._fullcircle
|
|
||||||
sin = math.sin(math.radians(angle))
|
sin = math.sin(math.radians(angle))
|
||||||
cos = math.cos(math.radians(angle))
|
cos = math.cos(math.radians(angle))
|
||||||
x0 = x + sin * r
|
x0 = x + sin * r
|
||||||
|
|
@ -526,7 +601,9 @@ class turtle:
|
||||||
|
|
||||||
# pylint:enable=too-many-locals, too-many-statements, too-many-branches
|
# pylint:enable=too-many-locals, too-many-statements, too-many-branches
|
||||||
|
|
||||||
def circle(self, radius, extent=None, steps=None):
|
def circle(
|
||||||
|
self, radius: float, extent: Optional[float] = None, steps: Optional[int] = None
|
||||||
|
) -> None:
|
||||||
"""Draw a circle with given radius. The center is radius units left of
|
"""Draw a circle with given radius. The center is radius units left of
|
||||||
the turtle; extent - an angle - determines which part of the circle is
|
the turtle; extent - an angle - determines which part of the circle is
|
||||||
drawn. If extent is not given, draw the entire circle. If extent is not
|
drawn. If extent is not given, draw the entire circle. If extent is not
|
||||||
|
|
@ -547,6 +624,12 @@ class turtle:
|
||||||
# --or: circle(radius, extent) # arc
|
# --or: circle(radius, extent) # arc
|
||||||
# --or: circle(radius, extent, steps)
|
# --or: circle(radius, extent, steps)
|
||||||
# --or: circle(radius, steps=6) # 6-sided polygon
|
# --or: circle(radius, steps=6) # 6-sided polygon
|
||||||
|
change_back = False
|
||||||
|
if not self._in_degrees():
|
||||||
|
change_back = True
|
||||||
|
original_mode = "standard" if not self._logomode else "logo"
|
||||||
|
self.degrees()
|
||||||
|
self.mode("standard")
|
||||||
pos = self.pos()
|
pos = self.pos()
|
||||||
h = self._heading
|
h = self._heading
|
||||||
if extent is None:
|
if extent is None:
|
||||||
|
|
@ -568,11 +651,13 @@ class turtle:
|
||||||
# get back to exact same position and heading
|
# get back to exact same position and heading
|
||||||
self.goto(pos)
|
self.goto(pos)
|
||||||
self.setheading(h)
|
self.setheading(h)
|
||||||
|
if change_back:
|
||||||
|
self.radians()
|
||||||
|
self.mode(original_mode)
|
||||||
|
|
||||||
# pylint:disable=inconsistent-return-statements
|
# pylint:disable=inconsistent-return-statements
|
||||||
def speed(self, speed=None):
|
def speed(self, speed: Optional[int] = None) -> Optional[int]:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Set the turtle's speed to an integer value in the range 0..10. If no
|
Set the turtle's speed to an integer value in the range 0..10. If no
|
||||||
argument is given, return current speed.
|
argument is given, return current speed.
|
||||||
|
|
||||||
|
|
@ -599,10 +684,11 @@ class turtle:
|
||||||
self._speed = 0
|
self._speed = 0
|
||||||
else:
|
else:
|
||||||
self._speed = speed
|
self._speed = speed
|
||||||
|
return None
|
||||||
|
|
||||||
# pylint:enable=inconsistent-return-statements
|
# pylint:enable=inconsistent-return-statements
|
||||||
|
|
||||||
def dot(self, size=None, color=None):
|
def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None:
|
||||||
"""Draw a circular dot with diameter size, using color.
|
"""Draw a circular dot with diameter size, using color.
|
||||||
If size is not given, the maximum of pensize+4 and
|
If size is not given, the maximum of pensize+4 and
|
||||||
2*pensize is used.
|
2*pensize is used.
|
||||||
|
|
@ -611,6 +697,13 @@ class turtle:
|
||||||
:param color: the color of the dot
|
:param color: the color of the dot
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
change_back = False
|
||||||
|
if not self._in_degrees():
|
||||||
|
change_back = True
|
||||||
|
original_mode = "standard" if not self._logomode else "logo"
|
||||||
|
print(f"old mode: {original_mode}")
|
||||||
|
self.degrees()
|
||||||
|
self.mode("standard")
|
||||||
if size is None:
|
if size is None:
|
||||||
size = max(self._pensize + 4, self._pensize * 2)
|
size = max(self._pensize + 4, self._pensize * 2)
|
||||||
if color is None:
|
if color is None:
|
||||||
|
|
@ -634,16 +727,20 @@ class turtle:
|
||||||
self._pensize = 1
|
self._pensize = 1
|
||||||
self._plot(self._x, self._y, color)
|
self._plot(self._x, self._y, color)
|
||||||
self._pensize = pensize
|
self._pensize = pensize
|
||||||
|
if change_back:
|
||||||
|
self.radians()
|
||||||
|
self.mode(original_mode)
|
||||||
|
|
||||||
def stamp(self, bitmap=None, palette=None):
|
def stamp(
|
||||||
|
self,
|
||||||
|
bitmap: Optional[displayio.Bitmap] = None,
|
||||||
|
palette: Optional[displayio.Palette] = None,
|
||||||
|
) -> int:
|
||||||
"""
|
"""
|
||||||
Stamp a copy of the turtle shape onto the canvas at the current
|
Stamp a copy of the turtle shape onto the canvas at the current
|
||||||
turtle position. Return a stamp_id for that stamp, which can be used to
|
turtle position. Return a stamp_id for that stamp, which can be used to
|
||||||
delete it by calling clearstamp(stamp_id).
|
delete it by calling clearstamp(stamp_id).
|
||||||
"""
|
"""
|
||||||
if len(self._fg_addon_group) >= 6:
|
|
||||||
print("Addon group full")
|
|
||||||
return -1
|
|
||||||
s_id = len(self._stamps)
|
s_id = len(self._stamps)
|
||||||
if self._turtle_pic is None:
|
if self._turtle_pic is None:
|
||||||
# easy.
|
# easy.
|
||||||
|
|
@ -657,7 +754,7 @@ class turtle:
|
||||||
# odb bitmap
|
# odb bitmap
|
||||||
new_stamp = displayio.TileGrid(
|
new_stamp = displayio.TileGrid(
|
||||||
self._turtle_odb,
|
self._turtle_odb,
|
||||||
pixel_shader=displayio.ColorConverter(),
|
pixel_shader=self._turtle_odb.pixel_shader,
|
||||||
x=int(self._x - self._turtle_odb.width // 2),
|
x=int(self._x - self._turtle_odb.width // 2),
|
||||||
y=int(self._y - self._turtle_odb.height // 2),
|
y=int(self._y - self._turtle_odb.height // 2),
|
||||||
)
|
)
|
||||||
|
|
@ -681,7 +778,7 @@ class turtle:
|
||||||
|
|
||||||
return s_id
|
return s_id
|
||||||
|
|
||||||
def clearstamp(self, stampid):
|
def clearstamp(self, stampid: int) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Delete stamp with given stampid.
|
Delete stamp with given stampid.
|
||||||
|
|
@ -694,8 +791,7 @@ class turtle:
|
||||||
if isinstance(self._stamps[stampid], tuple):
|
if isinstance(self._stamps[stampid], tuple):
|
||||||
self._fg_addon_group.remove(self._stamps[stampid][0])
|
self._fg_addon_group.remove(self._stamps[stampid][0])
|
||||||
self._turtle_odb_use -= 1
|
self._turtle_odb_use -= 1
|
||||||
if self._turtle_odb_use == 0:
|
|
||||||
self._stamps[stampid][1].close()
|
|
||||||
else:
|
else:
|
||||||
self._fg_addon_group.remove(self._stamps[stampid])
|
self._fg_addon_group.remove(self._stamps[stampid])
|
||||||
self._stamps[stampid] = None
|
self._stamps[stampid] = None
|
||||||
|
|
@ -704,9 +800,8 @@ class turtle:
|
||||||
else:
|
else:
|
||||||
raise TypeError("Stamp id must be an int")
|
raise TypeError("Stamp id must be an int")
|
||||||
|
|
||||||
def clearstamps(self, n=None):
|
def clearstamps(self, n: Optional[int] = None) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Delete all or first/last n of turtle's stamps. If n is None, delete
|
Delete all or first/last n of turtle's stamps. If n is None, delete
|
||||||
all stamps, if n > 0 delete first n stamps, else if n < 0 delete last
|
all stamps, if n > 0 delete first n stamps, else if n < 0 delete last
|
||||||
n stamps.
|
n stamps.
|
||||||
|
|
@ -715,7 +810,7 @@ class turtle:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
i = 1
|
i = 1
|
||||||
for sid in self._stamps: # pylint: disable=consider-using-dict-items
|
for sid in self._stamps:
|
||||||
if self._stamps[sid] is not None:
|
if self._stamps[sid] is not None:
|
||||||
self.clearstamp(sid)
|
self.clearstamp(sid)
|
||||||
if n is not None and i >= n:
|
if n is not None and i >= n:
|
||||||
|
|
@ -725,13 +820,15 @@ class turtle:
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Tell turtle's state
|
# Tell turtle's state
|
||||||
|
|
||||||
def pos(self):
|
def pos(self) -> Vec2D:
|
||||||
"""Return the turtle's current location (x,y) (as a Vec2D vector)."""
|
"""Return the turtle's current location (x,y) (as a Vec2D vector)."""
|
||||||
return Vec2D(self._x - self._w // 2, self._h // 2 - self._y)
|
return Vec2D(self._x - self._w // 2, self._h // 2 - self._y)
|
||||||
|
|
||||||
position = pos
|
position = pos
|
||||||
|
|
||||||
def towards(self, x1, y1=None):
|
def towards(
|
||||||
|
self, x1: Union[float, Vec2D, Tuple[float, float]], y1: Optional[float] = None
|
||||||
|
) -> float:
|
||||||
"""
|
"""
|
||||||
Return the angle between the line from turtle position to position
|
Return the angle between the line from turtle position to position
|
||||||
specified by (x,y) or the vector. This depends on the turtle's start
|
specified by (x,y) or the vector. This depends on the turtle's start
|
||||||
|
|
@ -750,21 +847,23 @@ class turtle:
|
||||||
result /= self._degreesPerAU
|
result /= self._degreesPerAU
|
||||||
return (self._angleOffset + self._angleOrient * result) % self._fullcircle
|
return (self._angleOffset + self._angleOrient * result) % self._fullcircle
|
||||||
|
|
||||||
def xcor(self):
|
def xcor(self) -> float:
|
||||||
"""Return the turtle's x coordinate."""
|
"""Return the turtle's x coordinate."""
|
||||||
return self._x - self._w // 2
|
return self._x - self._w // 2
|
||||||
|
|
||||||
def ycor(self):
|
def ycor(self) -> float:
|
||||||
"""Return the turtle's y coordinate."""
|
"""Return the turtle's y coordinate."""
|
||||||
return self._h // 2 - self._y
|
return self._h // 2 - self._y
|
||||||
|
|
||||||
def heading(self):
|
def heading(self) -> float:
|
||||||
"""Return the turtle's current heading (value depends on the turtle
|
"""Return the turtle's current heading (value depends on the turtle
|
||||||
mode, see mode()).
|
mode, see mode()).
|
||||||
"""
|
"""
|
||||||
return self._heading
|
return self._heading
|
||||||
|
|
||||||
def distance(self, x1, y1=None):
|
def distance(
|
||||||
|
self, x1: Union[float, List[float], Tuple[float, float]], y1: Optional[float]
|
||||||
|
) -> float:
|
||||||
"""
|
"""
|
||||||
Return the distance from the turtle to (x,y) or the vector, in turtle
|
Return the distance from the turtle to (x,y) or the vector, in turtle
|
||||||
step units.
|
step units.
|
||||||
|
|
@ -773,16 +872,16 @@ class turtle:
|
||||||
:param y: a number if x is a number, else None
|
:param y: a number if x is a number, else None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if y1 is None:
|
yn: float = x1[1] if y1 is None else y1 # type: ignore
|
||||||
y1 = x1[1]
|
xn: float = x1[0] if y1 is None else x1 # type: ignore
|
||||||
x1 = x1[0]
|
p = self.pos()
|
||||||
x0, y0 = self.pos()
|
x0, y0 = (p[0], p[1])
|
||||||
return math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2)
|
return math.sqrt((x0 - xn) ** 2 + (y0 - yn) ** 2)
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Setting and measurement
|
# Setting and measurement
|
||||||
|
|
||||||
def _setDegreesPerAU(self, fullcircle):
|
def _setDegreesPerAU(self, fullcircle: float) -> None:
|
||||||
"""Helper function for degrees() and radians()"""
|
"""Helper function for degrees() and radians()"""
|
||||||
self._fullcircle = fullcircle
|
self._fullcircle = fullcircle
|
||||||
self._degreesPerAU = 360 / fullcircle
|
self._degreesPerAU = 360 / fullcircle
|
||||||
|
|
@ -791,7 +890,7 @@ class turtle:
|
||||||
else:
|
else:
|
||||||
self._angleOffset = -fullcircle / 4
|
self._angleOffset = -fullcircle / 4
|
||||||
|
|
||||||
def degrees(self, fullcircle=360):
|
def degrees(self, fullcircle: float = 360) -> None:
|
||||||
"""Set angle measurement units, i.e. set number of "degrees" for
|
"""Set angle measurement units, i.e. set number of "degrees" for
|
||||||
a full circle.
|
a full circle.
|
||||||
Default value is 360 degrees.
|
Default value is 360 degrees.
|
||||||
|
|
@ -800,12 +899,16 @@ class turtle:
|
||||||
"""
|
"""
|
||||||
self._setDegreesPerAU(fullcircle)
|
self._setDegreesPerAU(fullcircle)
|
||||||
|
|
||||||
def radians(self):
|
def _in_degrees(self) -> bool:
|
||||||
|
print(self._degreesPerAU)
|
||||||
|
return self._degreesPerAU == 1.0
|
||||||
|
|
||||||
|
def radians(self) -> None:
|
||||||
"""Set the angle measurement units to radians.
|
"""Set the angle measurement units to radians.
|
||||||
Equivalent to degrees(2*math.pi)."""
|
Equivalent to degrees(2*math.pi)."""
|
||||||
self._setDegreesPerAU(2 * math.pi)
|
self._setDegreesPerAU(2 * math.pi)
|
||||||
|
|
||||||
def mode(self, mode=None):
|
def mode(self, mode: Optional[str] = None) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Set turtle mode ("standard" or "logo") and perform reset.
|
Set turtle mode ("standard" or "logo") and perform reset.
|
||||||
|
|
@ -832,12 +935,12 @@ class turtle:
|
||||||
raise RuntimeError("Mode must be 'logo', 'standard', or None")
|
raise RuntimeError("Mode must be 'logo', 'standard', or None")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def window_height(self):
|
def window_height(self) -> float:
|
||||||
"""
|
"""
|
||||||
Return the height of the turtle window."""
|
Return the height of the turtle window."""
|
||||||
return self._h
|
return self._h
|
||||||
|
|
||||||
def window_width(self):
|
def window_width(self) -> float:
|
||||||
"""
|
"""
|
||||||
Return the width of the turtle window."""
|
Return the width of the turtle window."""
|
||||||
return self._w
|
return self._w
|
||||||
|
|
@ -845,25 +948,25 @@ class turtle:
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Drawing state
|
# Drawing state
|
||||||
|
|
||||||
def pendown(self):
|
def pendown(self) -> None:
|
||||||
"""Pull the pen down - drawing when moving."""
|
"""Pull the pen down - drawing when moving."""
|
||||||
self._penstate = True
|
self._penstate = True
|
||||||
|
|
||||||
pd = pendown
|
pd = pendown
|
||||||
down = pendown
|
down = pendown
|
||||||
|
|
||||||
def penup(self):
|
def penup(self) -> None:
|
||||||
"""Pull the pen up - no drawing when moving."""
|
"""Pull the pen up - no drawing when moving."""
|
||||||
self._penstate = False
|
self._penstate = False
|
||||||
|
|
||||||
pu = penup
|
pu = penup
|
||||||
up = penup
|
up = penup
|
||||||
|
|
||||||
def isdown(self):
|
def isdown(self) -> bool:
|
||||||
"""Return True if pen is down, False if it's up."""
|
"""Return True if pen is down, False if it's up."""
|
||||||
return self._penstate
|
return self._penstate
|
||||||
|
|
||||||
def pensize(self, width=None):
|
def pensize(self, width: Optional[int] = None) -> int:
|
||||||
"""
|
"""
|
||||||
Set the line thickness to width or return it.
|
Set the line thickness to width or return it.
|
||||||
If no argument is given, the current pensize is returned.
|
If no argument is given, the current pensize is returned.
|
||||||
|
|
@ -882,12 +985,12 @@ class turtle:
|
||||||
|
|
||||||
# pylint:disable=no-self-use
|
# pylint:disable=no-self-use
|
||||||
|
|
||||||
def _color_to_pencolor(self, c):
|
def _color_to_pencolor(self, c: int) -> int:
|
||||||
return Color.colors.index(c)
|
return Color.colors.index(c)
|
||||||
|
|
||||||
# pylint:enable=no-self-use
|
# pylint:enable=no-self-use
|
||||||
|
|
||||||
def pencolor(self, c=None):
|
def pencolor(self, c: Optional[int] = None) -> int:
|
||||||
"""
|
"""
|
||||||
Return or set the pencolor.
|
Return or set the pencolor.
|
||||||
|
|
||||||
|
|
@ -915,7 +1018,7 @@ class turtle:
|
||||||
self._turtle_palette.make_opaque(1)
|
self._turtle_palette.make_opaque(1)
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def bgcolor(self, c=None):
|
def bgcolor(self, c: Optional[int] = None) -> int:
|
||||||
"""
|
"""
|
||||||
Return or set the background color.
|
Return or set the background color.
|
||||||
|
|
||||||
|
|
@ -949,7 +1052,7 @@ class turtle:
|
||||||
return Color.colors[self._bg_color]
|
return Color.colors[self._bg_color]
|
||||||
|
|
||||||
# pylint:disable=inconsistent-return-statements
|
# pylint:disable=inconsistent-return-statements
|
||||||
def bgpic(self, picname=None):
|
def bgpic(self, picname: Optional[str] = None) -> Optional[str]:
|
||||||
"""Set background image or return name of current backgroundimage.
|
"""Set background image or return name of current backgroundimage.
|
||||||
Optional argument:
|
Optional argument:
|
||||||
picname -- a string, name of an image file or "nopic".
|
picname -- a string, name of an image file or "nopic".
|
||||||
|
|
@ -963,27 +1066,28 @@ class turtle:
|
||||||
if self._bg_pic is not None:
|
if self._bg_pic is not None:
|
||||||
self._bg_addon_group.remove(self._odb_tilegrid)
|
self._bg_addon_group.remove(self._odb_tilegrid)
|
||||||
self._odb_tilegrid = None
|
self._odb_tilegrid = None
|
||||||
self._bg_pic.close()
|
|
||||||
self._bg_pic = None
|
self._bg_pic = None
|
||||||
self._bg_pic_filename = ""
|
self._bg_pic_filename = ""
|
||||||
else:
|
else:
|
||||||
with open(picname, "rb") as self._bg_pic:
|
odb = displayio.OnDiskBitmap(picname)
|
||||||
odb = displayio.OnDiskBitmap(self._bg_pic)
|
|
||||||
self._odb_tilegrid = displayio.TileGrid(
|
self._odb_tilegrid = displayio.TileGrid(
|
||||||
odb, pixel_shader=displayio.ColorConverter()
|
odb,
|
||||||
|
pixel_shader=odb.pixel_shader,
|
||||||
)
|
)
|
||||||
self._bg_addon_group.append(self._odb_tilegrid)
|
self._bg_addon_group.append(self._odb_tilegrid)
|
||||||
self._bg_pic_filename = picname
|
self._bg_pic_filename = picname
|
||||||
# centered
|
# centered
|
||||||
self._odb_tilegrid.y = ((self._h * self._fg_scale) // 2) - (odb.height // 2)
|
self._odb_tilegrid.y = ((self._h * self._fg_scale) // 2) - (odb.height // 2)
|
||||||
self._odb_tilegrid.x = ((self._w * self._fg_scale) // 2) - (odb.width // 2)
|
self._odb_tilegrid.x = ((self._w * self._fg_scale) // 2) - (odb.width // 2)
|
||||||
|
return None
|
||||||
|
|
||||||
# pylint:enable=inconsistent-return-statements
|
# pylint:enable=inconsistent-return-statements
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# More drawing control
|
# More drawing control
|
||||||
|
|
||||||
def reset(self):
|
def reset(self) -> None:
|
||||||
"""
|
"""
|
||||||
Delete the turtle's drawings from the screen, re-center the turtle
|
Delete the turtle's drawings from the screen, re-center the turtle
|
||||||
and set variables to the default values."""
|
and set variables to the default values."""
|
||||||
|
|
@ -997,7 +1101,7 @@ class turtle:
|
||||||
self.pensize(1)
|
self.pensize(1)
|
||||||
self.pencolor(Color.WHITE)
|
self.pencolor(Color.WHITE)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self) -> None:
|
||||||
"""Delete the turtle's drawings from the screen. Do not move turtle."""
|
"""Delete the turtle's drawings from the screen. Do not move turtle."""
|
||||||
self.clearstamps()
|
self.clearstamps()
|
||||||
for w in range(self._w):
|
for w in range(self._w):
|
||||||
|
|
@ -1012,7 +1116,7 @@ class turtle:
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Visibility
|
# Visibility
|
||||||
|
|
||||||
def showturtle(self):
|
def showturtle(self) -> None:
|
||||||
"""
|
"""
|
||||||
Make the turtle visible."""
|
Make the turtle visible."""
|
||||||
if self._turtle_group:
|
if self._turtle_group:
|
||||||
|
|
@ -1024,7 +1128,7 @@ class turtle:
|
||||||
|
|
||||||
st = showturtle
|
st = showturtle
|
||||||
|
|
||||||
def hideturtle(self):
|
def hideturtle(self) -> None:
|
||||||
"""
|
"""
|
||||||
Make the turtle invisible."""
|
Make the turtle invisible."""
|
||||||
if not self._turtle_group:
|
if not self._turtle_group:
|
||||||
|
|
@ -1033,7 +1137,7 @@ class turtle:
|
||||||
|
|
||||||
ht = hideturtle
|
ht = hideturtle
|
||||||
|
|
||||||
def isvisible(self):
|
def isvisible(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Return True if the Turtle is shown, False if it's hidden."""
|
Return True if the Turtle is shown, False if it's hidden."""
|
||||||
if self._turtle_group:
|
if self._turtle_group:
|
||||||
|
|
@ -1041,7 +1145,11 @@ class turtle:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# pylint:disable=too-many-statements, too-many-branches
|
# pylint:disable=too-many-statements, too-many-branches
|
||||||
def changeturtle(self, source=None, dimensions=(12, 12)):
|
def changeturtle(
|
||||||
|
self,
|
||||||
|
source: Optional[Union[displayio.TileGrid, str]] = None,
|
||||||
|
dimensions: Tuple[int, int] = (12, 12),
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Change the turtle.
|
Change the turtle.
|
||||||
if a string is provided, its a path to an image opened via OnDiskBitmap
|
if a string is provided, its a path to an image opened via OnDiskBitmap
|
||||||
|
|
@ -1059,8 +1167,6 @@ class turtle:
|
||||||
self._turtle_odb_use -= 1
|
self._turtle_odb_use -= 1
|
||||||
self._turtle_odb = None
|
self._turtle_odb = None
|
||||||
if self._turtle_odb_file is not None:
|
if self._turtle_odb_file is not None:
|
||||||
if self._turtle_odb_use == 0:
|
|
||||||
self._turtle_odb_file.close()
|
|
||||||
self._turtle_odb_file = None
|
self._turtle_odb_file = None
|
||||||
self._turtle_pic = None
|
self._turtle_pic = None
|
||||||
self._drawturtle()
|
self._drawturtle()
|
||||||
|
|
@ -1073,17 +1179,13 @@ class turtle:
|
||||||
self._turtle_alt_sprite = None
|
self._turtle_alt_sprite = None
|
||||||
self._turtle_odb = None
|
self._turtle_odb = None
|
||||||
if not isinstance(self._turtle_pic, tuple):
|
if not isinstance(self._turtle_pic, tuple):
|
||||||
self._turtle_odb_file.close()
|
|
||||||
self._turtle_odb_file = None
|
self._turtle_odb_file = None
|
||||||
self._turtle_odb_use -= 1
|
self._turtle_odb_use -= 1
|
||||||
self._turtle_pic = None
|
self._turtle_pic = None
|
||||||
self._turtle_odb_file = open( # pylint: disable=consider-using-with
|
|
||||||
source, "rb"
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
self._turtle_odb = displayio.OnDiskBitmap(self._turtle_odb_file)
|
self._turtle_odb = displayio.OnDiskBitmap(source)
|
||||||
except:
|
except:
|
||||||
self._turtle_odb_file.close()
|
|
||||||
self._turtle_odb_file = None
|
self._turtle_odb_file = None
|
||||||
self._turtle_pic = None
|
self._turtle_pic = None
|
||||||
if visible:
|
if visible:
|
||||||
|
|
@ -1092,7 +1194,8 @@ class turtle:
|
||||||
self._turtle_odb_use += 1
|
self._turtle_odb_use += 1
|
||||||
self._turtle_pic = True
|
self._turtle_pic = True
|
||||||
self._turtle_alt_sprite = displayio.TileGrid(
|
self._turtle_alt_sprite = displayio.TileGrid(
|
||||||
self._turtle_odb, pixel_shader=displayio.ColorConverter()
|
self._turtle_odb,
|
||||||
|
pixel_shader=self._turtle_odb.pixel_shader,
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._turtle_group:
|
if self._turtle_group:
|
||||||
|
|
@ -1104,8 +1207,6 @@ class turtle:
|
||||||
if self._turtle_pic is not None:
|
if self._turtle_pic is not None:
|
||||||
if self._turtle_odb_file is not None:
|
if self._turtle_odb_file is not None:
|
||||||
self._turtle_odb_use -= 1
|
self._turtle_odb_use -= 1
|
||||||
if self._turtle_odb_use == 0:
|
|
||||||
self._turtle_odb_file.close()
|
|
||||||
self._turtle_pic = dimensions
|
self._turtle_pic = dimensions
|
||||||
self._turtle_alt_sprite = source
|
self._turtle_alt_sprite = source
|
||||||
if self._turtle_group:
|
if self._turtle_group:
|
||||||
|
|
@ -1113,16 +1214,14 @@ class turtle:
|
||||||
self._turtle_group.append(self._turtle_alt_sprite)
|
self._turtle_group.append(self._turtle_alt_sprite)
|
||||||
self._drawturtle()
|
self._drawturtle()
|
||||||
else:
|
else:
|
||||||
raise TypeError(
|
raise TypeError('Argument must be "str", a "displayio.TileGrid" or nothing.')
|
||||||
'Argument must be "str", a "displayio.TileGrid" or nothing.'
|
|
||||||
)
|
|
||||||
|
|
||||||
# pylint:enable=too-many-statements, too-many-branches
|
# pylint:enable=too-many-statements, too-many-branches
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Other
|
# Other
|
||||||
|
|
||||||
def _turn(self, angle):
|
def _turn(self, angle: float) -> None:
|
||||||
if angle % self._fullcircle == 0:
|
if angle % self._fullcircle == 0:
|
||||||
return
|
return
|
||||||
if not self.isdown() or self._pensize == 1:
|
if not self.isdown() or self._pensize == 1:
|
||||||
|
|
@ -1130,9 +1229,7 @@ class turtle:
|
||||||
self._heading %= self._fullcircle # wrap
|
self._heading %= self._fullcircle # wrap
|
||||||
return
|
return
|
||||||
start_angle = self._heading
|
start_angle = self._heading
|
||||||
steps = math.ceil(
|
steps = math.ceil((self._pensize * 2) * 3.1415 * (abs(angle) / self._fullcircle))
|
||||||
(self._pensize * 2) * 3.1415 * (abs(angle) / self._fullcircle)
|
|
||||||
)
|
|
||||||
if steps < 1:
|
if steps < 1:
|
||||||
d_angle = angle
|
d_angle = angle
|
||||||
steps = 1
|
steps = 1
|
||||||
|
|
@ -1153,7 +1250,7 @@ class turtle:
|
||||||
return
|
return
|
||||||
|
|
||||||
if abs(angle - steps * d_angle) >= abs(d_angle):
|
if abs(angle - steps * d_angle) >= abs(d_angle):
|
||||||
steps += abs(angle - steps * d_angle) // abs(d_angle)
|
steps += int(abs(angle - steps * d_angle) // abs(d_angle))
|
||||||
|
|
||||||
self._plot(self._x, self._y, self._pencolor)
|
self._plot(self._x, self._y, self._pencolor)
|
||||||
for _ in range(steps):
|
for _ in range(steps):
|
||||||
|
|
@ -1167,7 +1264,7 @@ class turtle:
|
||||||
self._heading %= self._fullcircle
|
self._heading %= self._fullcircle
|
||||||
self._plot(self._x, self._y, self._pencolor)
|
self._plot(self._x, self._y, self._pencolor)
|
||||||
|
|
||||||
def _GCD(self, a, b):
|
def _GCD(self, a: int, b: int) -> int:
|
||||||
"""GCD(a,b):
|
"""GCD(a,b):
|
||||||
recursive 'Greatest common divisor' calculus for int numbers a and b"""
|
recursive 'Greatest common divisor' calculus for int numbers a and b"""
|
||||||
if b == 0:
|
if b == 0:
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,8 @@
|
||||||
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
|
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
|
||||||
.. use this format as the module name: "adafruit_foo.foo"
|
.. use this format as the module name: "adafruit_foo.foo"
|
||||||
|
|
||||||
|
API Reference
|
||||||
|
#############
|
||||||
|
|
||||||
.. automodule:: adafruit_turtle
|
.. automodule:: adafruit_turtle
|
||||||
:members:
|
:members:
|
||||||
|
|
|
||||||
34
docs/conf.py
34
docs/conf.py
|
|
@ -1,9 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -16,6 +15,7 @@ sys.path.insert(0, os.path.abspath(".."))
|
||||||
# ones.
|
# ones.
|
||||||
extensions = [
|
extensions = [
|
||||||
"sphinx.ext.autodoc",
|
"sphinx.ext.autodoc",
|
||||||
|
"sphinxcontrib.jquery",
|
||||||
"sphinx.ext.intersphinx",
|
"sphinx.ext.intersphinx",
|
||||||
"sphinx.ext.napoleon",
|
"sphinx.ext.napoleon",
|
||||||
"sphinx.ext.todo",
|
"sphinx.ext.todo",
|
||||||
|
|
@ -37,7 +37,6 @@ autodoc_mock_imports = [
|
||||||
"adafruit_bitmap_font",
|
"adafruit_bitmap_font",
|
||||||
"adafruit_display_text",
|
"adafruit_display_text",
|
||||||
"adafruit_esp32spi",
|
"adafruit_esp32spi",
|
||||||
"secrets",
|
|
||||||
"adafruit_sdcard",
|
"adafruit_sdcard",
|
||||||
"storage",
|
"storage",
|
||||||
"adafruit_io",
|
"adafruit_io",
|
||||||
|
|
@ -48,12 +47,12 @@ autodoc_mock_imports = [
|
||||||
|
|
||||||
|
|
||||||
intersphinx_mapping = {
|
intersphinx_mapping = {
|
||||||
"python": ("https://docs.python.org/3.4", None),
|
"python": ("https://docs.python.org/3", None),
|
||||||
"BusDevice": (
|
"BusDevice": (
|
||||||
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
|
"https://docs.circuitpython.org/projects/busdevice/en/latest/",
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
|
"CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
|
|
@ -66,7 +65,12 @@ master_doc = "index"
|
||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = "Adafruit turtle Library"
|
project = "Adafruit turtle Library"
|
||||||
copyright = "2019 Adafruit"
|
creation_year = "2019"
|
||||||
|
current_year = str(datetime.datetime.now().year)
|
||||||
|
year_duration = (
|
||||||
|
current_year if current_year == creation_year else creation_year + " - " + current_year
|
||||||
|
)
|
||||||
|
copyright = year_duration + " Adafruit"
|
||||||
author = "Adafruit"
|
author = "Adafruit"
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement for
|
# The version info for the project you're documenting, acts as replacement for
|
||||||
|
|
@ -83,7 +87,7 @@ release = "1.0"
|
||||||
#
|
#
|
||||||
# This is also used if you do content translation via gettext catalogs.
|
# This is also used if you do content translation via gettext catalogs.
|
||||||
# Usually you set "language" from the command line for these cases.
|
# Usually you set "language" from the command line for these cases.
|
||||||
language = None
|
language = "en"
|
||||||
|
|
||||||
# List of patterns, relative to source directory, that match files and
|
# List of patterns, relative to source directory, that match files and
|
||||||
# directories to ignore when looking for source files.
|
# directories to ignore when looking for source files.
|
||||||
|
|
@ -115,19 +119,9 @@ napoleon_numpy_docstring = False
|
||||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||||
# a list of builtin themes.
|
# a list of builtin themes.
|
||||||
#
|
#
|
||||||
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
|
import sphinx_rtd_theme
|
||||||
|
|
||||||
if not on_rtd: # only import and set the theme if we're building docs locally
|
html_theme = "sphinx_rtd_theme"
|
||||||
try:
|
|
||||||
import sphinx_rtd_theme
|
|
||||||
|
|
||||||
html_theme = "sphinx_rtd_theme"
|
|
||||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
|
|
||||||
except:
|
|
||||||
html_theme = "default"
|
|
||||||
html_theme_path = ["."]
|
|
||||||
else:
|
|
||||||
html_theme_path = ["."]
|
|
||||||
|
|
||||||
# Add any paths that contain custom static files (such as style sheets) here,
|
# Add any paths that contain custom static files (such as style sheets) here,
|
||||||
# relative to this directory. They are copied after the builtin static files,
|
# relative to this directory. They are copied after the builtin static files,
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,9 @@ Table of Contents
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:caption: Other Links
|
:caption: Other Links
|
||||||
|
|
||||||
Download <https://github.com/adafruit/Adafruit_CircuitPython_turtle/releases/latest>
|
Download from GitHub <https://github.com/adafruit/Adafruit_CircuitPython_turtle/releases/latest>
|
||||||
CircuitPython Reference Documentation <https://circuitpython.readthedocs.io>
|
Download Library Bundle <https://circuitpython.org/libraries>
|
||||||
|
CircuitPython Reference Documentation <https://docs.circuitpython.org>
|
||||||
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
|
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
|
||||||
Discord Chat <https://adafru.it/discord>
|
Discord Chat <https://adafru.it/discord>
|
||||||
Adafruit Learning System <https://learn.adafruit.com>
|
Adafruit Learning System <https://learn.adafruit.com>
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,6 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
sphinx>=4.0.0
|
sphinx
|
||||||
|
sphinxcontrib-jquery
|
||||||
|
sphinx-rtd-theme
|
||||||
|
|
|
||||||
BIN
examples/icons/Play_48x48_small.bmp
Normal file
BIN
examples/icons/Play_48x48_small.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
2
examples/icons/Play_48x48_small.bmp.license
Normal file
2
examples/icons/Play_48x48_small.bmp.license
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# SPDX-FileCopyrightText: 2021 Tim C for Adafruit Industries
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import Color, turtle
|
from adafruit_turtle import Color, turtle
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
|
||||||
38
examples/turtle_bgpic_changeturtle.py
Normal file
38
examples/turtle_bgpic_changeturtle.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import board
|
||||||
|
|
||||||
|
from adafruit_turtle import Color, turtle
|
||||||
|
|
||||||
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
||||||
|
# The purpose of this test is to check that the OnDiskBitmap usage is
|
||||||
|
# working correctly: bgpic(), changeturtle() & stamp()
|
||||||
|
|
||||||
|
# Make sure that the following file is copied to the CircuitPython drive
|
||||||
|
ICON = "/icons/Play_48x48_small.bmp"
|
||||||
|
turtle.bgpic(ICON)
|
||||||
|
turtle.changeturtle(ICON)
|
||||||
|
|
||||||
|
starsize = min(board.DISPLAY.width, board.DISPLAY.height) * 0.9 # 90% of screensize
|
||||||
|
|
||||||
|
print("Turtle time! Lets draw a star")
|
||||||
|
|
||||||
|
turtle.pencolor(Color.BLUE)
|
||||||
|
turtle.setheading(90)
|
||||||
|
|
||||||
|
turtle.penup()
|
||||||
|
turtle.goto(-starsize / 2, 0)
|
||||||
|
turtle.pendown()
|
||||||
|
|
||||||
|
start = turtle.pos()
|
||||||
|
while True:
|
||||||
|
turtle.forward(starsize)
|
||||||
|
turtle.stamp()
|
||||||
|
turtle.left(170)
|
||||||
|
if abs(turtle.pos() - start) < 1:
|
||||||
|
break
|
||||||
|
|
||||||
|
while True:
|
||||||
|
pass
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import Color, turtle
|
from adafruit_turtle import Color, turtle
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import turtle
|
from adafruit_turtle import turtle
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import turtle
|
from adafruit_turtle import turtle
|
||||||
|
|
||||||
print("Turtle time! Lets draw a square with dots")
|
print("Turtle time! Lets draw a square with dots")
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import turtle
|
from adafruit_turtle import turtle
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,28 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import turtle
|
from adafruit_turtle import turtle
|
||||||
|
|
||||||
|
|
||||||
def f(side_length, depth, generation):
|
def f(side_length, depth, generation):
|
||||||
if depth != 0:
|
if depth == 0:
|
||||||
side = lambda: f(side_length / 3, depth - 1, generation + 1)
|
turtle.forward(side_length)
|
||||||
side()
|
return
|
||||||
turtle.left(60)
|
side = lambda: f(side_length / 3, depth - 1, generation + 1)
|
||||||
side()
|
side()
|
||||||
turtle.right(120)
|
turtle.left(60)
|
||||||
side()
|
side()
|
||||||
turtle.left(60)
|
turtle.right(120)
|
||||||
side()
|
side()
|
||||||
|
turtle.left(60)
|
||||||
|
side()
|
||||||
|
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
||||||
unit = min(board.DISPLAY.width / 3, board.DISPLAY.height / 4)
|
unit = min(board.DISPLAY.width / 3, board.DISPLAY.height / 4)
|
||||||
top_len = unit * 3
|
top_len = unit * 3
|
||||||
print(top_len)
|
|
||||||
turtle.penup()
|
turtle.penup()
|
||||||
turtle.goto(-1.5 * unit, unit)
|
turtle.goto(-1.5 * unit, unit)
|
||||||
turtle.pendown()
|
turtle.pendown()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import turtle
|
from adafruit_turtle import turtle
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,24 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
from adafruit_turtle import turtle, Color
|
|
||||||
|
|
||||||
generation_colors = [Color.RED, Color.BLUE, Color.GREEN]
|
from adafruit_turtle import Color, turtle
|
||||||
|
|
||||||
|
generation_colors = [Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW]
|
||||||
|
|
||||||
|
|
||||||
def f(side_length, depth, generation):
|
def f(side_length, depth, generation):
|
||||||
if depth != 0:
|
if depth == 0:
|
||||||
side = lambda: f(side_length / 3, depth - 1, generation + 1)
|
turtle.forward(side_length)
|
||||||
side()
|
return
|
||||||
turtle.left(60)
|
side = lambda: f(side_length / 3, depth - 1, generation + 1)
|
||||||
side()
|
side()
|
||||||
turtle.right(120)
|
turtle.left(60)
|
||||||
side()
|
side()
|
||||||
turtle.left(60)
|
turtle.right(120)
|
||||||
side()
|
side()
|
||||||
|
turtle.left(60)
|
||||||
|
side()
|
||||||
|
|
||||||
|
|
||||||
def snowflake(num_generations, generation_color):
|
def snowflake(num_generations, generation_color):
|
||||||
|
|
@ -40,7 +43,7 @@ turtle.penup()
|
||||||
turtle.goto(-1.5 * unit, unit)
|
turtle.goto(-1.5 * unit, unit)
|
||||||
turtle.pendown()
|
turtle.pendown()
|
||||||
|
|
||||||
for generations in range(3):
|
for generations in range(4):
|
||||||
snowflake(generations, generation_colors[generations])
|
snowflake(generations, generation_colors[generations])
|
||||||
turtle.right(120)
|
turtle.right(120)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import turtle
|
from adafruit_turtle import turtle
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -10,7 +11,6 @@ def getMid(p1, p2):
|
||||||
|
|
||||||
|
|
||||||
def triangle(points, depth):
|
def triangle(points, depth):
|
||||||
|
|
||||||
turtle.penup()
|
turtle.penup()
|
||||||
turtle.goto(points[0][0], points[0][1])
|
turtle.goto(points[0][0], points[0][1])
|
||||||
turtle.pendown()
|
turtle.pendown()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import Color, turtle
|
from adafruit_turtle import Color, turtle
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import Color, turtle
|
from adafruit_turtle import Color, turtle
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
||||||
from adafruit_turtle import Color, turtle
|
from adafruit_turtle import Color, turtle
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import board
|
import board
|
||||||
from adafruit_turtle import turtle, Color
|
|
||||||
|
from adafruit_turtle import Color, turtle
|
||||||
|
|
||||||
turtle = turtle(board.DISPLAY)
|
turtle = turtle(board.DISPLAY)
|
||||||
|
|
||||||
|
|
|
||||||
3
optional_requirements.txt
Normal file
3
optional_requirements.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
45
pyproject.toml
Normal file
45
pyproject.toml
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = [
|
||||||
|
"setuptools",
|
||||||
|
"wheel",
|
||||||
|
"setuptools-scm",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "adafruit-circuitpython-turtle"
|
||||||
|
description = "Turtle graphics library for CircuitPython and displayio"
|
||||||
|
version = "0.0.0+auto.0"
|
||||||
|
readme = "README.rst"
|
||||||
|
authors = [
|
||||||
|
{name = "Adafruit Industries", email = "circuitpython@adafruit.com"}
|
||||||
|
]
|
||||||
|
urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_turtle"}
|
||||||
|
keywords = [
|
||||||
|
"adafruit",
|
||||||
|
"blinka",
|
||||||
|
"circuitpython",
|
||||||
|
"micropython",
|
||||||
|
"turtle",
|
||||||
|
"graphics,turtle",
|
||||||
|
]
|
||||||
|
license = {text = "MIT"}
|
||||||
|
classifiers = [
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"Topic :: Software Development :: Libraries",
|
||||||
|
"Topic :: Software Development :: Embedded Systems",
|
||||||
|
"Topic :: System :: Hardware",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
]
|
||||||
|
dynamic = ["dependencies", "optional-dependencies"]
|
||||||
|
|
||||||
|
[tool.setuptools]
|
||||||
|
py-modules = ["adafruit_turtle"]
|
||||||
|
|
||||||
|
[tool.setuptools.dynamic]
|
||||||
|
dependencies = {file = ["requirements.txt"]}
|
||||||
|
optional-dependencies = {optional = {file = ["optional_requirements.txt"]}}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
|
|
||||||
111
ruff.toml
Normal file
111
ruff.toml
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
target-version = "py38"
|
||||||
|
line-length = 100
|
||||||
|
|
||||||
|
[lint]
|
||||||
|
preview = true
|
||||||
|
select = ["I", "PL", "UP"]
|
||||||
|
|
||||||
|
extend-select = [
|
||||||
|
"D419", # empty-docstring
|
||||||
|
"E501", # line-too-long
|
||||||
|
"W291", # trailing-whitespace
|
||||||
|
"PLC0414", # useless-import-alias
|
||||||
|
"PLC2401", # non-ascii-name
|
||||||
|
"PLC2801", # unnecessary-dunder-call
|
||||||
|
"PLC3002", # unnecessary-direct-lambda-call
|
||||||
|
"E999", # syntax-error
|
||||||
|
"PLE0101", # return-in-init
|
||||||
|
"F706", # return-outside-function
|
||||||
|
"F704", # yield-outside-function
|
||||||
|
"PLE0116", # continue-in-finally
|
||||||
|
"PLE0117", # nonlocal-without-binding
|
||||||
|
"PLE0241", # duplicate-bases
|
||||||
|
"PLE0302", # unexpected-special-method-signature
|
||||||
|
"PLE0604", # invalid-all-object
|
||||||
|
"PLE0605", # invalid-all-format
|
||||||
|
"PLE0643", # potential-index-error
|
||||||
|
"PLE0704", # misplaced-bare-raise
|
||||||
|
"PLE1141", # dict-iter-missing-items
|
||||||
|
"PLE1142", # await-outside-async
|
||||||
|
"PLE1205", # logging-too-many-args
|
||||||
|
"PLE1206", # logging-too-few-args
|
||||||
|
"PLE1307", # bad-string-format-type
|
||||||
|
"PLE1310", # bad-str-strip-call
|
||||||
|
"PLE1507", # invalid-envvar-value
|
||||||
|
"PLE2502", # bidirectional-unicode
|
||||||
|
"PLE2510", # invalid-character-backspace
|
||||||
|
"PLE2512", # invalid-character-sub
|
||||||
|
"PLE2513", # invalid-character-esc
|
||||||
|
"PLE2514", # invalid-character-nul
|
||||||
|
"PLE2515", # invalid-character-zero-width-space
|
||||||
|
"PLR0124", # comparison-with-itself
|
||||||
|
"PLR0202", # no-classmethod-decorator
|
||||||
|
"PLR0203", # no-staticmethod-decorator
|
||||||
|
"UP004", # useless-object-inheritance
|
||||||
|
"PLR0206", # property-with-parameters
|
||||||
|
"PLR0904", # too-many-public-methods
|
||||||
|
"PLR0911", # too-many-return-statements
|
||||||
|
"PLR0912", # too-many-branches
|
||||||
|
"PLR0913", # too-many-arguments
|
||||||
|
"PLR0914", # too-many-locals
|
||||||
|
"PLR0915", # too-many-statements
|
||||||
|
"PLR0916", # too-many-boolean-expressions
|
||||||
|
"PLR1702", # too-many-nested-blocks
|
||||||
|
"PLR1704", # redefined-argument-from-local
|
||||||
|
"PLR1711", # useless-return
|
||||||
|
"C416", # unnecessary-comprehension
|
||||||
|
"PLR1733", # unnecessary-dict-index-lookup
|
||||||
|
"PLR1736", # unnecessary-list-index-lookup
|
||||||
|
|
||||||
|
# ruff reports this rule is unstable
|
||||||
|
#"PLR6301", # no-self-use
|
||||||
|
|
||||||
|
"PLW0108", # unnecessary-lambda
|
||||||
|
"PLW0120", # useless-else-on-loop
|
||||||
|
"PLW0127", # self-assigning-variable
|
||||||
|
"PLW0129", # assert-on-string-literal
|
||||||
|
"B033", # duplicate-value
|
||||||
|
"PLW0131", # named-expr-without-context
|
||||||
|
"PLW0245", # super-without-brackets
|
||||||
|
"PLW0406", # import-self
|
||||||
|
"PLW0602", # global-variable-not-assigned
|
||||||
|
"PLW0603", # global-statement
|
||||||
|
"PLW0604", # global-at-module-level
|
||||||
|
|
||||||
|
# fails on the try: import typing used by libraries
|
||||||
|
#"F401", # unused-import
|
||||||
|
|
||||||
|
"F841", # unused-variable
|
||||||
|
"E722", # bare-except
|
||||||
|
"PLW0711", # binary-op-exception
|
||||||
|
"PLW1501", # bad-open-mode
|
||||||
|
"PLW1508", # invalid-envvar-default
|
||||||
|
"PLW1509", # subprocess-popen-preexec-fn
|
||||||
|
"PLW2101", # useless-with-lock
|
||||||
|
"PLW3301", # nested-min-max
|
||||||
|
]
|
||||||
|
|
||||||
|
ignore = [
|
||||||
|
"PLR2004", # magic-value-comparison
|
||||||
|
"UP030", # format literals
|
||||||
|
"PLW1514", # unspecified-encoding
|
||||||
|
"PLR0913", # too-many-arguments
|
||||||
|
"PLR0915", # too-many-statements
|
||||||
|
"PLR0917", # too-many-positional-arguments
|
||||||
|
"PLR0904", # too-many-public-methods
|
||||||
|
"PLR0912", # too-many-branches
|
||||||
|
"PLR0916", # too-many-boolean-expressions
|
||||||
|
"PLR6301", # could-be-static no-self-use
|
||||||
|
"PLC0415", # import outside toplevel
|
||||||
|
"PLC2701", # private import
|
||||||
|
"UP007", # x | y typing
|
||||||
|
"UP006", # builtin instead of typing import
|
||||||
|
"PLR0914", # too many locals
|
||||||
|
]
|
||||||
|
|
||||||
|
[format]
|
||||||
|
line-ending = "lf"
|
||||||
57
setup.py
57
setup.py
|
|
@ -1,57 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
"""A setuptools based setup module.
|
|
||||||
|
|
||||||
See:
|
|
||||||
https://packaging.python.org/en/latest/distributing.html
|
|
||||||
https://github.com/pypa/sampleproject
|
|
||||||
"""
|
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
|
||||||
|
|
||||||
# To use a consistent encoding
|
|
||||||
from codecs import open
|
|
||||||
from os import path
|
|
||||||
|
|
||||||
here = path.abspath(path.dirname(__file__))
|
|
||||||
|
|
||||||
# Get the long description from the README file
|
|
||||||
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
|
|
||||||
long_description = f.read()
|
|
||||||
|
|
||||||
setup(
|
|
||||||
name="adafruit-circuitpython-turtle",
|
|
||||||
use_scm_version=True,
|
|
||||||
setup_requires=["setuptools_scm"],
|
|
||||||
description="Turtle graphics library for CircuitPython and displayio",
|
|
||||||
long_description=long_description,
|
|
||||||
long_description_content_type="text/x-rst",
|
|
||||||
# The project's main homepage.
|
|
||||||
url="https://github.com/adafruit/Adafruit_CircuitPython_turtle",
|
|
||||||
# Author details
|
|
||||||
author="Adafruit Industries",
|
|
||||||
author_email="circuitpython@adafruit.com",
|
|
||||||
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"],
|
|
||||||
# Choose your license
|
|
||||||
license="MIT",
|
|
||||||
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
|
|
||||||
classifiers=[
|
|
||||||
"Development Status :: 3 - Alpha",
|
|
||||||
"Intended Audience :: Developers",
|
|
||||||
"Topic :: Software Development :: Libraries",
|
|
||||||
"Topic :: System :: Hardware",
|
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"Programming Language :: Python :: 3.4",
|
|
||||||
"Programming Language :: Python :: 3.5",
|
|
||||||
],
|
|
||||||
# What does your project relate to?
|
|
||||||
keywords="adafruit blinka circuitpython micropython turtle graphics,turtle",
|
|
||||||
# You can just specify the packages manually here if your project is
|
|
||||||
# simple. Or you can use find_packages().
|
|
||||||
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
|
|
||||||
# CHANGE `py_modules=['...']` TO `packages=['...']`
|
|
||||||
py_modules=["adafruit_turtle"],
|
|
||||||
)
|
|
||||||
Loading…
Reference in a new issue