Example usage for com.badlogic.gdx.graphics Color set

List of usage examples for com.badlogic.gdx.graphics Color set

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Color set.

Prototype

public Color set(int rgba) 

Source Link

Document

Sets this color's component values through an integer representation.

Usage

From source file:com.cyphercove.lwptools.core.ColorUtil.java

License:Apache License

/** Amount is how far to shift hue (normalized across colors from 0 to 1). Returns the modified input color.*/
public static Color shiftHue(Color color, float amount) {
    float[] hsv = new float[3];
    androidIntToHSV(toAndroidInt(color), hsv);
    hsv[0] += amount * 360;//from   ww w  .j ava 2  s. co m
    while (hsv[0] < 0)
        hsv[0] += 360;
    while (hsv[0] >= 360)
        hsv[0] -= 360;
    return color.set(fromAndroidInt(hsvToAndroidInt(hsv)));
}

From source file:com.cyphercove.lwptools.core.ColorUtil.java

License:Apache License

/** Returns the modified input color.*/
public static Color scaleSaturation(Color color, float scale) {
    float[] hsv = new float[3];
    androidIntToHSV(toAndroidInt(color), hsv);
    hsv[1] *= scale;/*from  ww w  .  j a  v a  2 s.co m*/
    hsv[1] = Math.min(hsv[1], 1);
    //Unnecessary. hsv[1] = MathUtils.clamp(hsv[1], 0, 1f);
    return color.set(fromAndroidInt(hsvToAndroidInt(hsv)));
}

From source file:com.cyphercove.lwptools.core.ColorUtil.java

License:Apache License

/** Returns the modified input color.*/
public static Color maximizeSaturation(Color color) {
    float[] hsv = new float[3];
    androidIntToHSV(toAndroidInt(color), hsv);
    hsv[1] = 1f;/*  w w  w  . j av a 2s .  c o  m*/
    return color.set(fromAndroidInt(hsvToAndroidInt(hsv)));
}

From source file:com.cyphercove.lwptools.core.ColorUtil.java

License:Apache License

/** Returns the modified input color.*/
public static Color maximizeBrightness(Color color) {
    float[] hsv = new float[3];
    androidIntToHSV(toAndroidInt(color), hsv);
    hsv[2] = 1f;/*  ww  w.j a  v a  2  s . c o m*/
    return color.set(fromAndroidInt(hsvToAndroidInt(hsv)));
}

From source file:com.cyphercove.lwptools.core.ColorUtil.java

License:Apache License

/** Returns the modified input color.*/
public static Color scaleValue(Color color, float scale) {
    float[] hsv = new float[3];
    androidIntToHSV(toAndroidInt(color), hsv);
    hsv[2] *= scale;/*w w  w  .  jav a 2  s.  c om*/
    hsv[2] = MathUtils.clamp(hsv[2], 0, 1f); //necessary to prevent hue shifts
    return color.set(fromAndroidInt(hsvToAndroidInt(hsv)));
}

From source file:com.ray3k.skincomposer.utils.Utils.java

License:Open Source License

/**
 * Does not dispose pixmap./*from w ww .  j a v  a 2 s  .c  o m*/
 * @param pixmap
 * @return 
 */
public static Color averageColor(Pixmap pixmap) {
    Color temp = new Color();
    float sumR = 0.0f;
    float sumG = 0.0f;
    float sumB = 0.0f;
    int count = 0;
    for (int y = 0; y < pixmap.getHeight(); y++) {
        for (int x = 0; x < pixmap.getWidth(); x++) {
            temp.set(pixmap.getPixel(x, y));
            if (temp.a > 0) {
                sumR += temp.r;
                sumG += temp.g;
                sumB += temp.b;
                count++;
            }
        }
    }

    if (count == 0) {
        return new Color(Color.BLACK);
    } else {
        return new Color(sumR / count, sumG / count, sumB / count, 1.0f);
    }
}

From source file:com.ray3k.skincomposer.utils.Utils.java

License:Open Source License

/**
 * Does not dispose pixmap/*  w  w w .j  a  v  a  2  s.  c  o m*/
 * @param pixmap
 * @return 
 */
