0

I was wondering if this idea is possible and relatively easy to implement, some nice texture effects could be revealed with it. The purpose is to "emulate" a regular hexagon tile grid (instead of the classic rectangle) starting with with a special pre-processed image (sample attached). This image should support alpha transparency, inside there is a "regular hexagon" area drown with anything, while areas outside this "internal hexagon" boundary will be fully transparent in order to overlap smoothly and create a honeycomb style repetition. As far as I can see, and not having real experience, a guess is that we need to implement a new Paint Class in order to make this special texture fill. The center of this "virtual hexagon" will be the center of the rectangular image (the BufferedImage in TexturePaint).

Instead of tiling as usual with TexturePaint, the new Paint should place those tiles not in order side by side but with overlapping areas.

(just for reference)

How to add an image into a hexagon in a hexagonal grid?

Creating a hexagonal grid pattern

How can I get the grid coordinates of a hexagon tile by a pixel point in Java?

Create hexagonal field with flat tiles with JavaFX

Algorithm to generate a hexagonal grid with coordinate system

The question is, is it applicable to implement a new "hexagonTexturePaint implements Paint" class in order to do a hexagon tiling like this? and if so could you rise some fundamental key points on how to accomplish this? Here we do not try to implement a new hexagon grid, but just to emulate the placement of a tiled image differently, not side by side but with overlaps.

For convenience, an image with transparent areas and a solid hexagon has been attached alongside with its 2x2 classic square grid tile. Theoretically in the new hexagon alternative, the tiled image should not have empty areas and "half hexagon areas" should be filled also.

For code not much at this point, just some findings for a custom Paint here: Java custom Paint implementation performance issue Maybe it is a good starting point.

public class OrientableTexturePaint implements Paint {

    private TexturePaint texture;
    private float orientation;

    public OrientableTexturePaint(TexturePaint paint, float orientation)
    {
        texture = paint;
        this.orientation = HelperMethods.clampRadians((float)Math.toRadians(orientation));
    }

    public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) 
    {
        AffineTransform newTransform = (AffineTransform)xform.clone();
        newTransform.rotate(orientation);
        return texture.createContext(cm, deviceBounds, userBounds, newTransform, hints);
    }

    public int getTransparency() 
    {
        return texture.getTransparency();
    }
}

TexturePaint Class Source: https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/java.desktop/share/classes/java/awt/TexturePaint.java

Hexagon area predefined image

Classic tiling with empty spaces

jazznbass
  • 1
  • 3

0 Answers0