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

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

Introduction

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

Prototype

public Color lerp(final Color target, final float t) 

Source Link

Document

Linearly interpolates between this color and the target color by t which is in the range [0,1].

Usage

From source file:com.github.skittishSloth.openSkies.maps.terrains.TerrainTile.java

private static Color buildInterpolatedElevationColor(final float elevVal, final Elevation elevation) {
    final int elevationOrd = elevation.ordinal();
    final Elevation[] elevations = Elevation.values();
    final int numElevations = elevations.length;

    final Color prevColor;
    if (elevationOrd == 0) {
        prevColor = null;// w  ww . j  a v  a2  s. com
    } else {
        prevColor = elevations[elevationOrd - 1].getColor();
    }

    final Color nextColor;
    if (elevationOrd == (numElevations - 1)) {
        nextColor = null;
    } else {
        nextColor = elevations[elevationOrd + 1].getColor();
    }

    final Color baseColor = elevation.getColor().cpy();
    final Color target;
    final float diff;
    if (elevVal < 0.5f) {
        diff = 1.0f - (2 * elevVal);
        if (prevColor != null) {
            target = prevColor;
        } else {
            target = Color.BLACK;
        }
    } else {
        diff = elevVal;
        if (nextColor != null) {
            target = nextColor;
        } else {
            target = Color.WHITE;
        }
    }

    baseColor.lerp(target, diff);

    return baseColor;
}

From source file:com.quadbits.gdxhelper.controllers.TimePeriodTintController.java

License:Apache License

@Override
public void control(Actor actor, float deltaSeconds) {
    if (crossFading) {
        float deltaColorCrossBlend = deltaSeconds / fadeAnimDurationSeconds;
        colorCrossBlend += (targetColorCrossBlend == 1) ? deltaColorCrossBlend : -deltaColorCrossBlend;

        if (colorCrossBlend <= 0) {
            colorCrossBlend = 0;/*w ww . jav  a 2s .c om*/
            crossFading = false;
        }

        if (colorCrossBlend >= 1) {
            colorCrossBlend = 1;
            crossFading = false;
        }
    }

    float blend = membershipFunction.evaluate(timeManager);
    //if (blend == 0) {
    //    return;
    //}

    tmpColor.set(colors.get(primaryColorIndex));
    if (colorCrossBlend != 0 && secondaryColorIndex >= 0) {
        tmpColor.lerp(colors.get(secondaryColorIndex), colorCrossBlend);
    }

    Color actorColor = actor.getColor();
    actorColor.set(1, 1, 1, actorColor.a);
    actorColor.lerp(tmpColor, blend);
    actor.setColor(actorColor);
}

From source file:com.quadbits.gdxhelper.controllers.TintAtNightController.java

License:Apache License

@Override
public void control(Actor actor, float deltaSeconds) {
    float blend;//ww w.  j a v  a2  s. c  o  m
    switch (timeManager.getPeriod()) {
    case PRE_MIDNIGHT:
    case POST_MIDNIGHT:
        blend = 1;
        break;

    case TWILIGHT_POST_SUNSET:
        blend = timeManager.getTPeriod();
        break;

    case TWILIGHT_PRE_SUNRISE:
        blend = 1 - timeManager.getTPeriod();
        break;

    default:
        blend = 0;
    }

    Color actorColor = actor.getColor();
    actorColor.set(1, 1, 1, actorColor.a);
    actorColor.lerp(nightColor, blend);
    actor.setColor(actorColor);
}