public static Pixmap tintPixmap(Pixmap pixmap, Color color) {
    Color tempColor = new Color();
    for (int y = 0; y < pixmap.getHeight(); y++) {
        for (int x = 0; x < pixmap.getWidth(); x++) {
            tempColor.set(pixmap.getPixel(x, y));
            float a = tempColor.a;
            tempColor.mul(color);
            tempColor.a = a;
            pixmap.setColor(tempColor);
            pixmap.drawPixel(x, y);
            tempColor.set(pixmap.getPixel(x, y));
        }
    }
    return pixmap;
}

From source file:com.ray3k.skincomposer.utils.Utils.java

License:Open Source License

/**
 * Does not dispose pixmap./*from  w w  w  .  j a  v  a 2 s .co  m*/
 * @param pixmap
 * @param ninePatch
 * @return 
 */
public static Color averageEdgeColor(Pixmap pixmap, boolean ninePatch) {
    int border = 0;
    if (ninePatch) {
        border = 1;
    }

    Color temp = new Color();
    float sumR = 0.0f;
    float sumG = 0.0f;
    float sumB = 0.0f;
    int count = 0;

    //left edge
    for (int y = border; y < pixmap.getHeight() - border; y++) {
        for (int x = border; x < pixmap.getWidth() - border; x++) {
            temp.set(pixmap.getPixel(x, y));
            if (temp.a > 0) {
                sumR += temp.r;
                sumG += temp.g;
                sumB += temp.b;
                count++;
                break;
            }
        }
    }

    //right edge
    for (int y = border; y < pixmap.getHeight() - border; y++) {
        for (int x = pixmap.getWidth() - 1 - border; x > border; x--) {
            temp.set(pixmap.getPixel(x, y));
            if (temp.a > 0) {
                sumR += temp.r;
                sumG += temp.g;
                sumB += temp.b;
                count++;
                break;
            }
        }
    }

    //top edge
    for (int x = border; x < pixmap.getWidth() - border; x++) {
        for (int y = border; y < pixmap.getHeight() - border; y++) {
            temp.set(pixmap.getPixel(x, y));
            if (temp.a > 0) {
                sumR += temp.r;
                sumG += temp.g;
                sumB += temp.b;
                count++;
                break;
            }
        }
    }

    //bottom edge
    for (int x = border; x < pixmap.getWidth() - border; x++) {
        for (int y = pixmap.getHeight() - 1 - border; y > border; y--) {
            temp.set(pixmap.getPixel(x, y));
            if (temp.a > 0) {
                sumR += temp.r;
                sumG += temp.g;
                sumB += temp.b;
                count++;
                break;
            }
        }
    }

    if (count == 0) {
        return new Color(Color.BLACK);
    } else {
        return new Color(sumR / count, sumG / count, sumB / count, 1.0f);
    }
}

From source file:com.turbogerm.helljump.game.platforms.features.FlamePlatformFeature.java

License:Open Source License

@Override
public void applyModifier(PlatformModifier modifier) {
    Color color = modifier.spriteColor;
    float oldAplha = color.a;

    switch (mFlameStateMachine.getCurrentState()) {
    case FlameStateMachine.DORMANT:
        color.set(DORMANT_COLOR);
        break;//from  ww w .ja va 2 s.  c  o m

    case FlameStateMachine.TRANSITION1:
        color.set(mColorInterpolator.interpolateColor(DORMANT_COLOR, FLAME_COLOR,
                mFlameStateMachine.getStateElapsedFraction()));
        break;

    case FlameStateMachine.FLAME:
        color.set(FLAME_COLOR);
        break;

    case FlameStateMachine.TRANSITION2:
        color.set(mColorInterpolator.interpolateColor(FLAME_COLOR, DORMANT_COLOR,
                mFlameStateMachine.getStateElapsedFraction()));
        break;
    }

    color.a = oldAplha;
}

From source file:seventh.client.gfx.GdxCanvas.java

License:Open Source License

private void setColor(Color c, Integer color) {
    if (color != null) {
        int alpha = color >>> 24;
        color = (color << 8) | alpha;

        c.set(color);
    }/*from   w  ww. ja  v a2  s . c o m*/
}