Fork me on GitHub
#clojure-art
<
2022-12-08
>
Nundrum22:12:36

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:

genmeblog07:12:36

grid-cell expects screen coordinates and draws the enclosing cell. size of grid is the size of the cell.

💡 1
genmeblog07:12:00

To convert grid coordinates you can call grid/cell->mid or grid/cell->anchor .

genmeblog08:12:40

I see now that it's not clear enough. I'll update docs and maybe introduce another function for cell coordinates.

👍 1
genmeblog09:12:41

(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})))

genmeblog09:12:55

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})))

genmeblog09:12:04

Deployed 1.4.5-SNAPSHOT

Nundrum17:12:52

Thanks for that! I see how it works now.

Nundrum17:12:26

Is there some simple way to get the grid to align across the top?

genmeblog19:12:09

Unfortunately, qr coordinates are skewed

genmeblog19:12:38

Here is the list of other coordinate systems and conversion methods. Maybe I add them soon: https://www.redblobgames.com/grids/hexagons/#coordinates

Nundrum00:12:10

I figured out how to do the odd-q layout finally 🙂 Thanks for all the help!

👍 1