Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
  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();
  }
Ejemplo n.º 4
0
  /*======== 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);
      }
    }
  }