0

It took me too long to realize I had used rgb values suitable for colormode(255) instead of the default colormode(1.). I know this is a rather small detail, but is not turtle directed to learners which we are hopefully making the path as easy as possible?

My example code:

#color_mode_range.py    12Jul2023, from color_mode_issue.py
"""
color((r,g,b)) out-of-range error not well stated
"""
from turtle import *
# Default colormode == 1.
rgb = (0,134,255)       # cerulean, one shade
print("Setting color using color(", rgb, ")")
try:
    color(rgb)              # Set color
except Exception as ex:
    print("oops... we get the error response:\n", ex)
    cm = colormode()
    print("Color value(s) out of range 0-", cm,
          " would have been much more helpful", sep="")

Output

Setting color using color( (0, 134, 255) )
oops... we get the error response:
 bad color sequence: (0, 134, 255)
Color value(s) out of range 0-1.0 would have been much more helpful
crs
  • 51
  • 5
  • Turtle is actually [pretty confusing for learners, IMO](https://gist.github.com/ggorlen/f46857bd0057ca919b97d5569f6ec641). Tons of gotchas, poor design choices and confusing error messages. BTW, `from turtle import *` is poor practice that will probably lead to errors, since you're polluting the global namespace with 150+ functions, and it [creates confusion](https://stackoverflow.com/a/62296811/6243352) about whether those functions are invoking the pre-created internal single instance turtle or a user-created turtle. I always avoid the internal singleton/functional interface. – ggorlen Jul 12 '23 at 16:46
  • I used the "import *" mechanism to reduce the typing of and explanation to the 11 year-old I was showing turtle to. You are absolutely right about avoiding "import *". I've lately gone further and been doing such "import tkinter as tk" followed by tk.Canvas, instead of "from tkinter import Canvas" followed by Canvas so that my package usages show up more readily. – crs Jul 12 '23 at 16:59
  • Yes, that seems to be the usecase for the glob import, but you may have to pay back the savings later. You'd have to prefix every call with `t.` and have a one-time `t = Turtle()` otherwise, two extra characters per command. – ggorlen Jul 12 '23 at 17:10
  • I do like the use of explicit module (or module abbreviation).member which helps me to recognize module usage especially when the member names can be very common words. For example I've often wanted to use "color" for a variable name but couldn't when "from turtle import *" would cause that to hide the turtle.color member. – crs Jul 13 '23 at 16:31

0 Answers0