Example #1
0
  /**
   * Draw the given shape, filled with the specified colour.
   *
   * @param s The shape to draw.
   * @param col The colour to fill the polygon with.
   */
  public void drawShapeFilled(final Shape s, Q col) {
    col = this.sanitise(col);
    if (s instanceof Polygon) {
      this.drawPolygonFilled((Polygon) s, col);
    } else {
      this.drawShape(s, col);

      final int minx = (int) Math.max(0, Math.round(s.minX()));
      final int maxx = (int) Math.min(this.targetImage.getWidth(), Math.round(s.maxX()));
      final int miny = (int) Math.max(0, Math.round(s.minY()));
      final int maxy = (int) Math.min(this.targetImage.getHeight(), Math.round(s.maxY()));

      for (int y = miny; y <= maxy; y++) {
        for (int x = minx; x <= maxx; x++) {
          final Pixel p = new Pixel(x, y);
          if (s.isInside(p)) this.targetImage.setPixel(p.x, p.y, col);
        }
      }
    }
  }