question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minor turtle issues

See original GitHub issue

The existing turtle module is an excellent adaptation of CPython’s tkinter-based version that uses Scalable Vector Graphics (svg) for drawing including animations and is perfectly usable for simple demonstrations.

However, as I explored it, I found quite a few missing methods, some of which might not make much sense to implement in this browser version, but not all. I will document them here as I go along, as well as the progress done on a branch in my fork (https://github.com/aroberge/brython/tree/fix/master/turtle739).

  • 1. at https://github.com/brython-dev/brython/blob/master/www/src/Lib/turtle.py#L3020 , document[_CFG["turtle_canvas_id"]] can raise a KeyError exception if the restart() function is called twice in a row.
  • 2. write (https://github.com/brython-dev/brython/blob/master/www/src/Lib/turtle.py#L2777) should allow the user to set the font. However, the font information is not passed on to svg.text (https://github.com/brython-dev/brython/blob/master/www/src/Lib/turtle.py#L338). Similarly for the align parameter.
  • 3. Calling Turtle with “blank” as the default shape appears to be causing an error. This is for a turtle using a gif for its image. It will be removed.
  • 4. Setting speed to zero should result in immediate drawing; instead nothing is drawn. The fastest animation seems to be set to a duration of 0.1 s (https://github.com/brython-dev/brython/blob/master/www/src/Lib/turtle.py#L201), while svg supports animation duration in the range of ms (https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/dur)
  • 5. Many existing configuration settings are absolutely irrelevant (and ignored); they should be removed.
  • 6. left() appears to be turning “right” instead.
  • 7. The mode settings (logo, standard, world) appears to be ignored.
  • 8. CPython’s version has a bug (https://bugs.python.org/issue23660) which I filed almost 3 years ago on behalf of another user; this bug is still not fixed but it should be in the Brython’s version.
  • 9. In the Brython demo, it might be useful to add an output print “window” either for direct use by the turtle user or to report errors.
  • 10. The code run when the module is imported as __main__ is irrelevant for Brython and has been removed.
  • 11. The CPython turtle module has an undo() method which does not really makes sense in the current context. It, and all the associated objects (such as undobuffer) will be removed.
  • 12. With the CPython turtle, in both the standard and logo mode, the y coordinate increases towards the top of the screen, whereas it increases towards the bottom with the Brython turtle.
  • 13. When using CPython, the turtle itself is drawn the same when changing the line thickness; however this is not the case with Brython’s turtle.
  • 14. The dot() method does not produce a circle and appears to suspend any running program.
  • 15. If write() is the very first method called before any other turtle drawing, nothing gets written, nor drawn afterwards.
  • 16. The bgcolor() method does not do anything.
  • 17. The stamp() method does not do anything.
  • 18. begin_fill() and end_fill() are ignored.
  • 19. If two or more turtles are on the screen, only one is shown while a drawing is done; this is unlike the CPython version.
  • 20. The function based version (i.e. anonymous turtle) is not available.
  • 21. With penup(), the moving turtle is currently not drawn when moving.

Efficiency consideration

This following should be done as a second pass (perhaps in a different branch) after all the relevant methods have been done.

Currently, each time a turtle is moved, a “new” turtle shape is created and drawn on the screen as a separate svg element, moved, and, unlike in the CPython case, disappears from the screen after a drawing is done. It should be possible to repeatedly use the turtles that have been created by:

  1. setting fill to freeze after an animation has been done.
  2. setting fill to remove when another animation is desired.
  3. perform the animation
  4. set fill to freeze again

In addition to being more efficient, as we would reuse an existing svg element rather than creating and adding a new one each time, this would likely mimic better the behavior of the CPython turtle.

A further consideration might be to see if clear and reset for a given turtle could not be implemented by setting the visibility attribute of previously drawn elements.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
arobergecommented, Jan 2, 2018

image

The reddit post code using my current version. I had forgotten to call the done() method (which I previously named show()) in my recent attempts - thus producing no output.

1reaction
arobergecommented, Jan 2, 2018

Just because people like pictures … Using CPython’s version, I set the pen width to 30 and drew a black line, and then set the pen width to 3 and drew the same distance over: the “line” drawn has rounded edges. image

Using the current version with Brython, I get the following: image

This likely explains the difference between the image I obtained using the code from the reddit post and the image posted there.

I will try to change the “line” drawing method to reproduce the CPython’s case but add an additional option parameter (rounded_lines or similar), set to True by default but could be changed by the user.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common Problems in Aquatic Turtles - VCA Animal Hospitals
General information · Cystic calculi · Prolapses · Irregular shell growth · Shell fractures or trauma · Algae on the shell · Skin...
Read more >
Tiny Turtles and Salmonella | Healthy Pets, Healthy People
People can get sick from Salmonella by touching turtles, their tank water, their supplies, or the areas where they live and roam.
Read more >
Pet Turtles: Cute But Commonly Contaminated with Salmonella
“All reptiles and amphibians have the potential to be carriers of Salmonella,” says Vic Boddie II, Ph.D., a consumer safety officer in the...
Read more >
Common Diseases Of Aquatic Turtles - Reptiles Magazine
Turtles often develop infections of the shell, respiratory tract, skin, ears, and digestive tract. In severe cases, infection can spread through ...
Read more >
List of Turtle Diseases Illnesses and Injuries - Caring Pets
superficial wounds such as scratches and minor cuts are common place among turtles. This is especially the case when it comes to turtles...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found