protected int randColor () { return Color.rgb(128 + _rnd.nextInt(127), 128 + _rnd.nextInt(127), 128 + _rnd.nextInt(127)); }
/** * Creates a packed integer color from three RGB values in the range [0, 255]. */ public static int rgb(int r, int g, int b) { return argb(0xff, r, g, b); }
/** * Creates a new darkened version of the given color. This is implemented by composing a new * color consisting of the components of the original color, each multiplied by the dark factor. * The alpha channel is copied from the original. */ public static int darker (int color, float darkFactor) { return Color.argb(Color.alpha(color), Math.max((int)(Color.red(color) * darkFactor), 0), Math.max((int)(Color.green(color) * darkFactor), 0), Math.max((int)(Color.blue(color) * darkFactor), 0)); }
/** * Blends two colors proportionally. * @param p1 The percentage of the first color to use, from 0.0f to 1.0f inclusive. */ public static int blend (int c1, int c2, float p1) { float p2 = 1 - p1; return Color.rgb((int)(Color.red(c1) * p1 + Color.red(c2) * p2), (int)(Color.green(c1) * p1 + Color.green(c2) * p2), (int)(Color.blue(c1) * p1 + Color.blue(c2) * p2)); }
/** Returns a string representation of the specified particle's data. */ public static String dump (float[] data, int index, int start) { float a = Color.decodeUpper(data[start + ALPHA_RED]); float r = Color.decodeLower(data[start + ALPHA_RED]); float g = Color.decodeUpper(data[start + GREEN_BLUE]); float b = Color.decodeLower(data[start + GREEN_BLUE]); return index + " tx:" + data[start + M00] + "," + data[start + M01] + "," + data[start + M10] + "," + data[start + M11] + "," + data[start + TX] + "," + data[start + TY] + " vel:" + data[start + VEL_X] + "," + data[start + VEL_Y] + " life:" + data[start + BIRTH] + "," + data[start + LIFESPAN] + " color:" + r + "," + g + "," + b + "," + a; }
@Override public void drawTransform(Transform xf) { getWorldToScreenToOut(xf.p, tempVec1); tempVec2.setZero(); // float k_axisScale = 0.4f; canvas.setStrokeColor(Color.rgb(1, 0, 0)); // note: violates strokeAlpha tempVec2.x = xf.p.x; // + k_axisScale * xf.R.m11; // Transform no longer scales tempVec2.y = xf.p.y; // + k_axisScale * xf.R.m12; getWorldToScreenToOut(tempVec2, tempVec2); canvas.drawLine(tempVec1.x, tempVec1.y, tempVec2.x, tempVec2.y); canvas.setStrokeColor(Color.rgb(0, 1, 0)); // note: violates strokeAlpha tempVec2.x = xf.p.x; // + k_axisScale * xf.R.m21; // Transform no longer scales tempVec2.y = xf.p.y; // + k_axisScale * xf.R.m22; getWorldToScreenToOut(tempVec2, tempVec2); canvas.drawLine(tempVec1.x, tempVec1.y, tempVec2.x, tempVec2.y); canvas.setStrokeColor(Color.argb(strokeAlpha, 1, 0, 0)); // restores strokeAlpha }
@Override public void apply (int index, float[] data, int start, float now, float dt) { float alpha = interp.apply( startAlpha, rangeAlpha, now - data[start + BIRTH], data[start + LIFESPAN]); float red = Color.decodeLower(data[start + ALPHA_RED]); data[start + ALPHA_RED] = Color.encode(alpha, red); } };
@Override public void drawTransform(Transform xf) { if (canvas == null) { log().error(CANVASERROR); return; } getWorldToScreenToOut(xf.p, tempVec1); tempVec2.setZero(); // float k_axisScale = 0.4f; canvas.setStrokeColor(Color.rgb(1, 0, 0)); // note: violates strokeAlpha tempVec2.x = xf.p.x; // + k_axisScale * xf.R.m11; // Transform no longer scales tempVec2.y = xf.p.y; // + k_axisScale * xf.R.m12; getWorldToScreenToOut(tempVec2, tempVec2); canvas.drawLine(tempVec1.x, tempVec1.y, tempVec2.x, tempVec2.y); canvas.setStrokeColor(Color.rgb(0, 1, 0)); // note: violates strokeAlpha tempVec2.x = xf.p.x; // + k_axisScale * xf.R.m21; // Transform no longer scales tempVec2.y = xf.p.y; // + k_axisScale * xf.R.m22; getWorldToScreenToOut(tempVec2, tempVec2); canvas.drawLine(tempVec1.x, tempVec1.y, tempVec2.x, tempVec2.y); canvas.setStrokeColor(Color.argb(strokeAlpha, 1, 0, 0)); // restores strokeAlpha }
public void render(Surface surf) { surf.setFillColor(Color.rgb(255, 255, 255)); surf.fillRect(0, 0, graphics().width(), graphics().height()); } });
/** * Creates a packed integer color from three RGB values in the range [0, 255]. */ public static int rgb(int r, int g, int b) { return argb(0xff, r, g, b); }
/** * Creates a new brightened version of the given color. This is implemented by composing a new * color consisting of the components of the original color, each multiplied by 10/7, with * exceptions for zero-valued components. The alpha channel is copied from the original. */ public static int brighter (int color) { int a = Color.alpha(color); int r = Color.red(color), g = Color.green(color), b = Color.blue(color); // black is a special case the just goes to dark gray if (r == 0 && g == 0 && b == 0) return Color.argb(a, MIN_BRIGHT, MIN_BRIGHT, MIN_BRIGHT); // bump each component up to the minumum, unless it is absent if (r != 0) r = Math.max(MIN_BRIGHT, r); if (g != 0) g = Math.max(MIN_BRIGHT, g); if (b != 0) b = Math.max(MIN_BRIGHT, b); // scale return Color.argb(a, Math.min((int)(r*BRIGHT_FACTOR), 255), Math.min((int)(g*BRIGHT_FACTOR), 255), Math.min((int)(b*BRIGHT_FACTOR), 255)); }
@Override public void init() { // remove the background layer added by default graphics().rootLayer().removeAll(); // add a grey square SurfaceImage surf = graphics().createSurface(width, height); surf.surface().setFillColor(Color.rgb(200, 200, 200)); surf.surface().fillRect(0, 0, width, height); square = graphics().createImageLayer(surf); graphics().rootLayer().add(square); }
/** * Creates a packed integer color from three RGB values in the range [0, 255]. */ public static int rgb(int r, int g, int b) { return argb(0xff, r, g, b); }
@Override public void init() { // remove the background layer added by default graphics().rootLayer().clear(); // add a grey square square = graphics().createSurfaceLayer(width, height); square.surface().setFillColor(Color.rgb(200, 200, 200)); square.surface().fillRect(0, 0, square.surface().width(), square.surface().height()); graphics().rootLayer().add(square); }
/** * Sets the fill color from the cached rgb values. */ private void setFillColorFromCache() { canvas .setFillColor( Color.argb(fillAlpha, (int) (255 * cacheFillR), (int) (255 * cacheFillG), (int) (255 * cacheFillB))); }
@Override public void init () { // remove the background layer added by default game.rootLayer.disposeAll(); // add a grey square TextureSurface surf = game.createSurface(width, height); surf.begin().setFillColor(Color.rgb(200, 200, 200)).fillRect(0, 0, width, height).end().close(); ImageLayer square = new ImageLayer(surf.texture); game.rootLayer.add(square); conns.add(game.paint.connect(clock -> { float t = clock.tick / 1000f; IDimension vsize = game.plat.graphics().viewSize; square.setTranslation((FloatMath.cos(t) + 1) * (vsize.width() - width)/2, (FloatMath.sin(t) + 1) * (vsize.height() - height)/2); })); } }
/** * Sets the fill color from the cached rgb values. */ private void setFillColorFromCache() { canvas.setFillColor( Color.argb(fillAlpha, (int) (255 * cacheFillR), (int) (255 * cacheFillG), (int) (255 * cacheFillB))); }
/** * Sets the fill color from the cached rgb values. */ private void setStrokeColorFromCache() { canvas.setStrokeColor( Color.argb(strokeAlpha, (int) (255 * cacheStrokeR), (int) (255 * cacheStrokeG), (int) (255 * cacheStrokeB))); }