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

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

Introduction

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

Prototype

public Color add(Color color) 

Source Link

Document

Adds the given color to this color.

Usage

From source file:com.lyeeedar.Roguelike3D.Graphics.Lights.LightManager.java

License:Open Source License

public Color calculateLightAtPoint(Vector3 position, Vector3 normal, boolean bakeStatics) {
    Color h_ambient = ambientLight.cpy().mul(0.5f);
    Color light_agg_col = h_ambient.add(calculateLight(ambientDir, h_ambient.cpy(), 0, 1, normal));

    if (!bakeStatics)
        return light_agg_col;

    for (PointLight pl : staticPointLights) {
        Vector3 l_vector = pl.position.cpy().sub(position);

        light_agg_col.add(calculateLight(l_vector, pl.getColour().cpy(), pl.attenuation, pl.power, normal));

    }//from   w  w w.  j a v  a  2  s . c o  m
    return light_agg_col;
}

From source file:de.bioviz.ui.DrawableDroplet.java

License:Open Source License

/**
 * Computes the droplet's color./* w  w w .  j a va2 s  .  c  o  m*/
 *
 * @return The color used to display the droplet
 */
public Color getDisplayColor() {

    Color color = this.dropletColor.cpy();

    Net net = droplet.getNet();
    if (net != null && parentAssay.getDisplayOptions().getOption(BDisplayOptions.NetColorOnDroplets)) {
        color = net.getColor().buildGdxColor();
    }

    Rectangle pos = droplet.getPositionAt(parentAssay.getCurrentTime());

    if (pos != null) {
        Point p = pos.upperLeft();

        // if the droplet is currently not present, make it 'invisible' by
        // making it totally transparent
        if (p == null) {
            color.sub(Color.BLACK).clamp();

        } else {
            if (this.isHidden()) {
                color.a = 0.25f;
            } else {
                color.add(Color.BLACK).clamp();
            }
        }
    } else {
        color.sub(Color.BLACK).clamp();
    }

    return color;
}

From source file:de.bioviz.ui.DrawableField.java

License:Open Source License

/**
 * Computes the cell coloring based on the usage.
 *
 * @param result/* w  w w  .  j  ava  2s  .  co m*/
 *       The color that is to be adjusted by this method.
 * @return 1 if cell usage was used, 0 otherwise
 */
private int cellUsageColoring(final de.bioviz.ui.Color result) {
    if (getOption(CellUsage)) {
        float scalingFactor = this.parentAssay.getData().getMaxUsage();
        int usage = field.getUsage();
        float color = usage / scalingFactor;
        result.add(new Color(color, color, color, 0));
        return 1;
    }
    return 0;
}

From source file:de.bioviz.ui.DrawableField.java

License:Open Source License

/**
 * Decorates cells that are on the corners of a net bounding box.
 *///  ww w.j  av  a  2 s.c  om
