In my previous challenge, I drew the first diagram mostly by hand (with the help of vim's visual block mode). But surely there must be a better way...
Given an input of two dimensions, a width and a height, output a hexagonal grid with those dimensions in ASCII art.
Here's the diagram referenced in the intro (with minor edits), which should be
your output for the input width=7, height=3
:
_____ _____ _____
/ \ / \ / \
_____/ -2,-1 \_____/ 0,-1 \_____/ 2,-1 \_____
/ \ / \ / \ / \
/ -3,-1 \_____/ -1,-1 \_____/ 1,-1 \_____/ 3,-1 \
\ / \ / \ / \ /
\_____/ -2,0 \_____/ 0,0 \_____/ 2,0 \_____/
/ \ / \ / \ / \
/ -3,0 \_____/ -1,0 \_____/ 1,0 \_____/ 3,0 \
\ / \ / \ / \ /
\_____/ -2,1 \_____/ 0,1 \_____/ 2,1 \_____/
/ \ / \ / \ / \
/ -3,1 \_____/ -1,1 \_____/ 1,1 \_____/ 3,1 \
\ / \ / \ / \ /
\_____/ \_____/ \_____/ \_____/
Notice several things:
The width and height are essentially equivalent to how many hexagons there are for a given y and x coordinate respectively. These will always be odd numbers.
Each hexagon is represented by the ASCII art
_____ / \ / \ \ / \_____/
but borders are "shared" between neighboring hexagons.
The comma in the coordinates is always exactly two characters below the center of the top edge. The x-coordinate is then positioned directly before the comma, and the y-coordinate directly after.
You may assue that the coordinates will never be too large such that they would overlap the hexagon's borders.
Input may be taken as a whitespace-/comma-separated string, an array of integers, or two function/commandline arguments. Output must be a single string (to STDOUT, as a return value, etc.).
Since this is code-golf, the shortest code in bytes will win.
The grid above can be used as a test case. The maximum-sized
width=199, height=199
grid is obviously impractical to include here, but the
first few rows and columns should look like the following:
_____ ___
/ \ /
_____/-98,-99\_____/-96,
/ \ / \
/-99,-99\_____/-97,-99\___
\ / \ /
\_____/-98,-98\_____/-96,
/ \ / \
/-99,-98\_____/-97,-98\___
\ / \ /
\_____/-98,-97\_____/-96,
/ \ / \
/-99,-97\_____/-97,-97\___
\ / \ /