List of usage examples for com.badlogic.gdx.graphics Color set
public Color set(float r, float g, float b, float a)
From source file:com.andgate.ikou.utility.graphics.HSL.java
License:Open Source License
/** * Converts an HSL color value to RGB. Conversion formula * adapted from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes h, s, and l are contained in the set [0, 1] and * returns r, g, and b in the set [0, 1]. *///from w w w . j a va 2 s . c o m public void toRGBA(Color out) { float r, g, b; if (s == 0) { r = l; g = l; b = l; } else { float q = (l < 0.5f) ? (l * (1.0f + s)) : (l + s - l * s); float p = 2.0f * l - q; r = hue2rgb(p, q, h + 1.0f / 3.0f); g = hue2rgb(p, q, h); b = hue2rgb(p, q, h - 1.0f / 3.0f); } out.set(r, g, b, 1.0f); }
From source file:com.cyphercove.lwptools.core.ColorUtil.java
License:Apache License
public static Color invert(Color color) { color.set(1 - color.r, 1 - color.g, 1 - color.b, 1 - color.a); return color; }
From source file:com.cyphercove.lwptools.core.ColorUtil.java
License:Apache License
/**Sets the destination Color to an interpolation between the two source Colors. * @param interp Value between 0 and 1 corresponding to distance between src1 and src2.*/ public static Color setInterpolatedColor(Color dst, Color src1, Color src2, float interp) { invInterp = 1 - interp;//from w w w . j a v a 2s . c o m dst.set(src1.r * interp + src2.r * invInterp, src1.g * interp + src2.g * invInterp, src1.b * interp + src2.b * invInterp, src1.a * interp + src2.a * invInterp); return dst; }
From source file:com.cyphercove.lwptools.core.ColorUtil.java
License:Apache License
public static Color blendIntoFirst(Color one, Color two, float blend) { float inv = 1 - blend; one.set(inv * one.r + blend * two.r, inv * one.g + blend * two.g, inv * one.b + blend * two.b, inv * one.a + blend * two.a); return one;//from ww w . ja v a 2s . com }
From source file:com.kevlanche.threedeetest.ScalableObjLoader.java
License:Apache License
/** loads .mtl file */ public void load(FileHandle file) { String line;//from w ww. j a v a 2 s . c o m String[] tokens; String curMatName = "default"; Color difcolor = Color.WHITE; Color speccolor = Color.WHITE; float opacity = 1.f; float shininess = 0.f; String texFilename = null; if (file == null || file.exists() == false) return; BufferedReader reader = new BufferedReader(new InputStreamReader(file.read()), 4096); try { while ((line = reader.readLine()) != null) { if (line.length() > 0 && line.charAt(0) == '\t') line = line.substring(1).trim(); tokens = line.split("\\s+"); if (tokens[0].length() == 0) { continue; } else if (tokens[0].charAt(0) == '#') continue; else { final String key = tokens[0].toLowerCase(); if (key.equals("newmtl")) { ModelMaterial mat = new ModelMaterial(); mat.id = curMatName; mat.diffuse = new Color(difcolor); mat.specular = new Color(speccolor); mat.opacity = opacity; mat.shininess = shininess; if (texFilename != null) { ModelTexture tex = new ModelTexture(); tex.usage = ModelTexture.USAGE_DIFFUSE; tex.fileName = new String(texFilename); if (mat.textures == null) mat.textures = new Array<ModelTexture>(1); mat.textures.add(tex); } materials.add(mat); if (tokens.length > 1) { curMatName = tokens[1]; curMatName = curMatName.replace('.', '_'); } else curMatName = "default"; difcolor = Color.WHITE; speccolor = Color.WHITE; opacity = 1.f; shininess = 0.f; } else if (key.equals("kd") || key.equals("ks")) // diffuse or specular { float r = Float.parseFloat(tokens[1]); float g = Float.parseFloat(tokens[2]); float b = Float.parseFloat(tokens[3]); float a = 1; if (tokens.length > 4) a = Float.parseFloat(tokens[4]); if (tokens[0].toLowerCase().equals("kd")) { difcolor = new Color(); difcolor.set(r, g, b, a); } else { speccolor = new Color(); speccolor.set(r, g, b, a); } } else if (key.equals("tr") || key.equals("d")) { opacity = Float.parseFloat(tokens[1]); } else if (key.equals("ns")) { shininess = Float.parseFloat(tokens[1]); } else if (key.equals("map_kd")) { texFilename = file.parent().child(tokens[1]).path(); } } } reader.close(); } catch (IOException e) { return; } // last material ModelMaterial mat = new ModelMaterial(); mat.id = curMatName; mat.diffuse = new Color(difcolor); mat.specular = new Color(speccolor); mat.opacity = opacity; mat.shininess = shininess; if (texFilename != null) { ModelTexture tex = new ModelTexture(); tex.usage = ModelTexture.USAGE_DIFFUSE; tex.fileName = new String(texFilename); if (mat.textures == null) mat.textures = new Array<ModelTexture>(1); mat.textures.add(tex); } materials.add(mat); return; }
From source file:com.kotcrab.vis.ui.util.ColorUtils.java
License:Apache License
/** * Converts HSV color system to RGB/*from ww w .java 2 s .c o m*/ * @param h hue 0-360 * @param s saturation 0-100 * @param v value 0-100 * @param targetColor color that result will be stored in * @return targetColor */ public static Color HSVtoRGB(float h, float s, float v, Color targetColor) { if (h == 360) h = 359; int r, g, b; int i; float f, p, q, t; h = (float) Math.max(0.0, Math.min(360.0, h)); s = (float) Math.max(0.0, Math.min(100.0, s)); v = (float) Math.max(0.0, Math.min(100.0, v)); s /= 100; v /= 100; h /= 60; i = MathUtils.floor(h); f = h - i; p = v * (1 - s); q = v * (1 - s * f); t = v * (1 - s * (1 - f)); switch (i) { case 0: r = MathUtils.round(255 * v); g = MathUtils.round(255 * t); b = MathUtils.round(255 * p); break; case 1: r = MathUtils.round(255 * q); g = MathUtils.round(255 * v); b = MathUtils.round(255 * p); break; case 2: r = MathUtils.round(255 * p); g = MathUtils.round(255 * v); b = MathUtils.round(255 * t); break; case 3: r = MathUtils.round(255 * p); g = MathUtils.round(255 * q); b = MathUtils.round(255 * v); break; case 4: r = MathUtils.round(255 * t); g = MathUtils.round(255 * p); b = MathUtils.round(255 * v); break; default: r = MathUtils.round(255 * v); g = MathUtils.round(255 * p); b = MathUtils.round(255 * q); } targetColor.set(r / 255.0f, g / 255.0f, b / 255.0f, targetColor.a); return targetColor; }
From source file:com.quadbits.gdxhelper.actors.CloudsActor.java
License:Apache License
protected void setSpriteGridPropertiesFromCloud(SpriteGrid spriteGrid, Cloud cloud) { spriteGrid.setPosition(getX() + cloud.x, getY() + cloud.y); spriteGrid.setSize(cloud.width, cloud.height); spriteGrid.setFlipX(cloud.flipX);// w ww .j av a2s . c o m spriteGrid.setFlipY(cloud.flipY); Color spriteGridColor = spriteGrid.getColor(); Color actorColor = getColor(); spriteGridColor.set(actorColor.r, actorColor.g, actorColor.b, cloud.alpha); spriteGrid.setColor(spriteGridColor); }
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;/*from w w w. j av a 2 s .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;/*from w ww . j ava 2 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); }
From source file:com.tnf.ptm.common.PtmColorUtil.java
License:Apache License
public static Color load(String s) { String[] parts = s.split(" "); boolean hsb = "hsb".equals(parts[0]); int idx = hsb ? 1 : 0; int v1 = Integer.parseInt(parts[idx++]); int v2 = Integer.parseInt(parts[idx++]); int v3 = Integer.parseInt(parts[idx++]); float a = 1;//from ww w. j av a2s. co m if (parts.length > idx) { a = Integer.parseInt(parts[idx]) / 255f; } Color res = new Color(); if (hsb) { fromHSB(v1 / 360f, v2 / 100f, v3 / 100f, a, res); } else { res.set(v1 / 255f, v2 / 255f, v3 / 255f, a); } return res; }