Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding HEX support for set_pixel #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wetnun
Copy link

@wetnun wetnun commented Dec 29, 2020

per #130

Copy link
Member

@Gadgetoid Gadgetoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - I'm a little late on the update here, but in the event you have the time/inclination to bash the rough edges off I've pointed out a couple of changes.

g = int("0x"+hexstr[3:5], 16)
b = int("0x"+hexstr[5:], 16)

return (r, g, b, )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sufficient to just return r, g, b which implicitly returns a tuple.

:param hexstr: Hex string like FFB4C0
"""

r = int("0x"+hexstr[0:2], 16)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int(hexstr[0:2], 16) should work here, the 0x is ignored. eg:

>>> int("ff", 16)
255
>>> int("f", 16)
15
>>> int("01", 16)
1
>>> 

Might want to look at handling other cases like "#FFFFFF", "FFF" and "#FFF" but this is a start at least.

In hindsight set_pixel(0xFF, 0xFF, 0xFF) is quite a lot less trouble 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants