All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Demo.awt.Colors.py Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
"""\
Create a panel showing all of the colors defined in the pawt.colors module
Display the names of bright colors in black and of dark colors in white
"""

from java import awt
from pawt import colors, test
from math import sqrt

p = awt.Panel()
for name in dir(colors):
    color = getattr(colors, name)
    if isinstance(color, awt.Color):
        l = awt.Label(name, awt.Label.CENTER, background=color)
        intensity = sqrt(color.red**2 + color.green**2 + color.blue**2)/3
        if intensity < 90:
            l.foreground = colors.white
        p.add(l)

test(p, size=(700, 500))




© 2015 - 2024 Weber Informatics LLC | Privacy Policy