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:de.fgerbig.spacepeng.tween.SpriteTween.java
License:Open Source License
@Override public void setValues(Sprite target, int tweenType, float[] newValues) { switch (tweenType) { case POS_X:/*from w ww .j a va 2 s. c o m*/ target.setX(newValues[0]); break; case POS_Y: target.setY(newValues[0]); break; case POS_XY: target.setPosition(newValues[0], newValues[1]); break; case SCALE_X: target.setScale(newValues[0], target.getScaleY()); break; case SCALE_Y: target.setScale(target.getScaleX(), newValues[0]); break; case SCALE_XY: target.setScale(newValues[0], newValues[1]); break; case COLOR: Color c = target.getColor(); c.set(newValues[0], newValues[1], newValues[2], newValues[3]); target.setColor(c); break; default: assert false; break; } }
From source file:dorkbox.accessors.SpriteAccessor.java
License:Apache License
@Override public void setValues(Sprite target, int tweenType, float[] newValues) { switch (tweenType) { case POS_XY://from w w w. j a v a2 s . c o m target.setPosition(newValues[0], newValues[1]); break; case CPOS_XY: target.setPosition(newValues[0] - target.getWidth() / 2, newValues[1] - target.getHeight() / 2); break; case SCALE_XY: target.setScale(newValues[0], newValues[1]); break; case ROTATION: target.setRotation(newValues[0]); break; case OPACITY: Color c = target.getColor(); c.set(c.r, c.g, c.b, newValues[0]); target.setColor(c); break; case TINT: c = target.getColor(); c.set(newValues[0], newValues[1], newValues[2], c.a); target.setColor(c); break; default: assert false; } }
From source file:enibdevlab.dwarves.controllers.actions.animations.BetterColorAction.java
License:Apache License
protected void update(float percent) { float r = startR + (end.r - startR) * percent; float g = startG + (end.g - startG) * percent; float b = startB + (end.b - startB) * percent; float a = startA + (end.a - startA) * percent; Color color = actor.getColor(); color.set(r, g, b, a); }
From source file:me.scarlet.undertailor.gfx.text.TextComponent.java
License:Open Source License
/** * Internal method.//from ww w . ja v a 2s . com * * <p>Applies the parameters found on a single * {@link TextPiece} onto the provided {@link Builder} * .</p> * * @param builder the Builder to apply parameters to * @param tailor the current Undertailor instance * @param piece the TextPiece to read from */ protected static void applyParameters(Builder builder, Undertailor tailor, TextPiece piece) { piece.getParams().entries().forEach(entry -> { TextParam paramType = entry.key; String value = entry.value; if (value == null || value.trim().isEmpty()) { return; } switch (paramType) { case FONT: Font font = tailor.getAssetManager().getFontManager().getFont(value); if (font == null && (value != null && !value.trim().isEmpty())) logger.warn("Couldn't find font " + value + " to assign to text"); builder.setFont(font); break; case SOUND: Sound sound = tailor.getAssetManager().getAudioManager().getSound(value); if (sound == null) logger.warn("Couldn't find sound " + value + " to assign to text"); builder.setSound(sound); break; case STYLE: String[] split = value.split(","); for (String styleValue : split) { TextStyle style = tailor.getAssetManager().getStyleManager().getStyle(styleValue); if (style == null) logger.warn("Couldn't find style " + value + " to assign to text"); builder.addStyles(style); } break; case COLOR: case DELAY: case SEGMENTSIZE: case SPEED: try { if (paramType == TextParam.COLOR) { String[] rgb = value.trim().split(","); if (rgb.length > 1) { Color color = new Color(); color.set(Float.valueOf(rgb[0]), Float.valueOf(rgb[1]), Float.valueOf(rgb[2]), rgb.length >= 4 ? Float.valueOf(rgb[3]) : 255F); } else { if (!value.startsWith("#")) { value = "#" + value; } if (value.length() < 7) { throw new IllegalArgumentException(); } builder.setColor(Color.valueOf(value)); } } else { if (paramType == TextParam.DELAY) { builder.setDelay(Float.valueOf(value)); } else if (paramType == TextParam.SEGMENTSIZE) { builder.setSegmentSize(Integer.valueOf(value)); } else if (paramType == TextParam.SPEED) { builder.setSpeed(Float.valueOf(value)); } } } catch (Exception e) { logger.warn("Invalid value " + value + " for parameter " + paramType.toString()); } break; default: break; } }); }
From source file:me.scarlet.undertailor.lua.meta.LuaColorMeta.java
License:Open Source License
public LuaColorMeta() { this.metatable = new LuaTable(); // color:getRGB() set("getRGB", asFunction(vargs -> { Color color = obj(vargs); return varargsOf(valueOf((int) (color.r * 255)), valueOf((int) (color.g * 255)), valueOf((int) (color.b * 255))); }));/*w ww. j av a2s. c o m*/ // color:add(color) // color:add(r, g, b) set("add", asFunction(vargs -> { Color color = obj(vargs); if (vargs.arg(2).isnumber()) { float r = vargs.optint(2, 0) / 255F; float g = vargs.optint(3, 0) / 255F; float b = vargs.optint(4, 0) / 255F; return orNil(color.add(r, g, b, 0)); } else { Color added = convert(vargs.arg(2)).getObject(); return orNil(color.add(added)); } })); // color:multiply(color) // color:multiply(r, g, b) set("multiply", asFunction(vargs -> { Color color = obj(vargs); if (vargs.arg(2).isnumber()) { float r = vargs.optint(2, 0) / 255F; float g = vargs.optint(3, 0) / 255F; float b = vargs.optint(4, 0) / 255F; return orNil(color.mul(r, g, b, 0)); } else { Color multiplier = convert(vargs.arg(2)).getObject(); return orNil(color.mul(multiplier)); } })); // color:subtract(color) // color:subtract(r, g, b) set("subtract", asFunction(vargs -> { Color color = obj(vargs); if (vargs.arg(2).isnumber()) { float r = vargs.optint(2, 0) / 255F; float g = vargs.optint(3, 0) / 255F; float b = vargs.optint(4, 0) / 255F; return orNil(color.sub(r, g, b, 0)); } else { Color subtracted = convert(vargs.arg(2)).getObject(); return orNil(color.sub(subtracted)); } })); // color:setRGB(color) // color:setRGB(r, g, b) set("setRGB", asFunction(vargs -> { Color color = obj(vargs); if (vargs.arg(2).isnumber()) { float r = vargs.optint(2, 0) / 255F; float g = vargs.optint(3, 0) / 255F; float b = vargs.optint(4, 0) / 255F; return orNil(color.set(r, g, b, 1)); } else { Color set = convert(vargs.arg(2)).getObject(); return orNil(color.set(set)); } })); // color:clone() set("clone", asFunction(vargs -> { return orNil(obj(vargs).cpy()); })); // color:toHex() set("toHex", asFunction(vargs -> { return valueOf(obj(vargs).toString()); })); }
From source file:net.mwplay.cocostudio.ui.particleutil.CCParticleActor.java
License:Apache License
private void updateParticleQuads(Particle _particleData, int idx) { if (_particleCount <= 0) { return;/*from w w w .ja va2s . c o m*/ } pos.setZero(); if (_positionType == PositionTypeFree) { //Vector3 p1 = new Vector3(); p1.setZero(); p1.set(currentPosition.x, currentPosition.y, 0); transformPoint(p1); p2.setZero(); newPos.setZero(); p2.set(_particleData.startPos.x, _particleData.startPos.y, 0); // matrix4.trn(p2); // matrix4.getTranslation(p2); transformPoint(p2); newPos.set(_particleData.pos.x, _particleData.pos.y); p2.x = p1.x - p2.x; p2.y = p1.y - p2.y; newPos.x -= p2.x - pos.x; newPos.y -= p2.y - pos.y; updatePosWithParticle(_particleData, newPos, _particleData.size, _particleData.rotation, idx); } else if (_positionType == PositionTypeRelative) { newPos.setZero(); newPos.set(_particleData.pos.x, _particleData.pos.y); newPos.x = _particleData.pos.x - (currentPosition.x - _particleData.startPos.x); newPos.y = _particleData.pos.y - (currentPosition.y - _particleData.startPos.y); newPos.add(pos); updatePosWithParticle(_particleData, newPos, _particleData.size, _particleData.rotation, idx); } else { newPos.setZero(); newPos.set(_particleData.pos.x + pos.x, _particleData.pos.y + pos.y); updatePosWithParticle(_particleData, newPos, _particleData.size, _particleData.rotation, idx); } Color color = new Color(); if (m_bOpacityModifyRGB) { //for(int i=0;i<_particleCount;++i){ // Particle _particleData = m_pParticles[i]; color.set(_particleData.color.r * _particleData.color.a, _particleData.color.g * _particleData.color.a, _particleData.color.b * _particleData.color.a, _particleData.color.a); float[] toUpdate = vertices[idx]; float colorFloat = color.toFloatBits(); toUpdate[C1] = colorFloat; toUpdate[C2] = colorFloat; toUpdate[C3] = colorFloat; toUpdate[C4] = colorFloat; //} } else { //for(int i=0;i<_particleCount;++i){ // Particle _particleData = m_pParticles[i]; float[] toUpdate = vertices[idx]; float colorFloat = _particleData.color.toFloatBits(); toUpdate[C1] = colorFloat; toUpdate[C2] = colorFloat; toUpdate[C3] = colorFloat; toUpdate[C4] = colorFloat; //} } }
From source file:net.mwplay.cocostudio.ui.particleutil.CCParticleActor.java
License:Apache License
private void addParticle(int count) { int start = _particleCount; _particleCount += count;/*from w w w.j ava2s. co m*/ pos.setZero(); if (_positionType == PositionTypeFree) { pos = this.localToStageCoordinates(pos); } else if (_positionType == PositionTypeRelative) { //pos = m_tSourcePosition; pos.set(this.getX(), this.getY()); } for (int i = start; i < _particleCount; ++i) { // m_pParticles[i] = new Particle();; m_pParticles[i] = particlePool.obtain(); //life float theLife = m_fLife + m_fLifeVar * RANDOM_M11(); m_pParticles[i].timeToLive = Math.max(0, theLife); //postion m_pParticles[i].pos.x = m_tSourcePosition.x + m_tPosVar.x * RANDOM_M11(); m_pParticles[i].pos.y = m_tSourcePosition.y + m_tPosVar.y * RANDOM_M11(); float r = MathUtils.clamp(m_tStartColor.r + m_tStartColorVar.r * RANDOM_M11(), 0, 1); float g = MathUtils.clamp(m_tStartColor.g + m_tStartColorVar.g * RANDOM_M11(), 0, 1); float b = MathUtils.clamp(m_tStartColor.b + m_tStartColorVar.b * RANDOM_M11(), 0, 1); float a = MathUtils.clamp(m_tStartColor.a + m_tStartColorVar.a * RANDOM_M11(), 0, 1); m_pParticles[i].color.set(r, g, b, a); //end color r = MathUtils.clamp(m_tEndColor.r + m_tEndColorVar.r * RANDOM_M11(), 0, 1); g = MathUtils.clamp(m_tEndColor.g + m_tEndColorVar.g * RANDOM_M11(), 0, 1); b = MathUtils.clamp(m_tEndColor.b + m_tEndColorVar.b * RANDOM_M11(), 0, 1); a = MathUtils.clamp(m_tEndColor.a + m_tEndColorVar.a * RANDOM_M11(), 0, 1); m_pParticles[i].deltaColor.set(r, g, b, a); Color deltaColor = m_pParticles[i].deltaColor; Color color = m_pParticles[i].color; r = (deltaColor.r - color.r) / m_pParticles[i].timeToLive; g = (deltaColor.g - color.g) / m_pParticles[i].timeToLive; b = (deltaColor.b - color.b) / m_pParticles[i].timeToLive; a = (deltaColor.a - color.a) / m_pParticles[i].timeToLive; deltaColor.set(r, g, b, a); Particle _particleData = m_pParticles[i]; _particleData.size = m_fStartSize + m_fStartSizeVar * RANDOM_M11(); _particleData.size = Math.max(0, _particleData.size); _particleData.rotation = m_fStartSpin + m_fStartSpinVar * RANDOM_M11(); float endA = m_fEndSpin + m_fEndSpinVar * RANDOM_M11(); _particleData.deltaRotation = (endA - _particleData.deltaRotation) / _particleData.timeToLive; _particleData.startPos.x = pos.x; _particleData.startPos.y = pos.y; if (_endSize != START_SIZE_EQUAL_TO_END_SIZE) { float endSize = _endSize + _endSizeVar * RANDOM_M11(); endSize = Math.max(0, endSize); _particleData.deltaSize = (endSize - _particleData.size) / _particleData.timeToLive; } else { m_pParticles[i].deltaSize = 0; } if (_emitterMode == ParticleModeGravity) { _particleData.modeA.radialAccel = modeA.radialAccel + modeA.radialAccelVar * RANDOM_M11(); _particleData.modeA.tangentialAccel = modeA.tangentialAccel + modeA.tangentialAccelVar * RANDOM_M11(); if (modeA.rotationIsDir) { float ar = CC_DEGREES_TO_RADIANS(m_fAngle + m_fAngleVar * RANDOM_M11()); v.setZero(); v.x = (float) Math.cos(ar); v.y = (float) Math.sin(ar); float s = modeA.speed + modeA.speedVar * RANDOM_M11(); // Vector2 dir = new Vector2(); dir.setZero(); dir.mulAdd(v, s); _particleData.modeA.dir.x = dir.x; _particleData.modeA.dir.y = dir.y; _particleData.rotation = -CC_RADIANS_TO_DEGREES(dir.angleRad()); } else { float ar = CC_DEGREES_TO_RADIANS(m_fAngle + m_fAngleVar * RANDOM_M11()); v.setZero(); v.x = (float) MathUtils.cos(ar); v.y = (float) MathUtils.sin(ar); float s = modeA.speed + modeA.speedVar * RANDOM_M11(); //Vector2 dir = new Vector2(); dir.setZero(); dir.mulAdd(v, s); _particleData.modeA.dir.x = dir.x; _particleData.modeA.dir.y = dir.y; } } else { _particleData.modeB.radius = modeB.startRadius + modeB.startRadiusVar * RANDOM_M11(); _particleData.modeB.angle = CC_DEGREES_TO_RADIANS(m_fAngle + m_fAngleVar * RANDOM_M11()); _particleData.modeB.degreesPerSecond = CC_DEGREES_TO_RADIANS( modeB.rotatePerSecond + modeB.rotatePerSecondVar * RANDOM_M11()); if (modeB.endRadius == START_RADIUS_EQUAL_TO_END_RADIUS) { _particleData.modeB.deltaRadius = 0; } else { float endRadius = modeB.endRadius + modeB.endRadiusVar * RANDOM_M11(); _particleData.modeB.deltaRadius = (endRadius - _particleData.modeB.radius) / _particleData.timeToLive; } } } }
From source file:org.destinationsol.common.SolColorUtil.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;// ww w . j a v a2 s. c o 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; }
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 w w.ja v a2 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(); }