Re: Drawing a honeycomb



In article
<f581fd74-7a37-47ed-8d35-677d1c33b905@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
MikeB <MPBrede@xxxxxxxxx> wrote:

On Apr 6, 1:55 pm, Roedy Green <see_webs...@xxxxxxxxxxxxxxxxxxxx>
wrote:
On Mon, 6 Apr 2009 11:29:41 -0700 (PDT), MikeB <MPBr...@xxxxxxxxx>
wrote, quoted or indirectly quoted someone who said :

I want to create a pane that, instead of  a table of rows and columns,
have a honeycomb appearance, in other words an array of hexagonal
cells. I need to put information inside each cell, but I'm even stuck
at how to construct the borders of the cells. Ideally, the borders
should be sizable so that the user can adjus tthe size (and by
implication, the number of cells that will appear in the pane, or when
he resizes the pane.

You might have a start athttp://mindprod.com/products.html#SCREWS

It draws a hexagonal screw head.

A hexagon is defined as a line connecting vertices of the 6 rotations
of the angle pi/3 radians = 60 degrees where it intersects the circle.
Basically you convert polar to Cartesian co-ordinates.

Seehttp://mindprod.com/jgloss/coordinates.htmlhttp://mindprod.com/jgloss/pol
ar.htmlhttp://mindprod.com/jgloss/radian.html

Tackle this in stages.

1. draw a hexagon on a Canvas of JPanel.
2. draw a row of 4 hexagons
3. draw two rows of 4 meshing hexagons.
4. draw a grid of n x m hexagons.
5. draw a grid of hexagons with text on them.
6. resize the panel making all the hexagons grow
7. resize the panel adding hexagons.
8. resize the panel allowing both kinds of growth. How will you
specify it? sliders?  Simply dragging the panel bigger will not do.
9. don't draw cells that don't fit 100 in the panel.
10. sex it up with some edge effects and subtle colour variations.
Search the web for some honeycomb images to get some ideas.
[...]

Roedy, Thanks a million. Just what I needed.

For step one, I recall that turtle graphics made it especially easy to
draw regular polygons, as there's a simple formula for the interior
angle:

<http://en.wikipedia.org/wiki/Regular_polygon#Angles>

I'd be surprised if there weren't a Java implementation.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
.



Relevant Pages

  • Re: Drawing a honeycomb
    ... at how to construct the borders of the cells. ... draw a hexagon on a Canvas of JPanel. ... draw two rows of 4 meshing hexagons. ... resize the panel adding hexagons. ...
    (comp.lang.java.help)
  • Re: Drawing a honeycomb
    ... at how to construct the borders of the cells. ... draw a hexagon on a Canvas of JPanel. ... draw two rows of 4 meshing hexagons. ... resize the panel adding hexagons. ...
    (comp.lang.java.help)
  • Re: Drawing a honeycomb
    ... at how to construct the borders of the cells. ... You can approximate to a hex grid with a square grid offset by half a ... corners of your hexagons. ...
    (comp.lang.java.help)
  • Re: Nearest point to the mouse cursor?
    ... > It is very easy to get X and Y coordinates when the cells are rectangles: ... > that pattern is represented in the Rows array. ... >> I'm also drawing the hexcells in a panel, not a form and although I've ... > you draw your 50X50 board to the bitmap, and then copy it over to the panel ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Drawing a honeycomb
    ... Another way to think of it is to draw a line of alternating up down ... bottom of the top line buts a top of the bottom line. ... That gives you "grid" on which you can draw your hexagons. ... If the long-term trend continues, all fish and seafood species are projected to collapse ...
    (comp.lang.java.help)