/** * Set a knot type. * @param n the knot index * @param type the type * @see #getKnotType */ public void setKnotType(int n, int type) { knotTypes[n] = (byte)((knotTypes[n] & ~COLOR_MASK) | type); rebuildGradient(); }
/** * Set a knot blend type. * @param n the knot index * @param type the knot blend type * @see #getKnotBlend */ public void setKnotBlend(int n, int type) { knotTypes[n] = (byte)((knotTypes[n] & ~BLEND_MASK) | type); rebuildGradient(); }
/** * Construct a Gradient. */ public Gradient() { rebuildGradient(); }
/** * Set a knot color. * @param n the knot index * @param color the color * @see #getKnot */ public void setKnot(int n, int color) { yKnots[n] = color; rebuildGradient(); }
/** * Set a knot type. * * @param n the knot index * @param type the type * @see #getKnotType */ public void setKnotType(int n, int type) { knotTypes[n] = (byte) ((knotTypes[n] & ~COLOR_MASK) | type); rebuildGradient(); }
/** * Set a knot blend type. * * @param n the knot index * @param type the knot blend type * @see #getKnotBlend */ public void setKnotBlend(int n, int type) { knotTypes[n] = (byte) ((knotTypes[n] & ~BLEND_MASK) | type); rebuildGradient(); }
/** * Construct a Gradient. */ public Gradient() { rebuildGradient(); }
/** * Set a knot color. * * @param n the knot index * @param color the color * @see #getKnot */ public void setKnot(int n, int color) { yKnots[n] = color; rebuildGradient(); }
/** * Remove a knot. * @param n the knot index * @see #addKnot */ public void removeKnot(int n) { if (numKnots <= 4) return; if (n < numKnots-1) { System.arraycopy(xKnots, n+1, xKnots, n, numKnots-n-1); System.arraycopy(yKnots, n+1, yKnots, n, numKnots-n-1); System.arraycopy(knotTypes, n+1, knotTypes, n, numKnots-n-1); } numKnots--; if (xKnots[1] > 0) xKnots[1] = 0; rebuildGradient(); }
private void rebuild() { sortKnots(); rebuildGradient(); }
private void rebuild() { sortKnots(); rebuildGradient(); }
/** * Set the values of a set of knots. * @param x the knot positions * @param y the knot colors * @param types the knot types * @param offset the first knot to set * @param count the number of knots */ public void setKnots(int[] x, int[] y, byte[] types, int offset, int count) { numKnots = count; xKnots = new int[numKnots]; yKnots = new int[numKnots]; knotTypes = new byte[numKnots]; System.arraycopy(x, offset, xKnots, 0, numKnots); System.arraycopy(y, offset, yKnots, 0, numKnots); System.arraycopy(types, offset, knotTypes, 0, numKnots); sortKnots(); rebuildGradient(); }
/** * Randomize the gradient. */ public void randomize() { numKnots = 4 + (int)(6*Math.random()); xKnots = new int[numKnots]; yKnots = new int[numKnots]; knotTypes = new byte[numKnots]; for (int i = 0; i < numKnots; i++) { xKnots[i] = (int)(255 * Math.random()); yKnots[i] = 0xff000000 | ((int)(255 * Math.random()) << 16) | ((int)(255 * Math.random()) << 8) | (int)(255 * Math.random()); knotTypes[i] = RGB|SPLINE; } xKnots[0] = -1; xKnots[1] = 0; xKnots[numKnots-2] = 255; xKnots[numKnots-1] = 256; sortKnots(); rebuildGradient(); }
/** * Randomize the gradient. */ public void randomize() { numKnots = 4 + (int) (6 * Math.random()); xKnots = new int[numKnots]; yKnots = new int[numKnots]; knotTypes = new byte[numKnots]; for (int i = 0; i < numKnots; i++) { xKnots[i] = (int) (255 * Math.random()); yKnots[i] = 0xff000000 | ((int) (255 * Math.random()) << 16) | ((int) (255 * Math.random()) << 8) | (int) (255 * Math.random()); knotTypes[i] = RGB | SPLINE; } xKnots[0] = -1; xKnots[1] = 0; xKnots[numKnots - 2] = 255; xKnots[numKnots - 1] = 256; sortKnots(); rebuildGradient(); }
/** * Set the values of a set of knots. * * @param x the knot positions * @param y the knot colors * @param types the knot types * @param offset the first knot to set * @param count the number of knots */ public void setKnots(int[] x, int[] y, byte[] types, int offset, int count) { numKnots = count; xKnots = new int[numKnots]; yKnots = new int[numKnots]; knotTypes = new byte[numKnots]; System.arraycopy(x, offset, xKnots, 0, numKnots); System.arraycopy(y, offset, yKnots, 0, numKnots); System.arraycopy(types, offset, knotTypes, 0, numKnots); sortKnots(); rebuildGradient(); }
/** * Set a knot position. * @param n the knot index * @param x the knot position * @see #setKnotPosition */ public void setKnotPosition(int n, int x) { xKnots[n] = ImageMath.clamp(x, 0, 255); sortKnots(); rebuildGradient(); }
/** * Split a span into two by adding a knot in the middle. * @param n the span index */ public void splitSpan(int n) { int x = (xKnots[n] + xKnots[n+1])/2; addKnot(x, getColor(x/256.0f), knotTypes[n]); rebuildGradient(); }
/** * Split a span into two by adding a knot in the middle. * * @param n the span index */ public void splitSpan(int n) { int x = (xKnots[n] + xKnots[n + 1]) / 2; addKnot(x, getColor(x / 256.0f), knotTypes[n]); rebuildGradient(); }
/** * Set a knot position. * * @param n the knot index * @param x the knot position * @see #setKnotPosition */ public void setKnotPosition(int n, int x) { xKnots[n] = ImageMath.clamp(x, 0, 255); sortKnots(); rebuildGradient(); }
/** * Mutate the gradient. * @param amount the amount in the range zero to one */ public void mutate(float amount) { for (int i = 0; i < numKnots; i++) { int rgb = yKnots[i]; int r = ((rgb >> 16) & 0xff); int g = ((rgb >> 8) & 0xff); int b = (rgb & 0xff); r = PixelUtils.clamp( (int)(r + amount * 255 * (Math.random()-0.5)) ); g = PixelUtils.clamp( (int)(g + amount * 255 * (Math.random()-0.5)) ); b = PixelUtils.clamp( (int)(b + amount * 255 * (Math.random()-0.5)) ); yKnots[i] = 0xff000000 | (r << 16) | (g << 8) | b; knotTypes[i] = RGB|SPLINE; } sortKnots(); rebuildGradient(); }