UI: text_color animation
lachlantula last edited by lachlantula
I’m developing an application with the
uimodule, but have realised something that I’m not sure is either intentional or just overlooked;
background_colorcan be animated, whilst
Here’s an example. You can see that the text colour-changing is out of sync with the smooth background. The text changes to contrast with the background at the time.
Here is my code for the colour-changing functionality:
while True: r = lambda: random.randint(0, 255) colour = '%02X%02X%02X' % (r(), r(), r()) def determine_colour2(colour): (r, g, b) = (colour[:2], colour[2:4], colour[4:]) # This next bit is pretty complicated, but its basically just an algorithm to find out what colour is needed for text if 1 - (int(r, 16) * 0.299 + int(g, 16) * 0.587 + int(b, 16) * 0.114) / 255 < 0.5: return '333333' else: return 'efefef' colour2 = determine_colour2(colour) def animation(): v.background_color = colour v['chrome']['logo'].text_color = colour2 ui.animate(animation, duration = 3) time.sleep(3)
If anyone can let me know if I’m doing something wrong or if this functionality isn’t implemented into Pythonista at all, it would be appreciated. Thanks!