adafruit_display_shapes.polygon: arguments "colors" and/or "close" result in error messages

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
eddtrettel
 
Posts: 19
Joined: Thu Apr 04, 2019 12:22 am

adafruit_display_shapes.polygon: arguments "colors" and/or "close" result in error messages

Post by eddtrettel »

Hi,

I'm running "Adafruit CircuitPython 8.0.0-beta.6-28-g6013cde6a on 2023-01-05; Adafruit Matrix Portal M4 with samd51j19".

I've successfully used every argument in every shape in the adafruit_display_shapes library, with the exception of "colors" and "close" in Polygon.

When I try to use those I get a:

Traceback (most recent call last):
File "code.py", line 65, in <module>
TypeError: unexpected keyword argument 'close'

Same for "color".

Below is a sample case I made to demonstrate the issue. It gets interpreted (and generates a shape on the LED matrix) for those instances that exclude used "color" and "close".

I've read the doc and these are shown as optional parameters there.

I've also read the source code for polygon on github and in the preamble these also appear to be optional.

I've done a binary compare of the polygon.mpy on the Matrix Portal with the same file in the 8.0.0 beta library and they are identical, so it's not a case of the one on the Matrix Portal being out-of-sync.

Any help that can be given would be appreciated. Here's my sample code. If you can get "colors" and "close" to work, please let me know how. Thanks.

Code: Select all

from gc import enable, collect, mem_free
from time import monotonic, sleep
from displayio import release_displays, Bitmap, Palette, TileGrid, Group
from terminalio import FONT
from random import randint, uniform
from adafruit_matrixportal.matrix import Matrix
from adafruit_display_shapes.polygon import Polygon
enable()
release_displays()
matrix = Matrix(width=64, height=32, bit_depth=4)
bitmap = Bitmap(64, 32, 16)
palette = Palette(16)
tile_grid = TileGrid(bitmap, pixel_shader=palette)
group = Group()
matrix.display.show(group)
color_dict = dict(
    black=0x000000,
    blue=0x0000FF,
    coral=0xFF4040,
    cyan=0x00FFFF,
    green=0x004000,
    grey=0x404040,
    lime=0x00FF00,
    magenta=0xFF00FF,
    maroon=0x400000,
    navy=0x000040,
    olive=0x404000,
    purple=0x400040,
    red=0xFF0000,
    teal=0x004040,
    white=0xFFFFFF,
    yellow=0xFFFF00,
)
palette[0] = color_dict["black"]
palette[1] = color_dict["white"]
palette[2] = color_dict["red"]
palette[3] = color_dict["lime"]
palette[4] = color_dict["blue"]
palette[5] = color_dict["yellow"]
palette[6] = color_dict["cyan"]
palette[7] = color_dict["magenta"]
palette[8] = color_dict["coral"]
palette[9] = color_dict["grey"]
palette[10] = color_dict["maroon"]
palette[11] = color_dict["green"]
palette[12] = color_dict["navy"]
palette[13] = color_dict["olive"]
palette[14] = color_dict["teal"]
palette[15] = color_dict["purple"]
while True:
    outlinex = palette[randint(1, 15)]
    v1 = (randint(0, 63), randint(0, 31))
    v2 = (randint(0, 63), randint(0, 31))
    v3 = (randint(0, 63), randint(0, 31))
    v4 = (randint(0, 63), randint(0, 31))
    listx = [v1, v2, v3, v4]
    polygon = Polygon([v1, v2, v3, v4], outline=outlinex)
    group.append(polygon)
    polygon = Polygon(points=listx, outline=outlinex)
    group.append(polygon)
    polygon = Polygon([v1, v2, v3, v4])
    group.append(polygon)
    polygon = Polygon(points=listx)
    group.append(polygon)
    polygon = Polygon([v1, v2, v3, v4], outline=outlinex, close=True,colors=1)
    group.append(polygon)
    input("post append")
Attachments
code.py
here's the code, with tabs for indent
(2.09 KiB) Downloaded 2 times
Last edited by dastels on Fri Jan 27, 2023 5:39 pm, edited 1 time in total.
Reason: Add code tags

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: adafruit_display_shapes.polygon: arguments "colors" and/or "close" result in error messages

Post by dastels »

Make sure you have the latest version of the display shapes library (and all of them for that matter).

Dave

User avatar
eddtrettel
 
Posts: 19
Joined: Thu Apr 04, 2019 12:22 am

Re: adafruit_display_shapes.polygon: arguments "colors" and/or "close" result in error messages

Post by eddtrettel »

Thank you, dastels! I upgraded the library from the 2023 01 05 version to the 2023 01 27 version and can now use the "colors" and "close" parameters.

Now I'm stymied in how to get it to fill the polygon. In the documentation at https://docs.circuitpython.org/projects ... ml#polygon in the "colors" parameter it makes reference to filling the polygon, but doesn't say how to do this.

I've tried setting "colors" to 1,2,3,4,5,6,7,8,9 and it has no effect. I had "close" set to True to make it draw a closed shape and not an open one.

Perhaps this was never implemented as a feature. The other shapes (circle, square, etc) all have "fill" as an exclicitly named option.

Thanks again for your help.

Best regards,
E.T.

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: adafruit_display_shapes.polygon: arguments "colors" and/or "close" result in error messages

Post by dastels »

As you see, close & colors were just recently added to Polygon, so it may be a work in progress.

Dave

User avatar
eddtrettel
 
Posts: 19
Joined: Thu Apr 04, 2019 12:22 am

Re: adafruit_display_shapes.polygon: arguments "colors" and/or "close" result in error messages

Post by eddtrettel »

Thank you again for the insight into this. I'll hold off until other parameters are added, if ever.

I have to tip my hat to the folks who coded the "shapes" library. It's remarkable.

We can consider this item closed.

Best regards,
E.T.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”