Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

How to tell # of tiles from displayio.TileGrid?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How to tell # of tiles from displayio.TileGrid?

by gallaugher on Sat Oct 17, 2020 2:43 pm

Still pretty new to python & am trying to figure out: displayio.TileGrid. It seems this call takes a bmp & chops it up into pieces. I'm making the call using the code below. How can I tell how many "pieces" are in the image_grid?
image_grid = displayio.TileGrid(image_bit, pixel_shader=image_pal,
width=1, height=1,
tile_height=32, tile_width=32,
default_tile=0,
x=0, y=0)
I've tried len(image_grid)
I see the readthedocs at: https://circuitpython.readthedocs.io/en ... eGrid.html, but don't see any obvious property I can interrogate to find out how many images in the grid were created. Getting this would prevent me from hard-coding the # of images.
Since I'll always use 32 x 32 on this device, I figured I'd just drop in new files with the same name + since displayio.TileGrid can figure out how many tiles to create, I figured I could access this value instead of having to hard code (and change) the index value that image_grid iterates through & resets when cycling back to image_grid[0].

I'm working off a modified version of Liz's party parrot code & have it here - but I think everything I need is in the snippet above:
https://github.com/gallaugher/swift-sig ... in/code.py
Thanks!

gallaugher
 
Posts: 176
Joined: Tue Aug 14, 2018 12:42 pm

Re: How to tell # of tiles from displayio.TileGrid?

by gallaugher on Sun Oct 18, 2020 12:37 pm

Figured out an answer for anyone else looking for this.

Code that I originally worked with didn't require a separate call to displayio.OnDiskBitmap(open since image was being loaded by displayio.TileGrid, using displayio.OnDiskBitmap(open created a bitmap object that has a .height and .width value, so I could use this to determine how many images were in a horizontal sprite.

Repo with working code is at:
https://github.com/gallaugher/swift-sig ... in/code.py

gallaugher
 
Posts: 176
Joined: Tue Aug 14, 2018 12:42 pm

Please be positive and constructive with your questions and comments.