GithubHelp home page GithubHelp logo

adafruit_circuitpython_turtle's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

Turtle graphics library for CircuitPython and displayio

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-turtle

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-turtle

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-turtle

Usage Example

import board
from adafruit_turtle import Color, turtle

turtle = turtle(board.DISPLAY)
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.penup()
turtle.goto(-starsize/2, 0)
turtle.pendown()

start = turtle.pos()
while True:
    turtle.forward(starsize)
    turtle.left(170)
    if abs(turtle.pos() - start) < 1:
        break

while True:
    pass

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_turtle's People

Contributors

caternuson avatar dastels avatar dhalbert avatar evaherrada avatar foamyguy avatar jepler avatar kattni avatar ladyada avatar lesamouraipourpre avatar marius-450 avatar retiredwizard avatar rrahkola avatar shulltronics avatar siddacious avatar sommersoft avatar tannewt avatar tekktrik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_turtle's Issues

Pylint: assignment-from-no-return

************* Module turtle_koch
examples/turtle_koch.py:7:8: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
************* Module turtle_overlayed_koch
examples/turtle_overlayed_koch.py:9:8: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)

https://github.com/adafruit/Adafruit_CircuitPython_turtle/blob/c2d86f2f24bf1cf783bc3cce9bf59373e95dc242/examples/turtle_koch.py#L4:8

https://github.com/adafruit/Adafruit_CircuitPython_turtle/blob/c2d86f2f24bf1cf783bc3cce9bf59373e95dc242/examples/turtle_koch.py#L7:9

I'm not exactly sure why this is even being done, I would test just having it do turtle.forward(line_length) but I don't have the hardware with me to test.

@dastels Any insight into this?

Referencing main issue: adafruit/Adafruit_CircuitPython_Bundle#232
@kattni

turtle constructor incompatible with CPython: tuple expected at most 1 argument, got 2

I'm working on adopting this library to use with CPython on Generic x86 computers. When I try to use this library I get the following error:

Traceback (most recent call last):
  File "/home/carstentb/Projects/intro-to-computing/L5/benzene.py", line 20, in <module>
    start = turtle.pos()
  File "/home/carstentb/Projects/forks/Adafruit_CircuitPython_turtle/adafruit_turtle.py", line 729, in pos
    return Vec2D(self._x - self._w // 2, self._h // 2 - self._y)
TypeError: tuple expected at most 1 argument, got 2

After some Googleing, I found that for child classes of Tuple, one should use the new constructor instead of init. I implemented this and got it working for CPython (see my fork here), but that breaks it on CircuitPython! When I test my changes on a Feather nRF52840 Express from CircuitPython 7.3.1, I get this error:

Traceback (most recent call last):                                                                                    
  File "code.py", line 32, in <module>                                                                                
  File "/lib/adafruit_turtle.py", line 736, in pos                                                                    
  File "/lib/adafruit_turtle.py", line 97, in __new__                                                                 
TypeError: function takes 1 positional arguments but 2 were given

Is this an incompatibility of CircuitPython and CPython? I would love to get my changes merged in here, but obviously that can't happen if my changes break this on the CircuitPython interpreter.
I would appreciate any comments or direction on how this might be resolved. Thanks! :)

Draw to displayio Group.

I think this is a feature request. :) I'm wondering if it's possible, of if the library would need a re-write to go displayio?

Thanks!

pos() not working as expected?

Maybe I'm just not using it as intended?

Adafruit CircuitPython 4.1.0 on 2019-08-02; Adafruit PyPortal with samd51j20
>>> import board
>>> from adafruit_turtle import turtle
>>> turtle = turtle(board.DISPLAY)
>>> turtle.pos()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/adafruit_turtle.py", line 133, in __repr__
TypeError: can't convert Vec2D to float
>>> 

Other overrides work OK. Ex:

