numworks / epsilon

Modern graphing calculator operating system.
https://www.numworks.com/resources/engineering/software/
1.75k stars 463 forks source link

In the module turtle, color() doesn't change the color of write() #2223

Open mobluse opened 2 months ago

mobluse commented 2 months ago

Describe the bug

In the module turtle, color() doesn't change the color of write(). E.g.

from turtle import *
color("blue")
write("Hello, world.")

types text in black.

Screenshots

The same program running on Numworks and in Python3 in Linux: download-planet 2024-08-26-120405_422x334_scrot

To Reproduce

Steps to reproduce the behavior:

  1. Try the script on https://my.numworks.com/python/mobluse/planet
  2. See that in Numworks the text is black; not blue.

Expected behavior

The text written using write() should have the same color as lines drawn using the turtle.

Environment

Idaill commented 2 months ago

Im gonna answer you : color("blue") doesn't choose the color blue, it just return a value, here if you do print(color("blue")) it will return (0,0,255) . If you want to change the color, well just use kandinsky library, it's easier and faster, if you want to write a text using this, do draw_string("text",x,y,color_background_of_text,color_text) . Have a nice day !

Idaill commented 2 months ago

color("blue") does not affect write but affect the color of lines, i think this is not a bug and this is just that they dont think of adding this possibility .

EmilieNumworks commented 2 months ago

It's indeed a feature and not a bug but we can consider adding the feature though @adri1numworks.

mobluse commented 1 month ago

Im gonna answer you : color("blue") doesn't choose the color blue, it just return a value, here if you do print(color("blue")) it will return (0,0,255) . If you want to change the color, well just use kandinsky library, it's easier and faster, if you want to write a text using this, do draw_string("text",x,y,color_background_of_text,color_text) . Have a nice day !

I believe you mix up color() in turtle with color() in kandinsky. color() in kandinsky is a constructor and works as you write, but color() in turtle is a method that changes the color of what the (default) turtle draws, and that should include text, since that is how turtle in CPython (standard Python for computers) works. If turtle in NumWorks doesn't work as turtle in CPython, it is more difficult to port programs from NumWorks to CPython. download (2)

mobluse commented 1 month ago

I've noticed that NumWorks' turtle also has pencolor() (undocumented in NumWorks' manual) that also doesn't change the write() color, but in CPython pencolor() like color() changes the write() color. color() in CPython changes both pencolor and fillcolor, but NumWorks doesn't have begin_fill() and end_fill().

adri1numworks commented 1 month ago

Thanks for your comments. An issue was created internally to make NumWorks Python correspond to CPython regarding turtle.color()

mobluse commented 4 weeks ago

There is another issue with turtle.color(): When you run it without arguments in CPython it returns two colors; one for pencolor and one for fillcolor, but in NumWorks it only returns one color. I think turtle.color() should return two colors in a tuple just to be compatible with CPython even though fillcolor is not supported, since filling is not supported. You could have a fake fillcolor that is always the same as the pencolor. screenshot (1)

Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle as t
>>> t.color()
('black', 'black')
>>> t.pencolor()
'black'
>>> t.fillcolor()
'black'
>>>