List of usage examples for com.badlogic.gdx.graphics Color clamp
public Color clamp()
From source file:com.cyphercove.lwptools.core.ColorUtil.java
License:Apache License
public static Color mulRgbOnly(Color color, float scale) { color.r *= scale;/*w w w .j a va 2 s.c om*/ color.g *= scale; color.b *= scale; color.clamp(); return color; }
From source file:de.bioviz.ui.DrawableField.java
License:Open Source License
/** * Calculates the current color based on the parent circuit's * displayOptions.//w ww.j a va 2s .co 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:mobi.shad.s3lib.gfx.util.GradientUtil.java
License:Apache License
/** * @param colorTop//w ww . ja v a 2 s . co m * @param colorBottom * @param ratio * @return */ public static Color linearGradientColor(Color colorTop, Color colorBottom, float ratio) { Color color = new Color(); color.r = (float) (colorBottom.r * ratio + colorTop.r * (1 - ratio)); color.g = (float) (colorBottom.g * ratio + colorTop.g * (1 - ratio)); color.b = (float) (colorBottom.b * ratio + colorTop.b * (1 - ratio)); color.a = 1.0f; color.clamp(); return color; }
From source file:org.illarion.engine.backend.gdx.GdxGraphics.java
License:Open Source License
/** * Transfer the color values from a game engine color instance to a libGDX color instance. * * @param source the engine color instance that is the source of the color data * @param target the libGDX color instance that is the target of the color data *///w ww . jav a 2 s. c om static void transferColor(@Nonnull final Color source, @Nonnull final com.badlogic.gdx.graphics.Color target) { target.set(source.getRedf(), source.getGreenf(), source.getBluef(), source.getAlphaf()); target.clamp(); }