apppublic/appPublic/set_fgcolor.py
2022-06-09 12:37:58 +08:00

24 lines
519 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#
"""
kivy color:
[ r, g, b, a]
不同的颜色值总能找到一个人眼感知的灰度值,这是著名的心理学公式:
灰度 = 红×0.299 + 绿×0.587 + 蓝×0.114
"""
当灰度值大于0.5时使用暗色否则使用明色
def get_fgcolor_from_bgcolor(bgcolor):
dark_fgcolor=[0.11,0.11,0.11,1]
bright_fgcolor=[0.89,0.89,0.89,1]
graylevel = 0.299 * bgcolor[0] + \
0.587 * bgcolor[1] + \
0.114 * bgcolor[2]
if graylevel > 0.5:
return dark_fgcolor
else:
return bright_fgcolor