Java Code Examples for com.badlogic.gdx.graphics.Color#set()
The following examples show how to use
com.badlogic.gdx.graphics.Color#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From skin-composer with MIT License | 6 votes |
/** * Does not dispose pixmap. * @param pixmap * @return */ public static Color averageColor(Pixmap pixmap) { Color temp = new Color(); float sumR = 0.0f; float sumG = 0.0f; float sumB = 0.0f; int count = 0; for (int y = 0; y < pixmap.getHeight(); y++) { for (int x = 0; x < pixmap.getWidth(); x++) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; } } } if (count == 0) { return new Color(Color.BLACK); } else { return new Color(sumR / count, sumG / count, sumB / count, 1.0f); } }
Example 2
Source File: Utils.java From skin-composer with MIT License | 6 votes |
/** * Does not dispose pixmap * @param pixmap * @return */ public static Pixmap tintPixmap(Pixmap pixmap, Color color) { Color tempColor = new Color(); for (int y = 0; y < pixmap.getHeight(); y++) { for (int x = 0; x < pixmap.getWidth(); x++) { tempColor.set(pixmap.getPixel(x, y)); float a = tempColor.a; tempColor.mul(color); tempColor.a = a; pixmap.setColor(tempColor); pixmap.drawPixel(x, y); tempColor.set(pixmap.getPixel(x, y)); } } return pixmap; }
Example 3
Source File: DefaultAnimator.java From uracer-kotd with Apache License 2.0 | 5 votes |
private void updateLights (TrackProgressData progressData, Color ambient, Color trees, float collisionFactor) { float base = 0.1f; float timeModFactor = URacer.Game.getTimeModFactor(); float blue = (base * 3f * timeModFactor) * (1 - AMath.sigmoidT(collisionFactor, 0.7f, true)); // Gdx.app.log("DefaultAnimator", "blue=" + blue); //@off ambient.set( base * 1.5f, base, base + blue, 0.55f + 0.05f * timeModFactor ); //@on ambient.clamp(); trees.set(ambient); // Gdx.app.log("", "" + ambient); // update point lights, more intensity from lights near the player PlayerCar player = world.getPlayer(); PointLight[] lights = world.getLights(); if (lights != null && player != null) { for (int l = 0; l < lights.length; l++) { float dist = player.getWorldPosMt().dst2(lights[l].getPosition()); float maxdist = 30; maxdist *= maxdist; dist = 1 - MathUtils.clamp(dist, 0, maxdist) / maxdist; float r = 1f; float g = 1f; float b = 1f; float a = 0.65f; lights[l].setColor(r, g, b, a);// + AMath.fixup(0.4f * dist)); } } }
Example 4
Source File: AOTextureGenerator.java From Cubes with MIT License | 5 votes |
protected static void generate(FileHandle file) { final long startTime = System.currentTimeMillis(); startExecutor(); Pixmap weak = generate(0.5f); Pixmap strong = generate(0.1f); Pixmap out = new Pixmap(weak.getWidth(), weak.getHeight(), weak.getFormat()); Color outColor = new Color(); Color tempColor = new Color(); for (int x = 0; x < out.getWidth(); x++) { for (int y = 0; y < out.getHeight(); y++) { outColor.r = tempColor.set(weak.getPixel(x, y)).r; outColor.g = tempColor.set(strong.getPixel(x, y)).r; outColor.b = 1f; outColor.a = 1f; out.drawPixel(x, y, Color.rgba8888(outColor)); } } weak.dispose(); strong.dispose(); System.out.println("Took " + ((System.currentTimeMillis() - startTime) / 1000 / 60) + " minutes"); System.out.println("Writing to: " + file.path()); System.out.println(); PixmapIO.writePNG(file, out); out.dispose(); }
Example 5
Source File: AOTextureGenerator.java From Cubes with MIT License | 5 votes |
private static void pixmapToDouble(Pixmap in, double[][] out) { Color c = new Color(); for (int x = 0; x < in.getWidth(); x++) { for (int y = 0; y < in.getHeight(); y++) { c.set(in.getPixel(x, y)); out[x][y] = c.r; } } }
Example 6
Source File: GdxCanvas.java From seventh with GNU General Public License v2.0 | 5 votes |
private void setColor(Color c, Integer color) { if(color != null) { int alpha = color >>> 24; color = (color << 8) | alpha; c.set(color); } }
Example 7
Source File: GameWorld.java From uracer-kotd with Apache License 2.0 | 4 votes |
private void createLights () { if (!mapUtils.hasObjectGroup(ObjectGroup.Lights)) { this.nightMode = false; return; } float rttScale = 0.5f; int maxRays = 360; if (!URacer.Game.isDesktop()) { rttScale = 0.2f; maxRays = 360; } RayHandler.setColorPrecisionHighp(); rayHandler = new RayHandler(box2dWorld, maxRays, (int)(ScaleUtils.PlayWidth * rttScale), (int)(ScaleUtils.PlayHeight * rttScale), true); rayHandler.setShadows(true); rayHandler.setCulling(true); rayHandler.setBlur(true); rayHandler.setBlurNum(2); rayHandler.setAmbientLight(0.1f, 0.05f, 0.1f, 0.4f); final Color c = new Color(); // setup player headlights data c.set(0.1f, 0.2f, 0.9f, 0.85f); int headlightsMask = CollisionFilters.CategoryTrackWalls; // int headlightsMask = CollisionFilters.CategoryTrackWalls | CollisionFilters.CategoryReplay; // int headlightsMask = CollisionFilters.CategoryReplay; // int headlightsMask = 0; playerHeadlightsA = new ConeLight(rayHandler, maxRays, c, 25, 0, 0, 0, 9); playerHeadlightsA.setSoft(true); playerHeadlightsA.setMaskBits(headlightsMask); playerHeadlightsB = new ConeLight(rayHandler, maxRays, c, 25, 0, 0, 0, 9); playerHeadlightsB.setSoft(true); playerHeadlightsB.setMaskBits(headlightsMask); // setup level lights data, if any Vector2 pos = new Vector2(); MapLayer group = mapUtils.getObjectGroup(ObjectGroup.Lights); int lights_count = group.getObjects().getCount(); lights = new PointLight[lights_count]; for (int i = 0; i < lights_count; i++) { //@off c.set( // MathUtils.random(0,1), // MathUtils.random(0,1), // MathUtils.random(0,1), 1f, .85f, 0.6f, 0.8f // MathUtils.random(0.85f,1), // MathUtils.random(0.8f,0.85f), // MathUtils.random(0.6f,0.8f), // 0.55f ); //@on RectangleMapObject o = (RectangleMapObject)group.getObjects().get(i); pos.set(o.getRectangle().x, o.getRectangle().y);// .scl(scalingStrategy.invTileMapZoomFactor); pos.y = worldSizePx.y - pos.y; pos.set(Convert.px2mt(pos));// .scl(scalingStrategy.tileMapZoomFactor); PointLight l = new PointLight(rayHandler, maxRays, c, MathUtils.random(15, 20), pos.x, pos.y); l.setSoft(true); l.setStaticLight(false); l.setMaskBits(CollisionFilters.CategoryPlayer | CollisionFilters.CategoryTrackWalls); lights[i] = l; } // playerImpulse = new PointLight(rayHandler, maxRays); // playerImpulse.setMaskBits(CollisionFilters.CategoryPlayer | CollisionFilters.CategoryReplay); // playerImpulse.setSoft(true); // playerImpulse.setStaticLight(false); // playerImpulse.setActive(true); // playerImpulse.setColor(1, 1, 1, 1f); // playerImpulse.setDistance(5); }
Example 8
Source File: ColorUtils.java From typing-label with MIT License | 4 votes |
/** * Converts HSV color system to RGB * * @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; }
Example 9
Source File: Utils.java From skin-composer with MIT License | 4 votes |
/** * Does not dispose pixmap. * @param pixmap * @param ninePatch * @return */ public static Color averageEdgeColor(Pixmap pixmap, boolean ninePatch) { int border = 0; if (ninePatch) { border = 1; } Color temp = new Color(); float sumR = 0.0f; float sumG = 0.0f; float sumB = 0.0f; int count = 0; //left edge for (int y = border; y < pixmap.getHeight() - border; y++) { for (int x = border; x < pixmap.getWidth() - border; x++) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; break; } } } //right edge for (int y = border; y < pixmap.getHeight() - border; y++) { for (int x = pixmap.getWidth() - 1 - border; x > border; x--) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; break; } } } //top edge for (int x = border; x < pixmap.getWidth() - border; x++) { for (int y = border; y < pixmap.getHeight() - border; y++) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; break; } } } //bottom edge for (int x = border; x < pixmap.getWidth() - border; x++) { for (int y = pixmap.getHeight() - 1 - border; y > border; y--) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; break; } } } if (count == 0) { return new Color(Color.BLACK); } else { return new Color(sumR / count, sumG / count, sumB / count, 1.0f); } }
Example 10
Source File: SystemProfiler.java From riiablo with Apache License 2.0 | 4 votes |
/** * Calculates semi unique color from given hash */ public static Color calculateColor(int hash, Color color) { float hue = (hash % 333) / 333f; float saturation = ((hash % 271) / 271f) * 0.2f + 0.8f; float brightness = ((hash % 577) / 577f) * 0.1f + 0.9f; int r = 0, g = 0, b = 0; if (saturation == 0) { r = g = b = (int) (brightness * 255.0f + 0.5f); } else { float h = (hue - (float) Math.floor(hue)) * 6.0f; float f = h - (float) Math.floor(h); float p = brightness * (1.0f - saturation); float q = brightness * (1.0f - saturation * f); float t = brightness * (1.0f - (saturation * (1.0f - f))); switch ((int) h) { case 0: r = (int) (brightness * 255.0f + 0.5f); g = (int) (t * 255.0f + 0.5f); b = (int) (p * 255.0f + 0.5f); break; case 1: r = (int) (q * 255.0f + 0.5f); g = (int) (brightness * 255.0f + 0.5f); b = (int) (p * 255.0f + 0.5f); break; case 2: r = (int) (p * 255.0f + 0.5f); g = (int) (brightness * 255.0f + 0.5f); b = (int) (t * 255.0f + 0.5f); break; case 3: r = (int) (p * 255.0f + 0.5f); g = (int) (q * 255.0f + 0.5f); b = (int) (brightness * 255.0f + 0.5f); break; case 4: r = (int) (t * 255.0f + 0.5f); g = (int) (p * 255.0f + 0.5f); b = (int) (brightness * 255.0f + 0.5f); break; case 5: r = (int) (brightness * 255.0f + 0.5f); g = (int) (p * 255.0f + 0.5f); b = (int) (q * 255.0f + 0.5f); break; } } return color.set(r / 255f, g / 255f, b / 255f, 1); }
Example 11
Source File: ColorUtils.java From vis-ui with Apache License 2.0 | 4 votes |
/** * Converts HSV color system to RGB * @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; }