Example #1
0
  private float randomFromTo(double from, double to) {
    float random = Application.RANDOMGEN.nextFloat();
    double difference = Math.abs(to - from);

    random *= difference;
    random += Math.min(from, to);

    return random;
  }
Example #2
0
  public Painting paint(double width, double height) {
    Painting painting = new Painting(width, height);

    int backgroundColor =
        Color.HSBtoRGB(
            Application.RANDOMGEN.nextFloat(), randomFromTo(90, 100), randomFromTo(75, 100));
    painting.setCanvasColor(new Color(backgroundColor));

    for (int i = 0; i < 10; ++i) {
      // int fillColor = Color.HSBtoRGB(shapeHue(), randomFromTo(90, 100),
      // randomFromTo(75, 100));
      // int fillColor = r.nextInt(255);
      painting.addPaintInstruction(
          new ChangeColor(
              new Color(
                  Application.RANDOMGEN.nextInt(255),
                  Application.RANDOMGEN.nextInt(255),
                  Application.RANDOMGEN.nextInt(255))));

      float alpha = randomFromTo(90, 100) / 100;
      painting.addPaintInstruction(new SetTransparency(alpha));

      if (Application.RANDOMGEN.nextDouble() < 0.5) {

        double x = randomFromTo(width / 8, ((width / 8) * 7));
        double y = randomFromTo(height / 8, ((height / 8) * 7));
        double w = randomFromTo(width / 6, width / 3);
        double h = randomFromTo(height / 6, height / 3);
        Ellipse2D ellipse = new Ellipse2D.Double(x, y, w, h);
        painting.addPaintInstruction(new PaintShape(ellipse));
      } else {
        Polygon quadrilateral = new Polygon();
        for (int j = 0; j < 4; ++j) {
          quadrilateral.addPoint(
              Application.RANDOMGEN.nextInt((int) width),
              Application.RANDOMGEN.nextInt((int) height));
        }
        painting.addPaintInstruction(new PaintShape(quadrilateral));
      }
    }

    return painting;
  }