I would like to propose an addition to the pew API and would like to hear your opinions on it: The ability to query the color capabilities of the current PewPew display.
Reason:
In Othello (https://github.com/pypewpew/game-othello/blob/master/othello.py), of the 3 non-black colors available on a traditional PewPew, I want to choose the most distinguishable two for the pieces of the two players. On a red-green PewPew, that is red and green. On a monochromatic 4-shade-of-brightness PewPew, that …
[View More]is "dim" and "bright". (The third color, orange or "medium", is used for the cursor when over a piece, which is additionally distinguished by blinking.) These colors are not encoded by the same numbers, so I need to know in which of the two cases I am. Currently (https://github.com/pypewpew/game-othello/blob/e7e93fa9844166f96441a7342d8b5…), I do that using `if 'PewPew 10.' in os.uname().machine:`. That works as long as the PewPew 10 is the only monochromatic PewPew. However, I will soon want to have it work on the Playdate, which is monochromatic as well. (`os.uname().machine` is currently `PewPew PD with STM32` there and I would rather not make it masquerade as a PewPew 10.)
Proposal:
It's hard to balance simplicity and usefulness. I'm not sure if the following is the right choice, but consider it a basis for discussion:
There is a new attribute `colordepth` of the `pew` module. Its value is a tuple giving the bit depth of all color channels:
- On a traditional red-green PewPew (e.g. PewPew Lite), it is `(1, 1)`: Two channels of one bit each.
- On a monochromatic 4-shade-of-brightness PewPew (PewPew 10), it is `(2,)`: One channel of two bits.
- On a PicoPew, which has a red-green LED matrix and can drive each LED with 256-level PWM, it is `(8, 8)`.
- On a PewPew with an RGB LCD (e.g. PewPew M4 and presumably PewPew LCD 5), once anyone actually implements the `palette()` API (https://picopew.readthedocs.io/en/latest/reference.html) for full color, it could be `(5, 6, 5)`.
My check in Othello would then become `if len(pew.colordepth) == 1:` (or, combined with a fallback for older PewPews that don't implement it yet, `if len(pew.colordepth) == 1 if hasattr(pew, 'colordepth') else 'PewPew 10.' in os.uname().machine:`).
This deliberately does not encode what the meaning of the color channels is. That's because 1. it might not be known (a monochromatic PewPew does not know what color of LED matrix you soldered on it) and 2. I see no reason for a game to want to know it. You can reasonably assume that 3 channels are RGB, and if 2 are red and green then red is first and green is second, but for all you know it might also be pink and blue if displays like that exist.
It also does not encode whether on a monochromatic display the numbers encode "brightness" (as on an LED matrix) or "darkness" (as on a black-on-light reflective LCD). Maybe someone would have a use for that?
On the Playdate and PicoPew I can obviously implement whatever I want, but it would be nice to have it standardized on all PewPews to make it easier to write games that run everywhere.
-Christian
[View Less]