public BufferedImage filter(BufferedImage src, BufferedImage dst) { if (dst == null) dst = createCompatibleDestImage(src, null); int width = src.getWidth(); int height = src.getHeight(); int numScratches = (int) (density * width * height / 100); ArrayList<Line2D> lines = new ArrayList<Line2D>(); { float l = length * width; Random random = new Random(seed); Graphics2D g = dst.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(new Color(color)); g.setStroke(new BasicStroke(this.width)); for (int i = 0; i < numScratches; i++) { float x = width * random.nextFloat(); float y = height * random.nextFloat(); float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f)); float s = (float) Math.sin(a) * l; float c = (float) Math.cos(a) * l; float x1 = x - c; float y1 = y - s; float x2 = x + c; float y2 = y + s; g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); lines.add(new Line2D.Float(x1, y1, x2, y2)); } g.dispose(); } if (false) { // int[] inPixels = getRGB( src, 0, 0, width, height, null ); int[] inPixels = new int[width * height]; int index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float sx = x, sy = y; for (int i = 0; i < numScratches; i++) { Line2D.Float l = (Line2D.Float) lines.get(i); float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1); if (dot > 0) inPixels[index] |= (1 << i); } index++; } } Colormap colormap = new LinearColormap(); index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff; inPixels[index] = colormap.getColor(f); index++; } } setRGB(dst, 0, 0, width, height, inPixels); } return dst; }
public void randomize() { seed = new Date().getTime(); randomGenerator.setSeed(seed); a = randomGenerator.nextFloat(); b = randomGenerator.nextFloat(); c = randomGenerator.nextFloat(); d = randomGenerator.nextFloat(); k = randomGenerator.nextInt() % 20 - 10; }
private int displace(int rgb, float amount) { int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; r = PixelUtils.clamp(r + (int) (amount * (randomGenerator.nextFloat() - 0.5))); g = PixelUtils.clamp(g + (int) (amount * (randomGenerator.nextFloat() - 0.5))); b = PixelUtils.clamp(b + (int) (amount * (randomGenerator.nextFloat() - 0.5))); return 0xff000000 | (r << 16) | (g << 8) | b; }
private int randomRGB(int[] inPixels, int x, int y) { if (useImageColors) { return inPixels[y * originalSpace.width + x]; } else { int r = (int) (255 * randomGenerator.nextFloat()); int g = (int) (255 * randomGenerator.nextFloat()); int b = (int) (255 * randomGenerator.nextFloat()); return 0xff000000 | (r << 16) | (g << 8) | b; } }
public void setRandom(Random random) /* Sets all the scalars in 'this' to random values uniformly distributed * over (0.0, 1.0) using the pseudo-random generator 'random'. */ { // setZero(); for (int k = 0; k < size; ++k) f[k] = random.nextFloat(); }
public ScalarImage(int width, int height, Random random) /* Constructs a new ScalarImage = < width, height, zero-buffer > */ { this.width = width; this.height = height; size = width * height; f = new float[size]; offset = new int[height]; for (int j = 0; j < height; ++j) offset[j] = width * j; for (int k = 0; k < size; ++k) f[k] = random.nextFloat(); }
/*======== public void drawPolygons() ========== Inputs: EdgeMatrix pm Color c Returns: Go through the point matrix as if it were a polygon matrix Call drawline in batches of 3s to create triangles. 04/16/12 22:05:02 jdyrlandweaver ====================*/ public void drawPolygons(EdgeMatrix pm, Color c) { Random rndm = new Random(); Color rndmColor; float r, g, b; if (pm.getLastCol() < 3) return; for (int i = 0; i < pm.getLastCol() - 2; i += 3) { if (pm.calculateDot(i) > 0) { r = rndm.nextFloat(); g = rndm.nextFloat(); b = rndm.nextFloat(); rndmColor = new Color(r, g, b); scanLine(pm, i, rndmColor); } } }
public DMoteModel(int id, Random rand, DDocument root) { this.root = root; this.id = id; x = 20 + rand.nextInt(root.canvas.getWidth() - 20); y = 20 + rand.nextInt(root.canvas.getHeight() - 20); values = new float[root.sensed_motes.size()]; colors = new Color[root.sensed_motes.size()]; sizes = new int[root.sensed_motes.size()]; for (int i = 0; i < root.sensed_motes.size(); i++) { values[i] = rand.nextFloat() * 1000; colors[i] = setColor(values[i]); sizes[i] = setShapeSize(values[i]); } listeners = null; }
private float checkCube(float x, float y, int cubeX, int cubeY, Point[] results) { int numPoints; random.setSeed(571 * cubeX + 23 * cubeY); switch (gridType) { case RANDOM: default: numPoints = probabilities[random.nextInt() & 0x1fff]; break; case SQUARE: numPoints = 1; break; case HEXAGONAL: numPoints = 1; break; case OCTAGONAL: numPoints = 2; break; case TRIANGULAR: numPoints = 2; break; } for (int i = 0; i < numPoints; i++) { float px = 0, py = 0; float weight = 1.0f; switch (gridType) { case RANDOM: px = random.nextFloat(); py = random.nextFloat(); break; case SQUARE: px = py = 0.5f; if (randomness != 0) { px += randomness * (random.nextFloat() - 0.5); py += randomness * (random.nextFloat() - 0.5); } break; case HEXAGONAL: if ((cubeX & 1) == 0) { px = 0.75f; py = 0; } else { px = 0.75f; py = 0.5f; } if (randomness != 0) { px += randomness * Noise.noise2(271 * (cubeX + px), 271 * (cubeY + py)); py += randomness * Noise.noise2(271 * (cubeX + px) + 89, 271 * (cubeY + py) + 137); } break; case OCTAGONAL: switch (i) { case 0: px = 0.207f; py = 0.207f; break; case 1: px = 0.707f; py = 0.707f; weight = 1.6f; break; } if (randomness != 0) { px += randomness * Noise.noise2(271 * (cubeX + px), 271 * (cubeY + py)); py += randomness * Noise.noise2(271 * (cubeX + px) + 89, 271 * (cubeY + py) + 137); } break; case TRIANGULAR: if ((cubeY & 1) == 0) { if (i == 0) { px = 0.25f; py = 0.35f; } else { px = 0.75f; py = 0.65f; } } else { if (i == 0) { px = 0.75f; py = 0.35f; } else { px = 0.25f; py = 0.65f; } } if (randomness != 0) { px += randomness * Noise.noise2(271 * (cubeX + px), 271 * (cubeY + py)); py += randomness * Noise.noise2(271 * (cubeX + px) + 89, 271 * (cubeY + py) + 137); } break; } float dx = (float) Math.abs(x - px); float dy = (float) Math.abs(y - py); float d; dx *= weight; dy *= weight; if (distancePower == 1.0f) d = dx + dy; else if (distancePower == 2.0f) d = (float) Math.sqrt(dx * dx + dy * dy); else d = (float) Math.pow( (float) Math.pow(dx, distancePower) + (float) Math.pow(dy, distancePower), 1 / distancePower); // Insertion sort the long way round to speed it up a bit if (d < results[0].distance) { Point p = results[2]; results[2] = results[1]; results[1] = results[0]; results[0] = p; p.distance = d; p.dx = dx; p.dy = dy; p.x = cubeX + px; p.y = cubeY + py; } else if (d < results[1].distance) { Point p = results[2]; results[2] = results[1]; results[1] = p; p.distance = d; p.dx = dx; p.dy = dy; p.x = cubeX + px; p.y = cubeY + py; } else if (d < results[2].distance) { Point p = results[2]; p.distance = d; p.dx = dx; p.dy = dy; p.x = cubeX + px; p.y = cubeY + py; } } return results[2].distance; }