I'm not grokking something about Clojure2D + fastmath.grid.
(def g (grid/grid :flat-hex 20))
(doseq [x (range 0 20)
y (range 0 20)]
(-> canvas (c2d/grid-cell grid x y true)
I'd expect that to draw a 20x20 grid of hexes. But I just get a tiny set of hexes:I see now that it's not clear enough. I'll update docs and maybe introduce another function for cell coordinates.
(let [grid (grid/grid :flat-hex 20.0)]
(with-canvas [c (canvas 600 600)]
(set-background c 0)
(doseq [q (range 0 20)
r (range 0 20)
:let [m (grid/cell->anchor grid q r)]]
(-> c (grid-cell grid (m 0) (m 1) true)))
(show-window {:canvas c})))Today I'll deploy a snapshot which will introduce grid-qr-cell function.
(let [grid (grid/grid :flat-hex 20.0)]
(with-canvas [c (canvas 600 600)]
(set-background c 0)
(doseq [q (range 0 20)
r (range 0 20)]
(-> c (grid-qr-cell grid q r true)))
(show-window {:canvas c})))Deployed 1.4.5-SNAPSHOT
Thanks for that! I see how it works now.
Is there some simple way to get the grid to align across the top?
Unfortunately, qr coordinates are skewed
Here is the list of other coordinate systems and conversion methods. Maybe I add them soon: https://www.redblobgames.com/grids/hexagons/#coordinates
I figured out how to do the odd-q layout finally 🙂 Thanks for all the help!
grid-cell expects screen coordinates and draws the enclosing cell.
size of grid is the size of the cell.
To convert grid coordinates you can call grid/cell->mid or grid/cell->anchor .
I can changes the ranges to something like (range 0 100 20) and I get more, but all the examples look like that shouldn't be necessary.