private void netColoring() {
    /**
     * The NetColorOnFields display option is a little special and thus
     * gets quite some amount of code here.
     * The idea is that we use the sprite's corner vertices and colorize
     * them separately *if* they are part of a net's edge. At first, these
     * colors are stored in the cornerColors array. When drawing, this
     * array is checked for existence and if it isn't null, each none-black
     * color *completely overrides* the given field color at this corner.
     */
    if (getOption(NetColorOnFields)) {
        if (cornerColors == null) {
            cornerColors = new Color[4]; // one color for each corner
        }

        final int bottomleft = 0;
        final int topleft = 1;
        final int topright = 2;
        final int bottomright = 3;

        for (int i = 0; i < cornerColors.length; i++) {
            // Create non-null array contents
            cornerColors[i] = Color.BLACK.cpy();
        }
        for (final Net net : this.getParentAssay().getData().getNetsOf(this.getField())) {
            de.bioviz.ui.Color netCol = net.getColor().cpy();

            // Increase brightness for hovered nets
            if (this.parentAssay.getHoveredField() != null && this.getParentAssay().getData()
                    .getNetsOf(this.getParentAssay().getHoveredField().field).contains(net)) {
                netCol.add(Colors.HOVER_NET_DIFF_COLOR);

            }
            Point top = new Point(field.x(), field.y() + 1);
            Point bottom = new Point(field.x(), field.y() - 1);
            Point left = new Point(field.x() - 1, field.y());
            Point right = new Point(field.x() + 1, field.y());

            Color color = netCol.buildGdxColor();

            Biochip parent = getParentAssay().getData();

            boolean fieldAtTop = parent.hasFieldAt(top);
            boolean fieldAtBottom = parent.hasFieldAt(bottom);
            boolean fieldAtLeft = parent.hasFieldAt(left);
            boolean fieldAtRight = parent.hasFieldAt(right);

            boolean containsTop = fieldAtTop && net.containsField(parent.getFieldAt(top));
            boolean containsBottom = fieldAtBottom && net.containsField(parent.getFieldAt(bottom));
            boolean containsLeft = fieldAtLeft && net.containsField(parent.getFieldAt(left));
            boolean containsRight = fieldAtRight && net.containsField(parent.getFieldAt(right));

            if (!fieldAtTop || !containsTop) {
                this.cornerColors[topleft].add(color);
                this.cornerColors[topright].add(color);
            }
            if (!fieldAtBottom || !containsBottom) {
                this.cornerColors[bottomleft].add(color);
                this.cornerColors[bottomright].add(color);
            }
            if (!fieldAtLeft || !containsLeft) {
                this.cornerColors[bottomleft].add(color);
                this.cornerColors[topleft].add(color);
            }
            if (!fieldAtRight || !containsRight) {
                this.cornerColors[topright].add(color);
                this.cornerColors[bottomright].add(color);
            }
        }
        for (int i = 0; i < cornerColors.length; i++) {
            if (cornerColors[i].equals(Color.BLACK)) {
                cornerColors[i] = super.getColor();
            }
        }
    } else {
        cornerColors = null;
    }
}

From source file:de.bioviz.ui.DrawableField.java

License:Open Source License

/**
 * Calculates the current color based on the parent circuit's
 * displayOptions./*  w  w  w.  java  2  s . c o  m*/
 *
 * @return the field's color.
 */
@Override
public Color getColor() {

    /**
     * This value stores the amount of colors being overlaid in the process
     * of computing the color. This is currently required to calculate the
     * average value of all colors at the end of the process (e.g. if three
     * different colors are being added, the final result needs to be
     * divided by three).
     */
    int colorOverlayCount = 0;

    /*
    We need to create a copy of the FIELD_EMPTY_COLOR as that value is
    final and thus can not be modified.
    If that value is unchangeable, the cells all stay white
     */
    de.bioviz.ui.Color result = new de.bioviz.ui.Color(Color.BLACK);

    if (getField().isBlocked(getParentAssay().getCurrentTime())) {
        result.add(Colors.BLOCKED_COLOR);
        colorOverlayCount++;
    }

    netColoring();

    colorOverlayCount += cellUsageColoring(result);

    colorOverlayCount += inteferenceRegionColoring(result);

    colorOverlayCount += reachableRegionColoring(result);

    /**
     * Here we highlight cells based on their actuation value
     */
    int t = getParentAssay().getCurrentTime();
    if (getOption(Actuations)) {
        Actuation act = field.getActuation(t);

        switch (act) {
        case ON:
            result.add(Colors.ACTUATION_ON_COLOR);
            break;
        case OFF:
            result.add(Colors.ACTUATION_OFF_COLOR);
            break;
        case DONTCARE:
        default:
            result.add(Colors.ACTUATION_DONTCARE_COLOR);
        }
        ++colorOverlayCount;
    }

    if (colorOverlayCount == 0) {
        colorOverlayCount += typeColoring(result, t);
    }

    if (getOption(Adjacency)) {
        final Stream<FluidicConstraintViolation> violations = getParentAssay().getData()
                .getAdjacentActivations().stream();

        if (violations.anyMatch(v -> v.containsField(this.field))) {
            result.add(Colors.ADJACENT_ACTIVATION_COLOR);
        }
    }

    if (colorOverlayCount > 0) {
        result.mul(1f / ((float) colorOverlayCount));
        result.clamp();
    } else {
        result = new de.bioviz.ui.Color(Colors.FIELD_COLOR);
    }

    if (this.isHovered()) {
        result.add(Colors.HOVER_DIFF_COLOR);
    }

    if (getOption(HighlightAnnotatedFields) && field.hasAnnotations()) {
        result = new de.bioviz.ui.Color(Color.VIOLET);
    }

    return result.buildGdxColor().cpy();
}

