clojure-art

Nundrum 2022-12-08T22:20:36.077139Z

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:

genmeblog 2022-12-09T08:32:40.197329Z

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

👍 1
genmeblog 2022-12-09T09:20:41.329269Z

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

genmeblog 2022-12-09T09:21:55.432269Z

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

genmeblog 2022-12-09T09:29:04.556129Z

Deployed 1.4.5-SNAPSHOT

Nundrum 2022-12-09T17:55:52.461769Z

Thanks for that! I see how it works now.

Nundrum 2022-12-09T17:56:26.164729Z

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

genmeblog 2022-12-09T19:26:09.373819Z

Unfortunately, qr coordinates are skewed

genmeblog 2022-12-09T19:27:38.142539Z

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

Nundrum 2022-12-10T00:42:10.378329Z

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

👍 1
genmeblog 2022-12-09T07:53:36.018619Z

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

💡 1
genmeblog 2022-12-09T07:58:00.913519Z

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

Nundrum 2022-12-08T22:22:02.115029Z

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.