>>> turtle.pos()[0]
0
>>> turtle.pos()[1]
0
>>> print(turtle.pos())
(0, 0)
>>> 

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_turtle.py:97
  • adafruit_turtle.py:100
  • adafruit_turtle.py:103
  • adafruit_turtle.py:108
  • adafruit_turtle.py:113
  • adafruit_turtle.py:122
  • adafruit_turtle.py:144
  • adafruit_turtle.py:264
  • adafruit_turtle.py:279
  • adafruit_turtle.py:291
  • adafruit_turtle.py:305
  • adafruit_turtle.py:320
  • adafruit_turtle.py:402
  • adafruit_turtle.py:411
  • adafruit_turtle.py:420
  • adafruit_turtle.py:449
  • adafruit_turtle.py:529
  • adafruit_turtle.py:573
  • adafruit_turtle.py:605
  • adafruit_turtle.py:638
  • adafruit_turtle.py:684
  • adafruit_turtle.py:707
  • adafruit_turtle.py:734
  • adafruit_turtle.py:767
  • adafruit_turtle.py:785
  • adafruit_turtle.py:794
  • adafruit_turtle.py:808
  • adafruit_turtle.py:866
  • adafruit_turtle.py:885
  • adafruit_turtle.py:890
  • adafruit_turtle.py:918
  • adafruit_turtle.py:952
  • adafruit_turtle.py:1044
  • adafruit_turtle.py:1123
  • adafruit_turtle.py:1168

internal time.sleep(0.003) hacks are required but limit speed

Wanting to speed it up before speed and turtle hiding are implemented i noticed the time.sleep(0.003) calls in the code and figured I'd start there as a quick hack.

Removing those "does" speed it up. It also messes up the drawing with only a fraction of pixels making it to the display (on a pygamer under circuitpython 4.1.0beta1). There appears to be a displayio related race condition those sleeps are working around?

'Vec2D' object is not subscriptable

Duplicate of adafruit/circuitpython#2503. Opened here to help users who may look here. See the link for a full explanation.

A simple workaround if you run into this is to change the Vec2D class to have a tuple instead of extending tuple:

class Vec2D(object):
    def __init__(self, x, y):
        self.tup = (x, y)

    def __getitem__(self, i):
        return self.tup[i]

Drawing shapes requires degrees mode

Using the dot or circle functions while in radians mode appears to freeze the program for a number of seconds as it draws small lines for dot (instead of a dot) and heads out to a point and back for circle (instead of a circle or any regular polygon) before continuing to run the rest of the program. Using a Circuit Playground Bluefruit with TFT Gizmo.

Code to reproduce:

import board
import busio
import displayio
import adafruit_turtle

displayio.release_displays()
spi = busio.SPI(board.SCL, MOSI=board.SDA)
display_bus = displayio.FourWire(spi, command=board.TX, chip_select=board.RX)
display = ST7789(display_bus, width=240, height=240, rowstart=80, backlight_pin=board.A3, rotation=180)
turtle = adafruit_turtle.turtle(display)

turtle.radians()
turtle.pendown()
turtle.dot(10)
turtle.circle(50)

The workaround is to reset mode with turtle.degrees() before attempting to call either dot or circle.

Can not specify external display

It looks like the idea was to be able to pass in a display object to override the default of using board.DISPLAY. However, for boards with no built in display, currently can not even import the library:

Adafruit CircuitPython 5.0.0-alpha.4 on 2019-09-15; Adafruit Circuit Playground Bluefruit with nRF52840
>>> from adafruit_turtle import turtle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/travis/build/adafruit/Adafruit_CircuitPython_Bundle/libraries/helpers/turtle/adafruit_turtle.py", line 136, in <module>
  File "/home/travis/build/adafruit/Adafruit_CircuitPython_Bundle/libraries/helpers/turtle/adafruit_turtle.py", line 139, in turtle
AttributeError: 'module' object has no attribute 'DISPLAY'
>>> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.