From source file:de.bioviz.ui.DrawableField.java

License:Open Source License

/**
 * Computes the color based on the type of the field.
 *
 * @param result/*from ww w  .j av a  2  s  . com*/
 *       The resulting color.
 * @param timeStep
 *       The current time step.
 * @return The amount of new color overlays.
 */
private int typeColoring(final de.bioviz.ui.Color result, final int timeStep) {

    int colorOverlayCount = 0;
    if (field instanceof Sink) {
        result.add(Colors.SINK_COLOR);
        colorOverlayCount++;
    } else if (field instanceof Dispenser) {
        result.add(Colors.SOURCE_COLOR);
        colorOverlayCount++;
    } else {
        result.add(Colors.FIELD_COLOR);
        colorOverlayCount++;
    }

    for (final Mixer m : field.mixers) {
        if (m.timing.inRange(timeStep)) {
            result.add(Colors.MIXER_COLOR);
        }
    }
    return colorOverlayCount;
}

From source file:de.bioviz.ui.DrawableField.java

License:Open Source License

/**
 * Colors the field based on reachability by droplets.
 *
 * @param result Return parameter storing the color that is computed after
 *               applying the reachability check.
 * @return 1 if the field can be reached within one time step by any
 * droplet, 0 otherwise./*w  ww  .  j  a  v  a 2  s .c om*/
 */
private int reachableRegionColoring(final de.bioviz.ui.Color result) {
    int colorOverlayCount = 0;
    if (getOption(MovementNeighbourhood)) {

        int t = getParentAssay().getCurrentTime();

        final Set<Droplet> dropsSet = getParentAssay().getData().getDroplets();
        boolean fieldIsReachable = dropsSet.stream().map(d -> d.getPositionAt(t)).filter(Objects::nonNull)
                .anyMatch(p -> p.reachable(field.pos));
        if (fieldIsReachable) {
            result.add(Colors.REACHABLE_FIELD_COLOR);
            colorOverlayCount = 1;
        }
    }

    return colorOverlayCount;
}

From source file:de.bioviz.ui.DrawableField.java

License:Open Source License

/**
 * Colors based on the interference region.
 *
 * @param result// w ww.j av  a2  s . c o  m
 *       The color that results from this method call.
 * @return The amount of color overlays produced by this method.
 */
private int inteferenceRegionColoring(final de.bioviz.ui.Color result) {
    int colorOverlayCount = 0;

    boolean isBlocked = getField().isBlocked(getParentAssay().getCurrentTime());

    /** Colours the interference region **/
    if (getOption(InterferenceRegion)) {
        int amountOfInterferenceRegions = 0;
        final Set<Droplet> dropsSet = getParentAssay().getData().getDroplets();

        ArrayList<Droplet> drops = dropsSet.stream().filter(d -> isPartOfInterferenceRegion(d))
                .collect(Collectors.toCollection(ArrayList<Droplet>::new));

        for (int i = 0; i < drops.size(); ++i) {
            boolean interferenceViolation = false;
            for (int j = i + 1; j < drops.size(); j++) {
                final Droplet drop1 = drops.get(i);
                final Droplet drop2 = drops.get(j);
                boolean sameNet = getParentAssay().getData().sameNet(drop1, drop2);
                if (!sameNet && !isBlocked) {
                    result.add(Colors.INTERFERENCE_REGION_OVERLAP_COLOR);
                    ++colorOverlayCount;
                    interferenceViolation = true;
                }
            }

            /*
            We only increase the amount of interference regions if no
            violation took place. This makes sense as a violation is
            handled
            differently.
             */
            if (!interferenceViolation) {
                ++amountOfInterferenceRegions;
            }
        }

        if (amountOfInterferenceRegions > 0 && !isBlocked) {
            float scale = (float) Math.sqrt(amountOfInterferenceRegions);
            Color c = new Color(Colors.INTERFERENCE_REGION_COLOR);
            result.add(c.mul(scale));
            ++colorOverlayCount;
        }

    }
    return colorOverlayCount;
}