I want to make a project that will draw a kaleidoscope. I would need to draw some shapes inside a triangle and then reflect that triangle in six directions to make a hexagonal display.
I don't know how to draw shapes within a triangle so that any part of the shape that extends beyond the boundary is not drawn and I don't know how to reflect the shapes to make a hexagon.
If you have a Graphics2D (for instance from a BufferedImage) you can give it a clip (see the api) and that clip can be any shape, like a triangle. Anyrhing you draw in that G2D will be clipped inside that shape.
There are three kinds of actuaries: those who can count, and those who can't.
1) determine the size of your equilateral triangle, say W and H.
2) create the triangle as a Path2D.Double, with coordinates (W/2, 0), (0, H), (W, H) and close it.
3) create a BufferedImage buf, type INT_ARGB, with width W and height H
4) get its g2d, set the triangle as clip and draw all the colours and shapes to it that you want.
5) create the main BufferedImage mainBuf, with height 2*H, and sufficient width. We now draw 6 times buf to its g2d, the first one at (0, H), then rotate mainBuf PI/3 around its center (as Tim said, there are methods in the g2d that make this possible) and draw buf again, at (), H). By doing this six times, mainBuf has now 6 copies of the triangle, all neatly rotated around mainBuf's center.
6) draw mainBuf in your JPanel
7) global health warning: I typed this out of my head, and therefore there are no guarantees! If it doesn't work like I had in mind, let us know what problem you emcountered.
There are three kinds of actuaries: those who can count, and those who can't.