Skip to content

Instantly share code, notes, and snippets.

class ColorDict(object):
"""Provides a color for each key, trying to create as distinct a set
of colors as possible.
"""
# Minimum difference in hue between unique colors, before we begin
# to recycle old colors rather than generating new ones.
THRESHOLD = 0.05
def __init__(self):
// Modify contrast using a ColorMatrix (on Android)
ColorMatrixColorFilter setContrast(float contrast) {
float scale = contrast + 1.f;
float translate = (-.5f * scale + .5f) * 255.f;
float[] array = new float[] {
scale, 0, 0, 0, translate,
0, scale, 0, 0, translate,
0, 0, scale, 0, translate,
0, 0, 0, 1, 0};
ColorMatrix matrix = new ColorMatrix(array);