Fork me on GitHub
#off-topic
<
2021-06-01
>
Stuart09:06:33

ANy recommendations for stuff to look into if I want to have a grid in html that is big'ish, 20x20, where each cell is clickable? Something like this: right now I just have it generating 400 divs then i partition them by 20 for each row... What's a smarter way for a frontend n00b to look into?

hindol09:06:00

Also a frontend beginner. I would probably use a canvas for the grid.

👍 3
Stuart09:06:51

can you detect where the user is clicking on a canvas? I want them to be able to click squares and toggle thembetwen open and maze wall

Stuart09:06:40

eventually i want to draw lines on the maze to show the solved route, which WOULD be easier on a canvas.

hindol09:06:52

Yes, basically you can get the pointer x, y and need to do the math in code.

hkjels09:06:15

Canvas, as you point out makes it more difficult to handle pointer actions

hkjels09:06:25

I suggest you use svg instead

hkjels09:06:02

there you could draw with a similar api, but also have pointer-events for the individual elements

hkjels09:06:42

otherwise, using partition this way is just fine

Stuart09:06:49

so i could use the divs for the squres, but maybe draw the route using svg? or would it be one or the other?

hkjels10:06:35

You could mix, but it’s easier to just buy in on svg

hkjels10:06:44

Creating a square in svg is trivial

slipset10:06:18

Backender myself, but I think you’d enjoy http://www.parens-of-the-dead.com/

👀 3
hkjels11:06:53

That’s pretty cool

rafalw11:06:10

not sure if good fit in this case, but worth checking http://quil.info/

☝️ 3
phronmophobic18:06:17

If you're only drawing vertical and horizontal lines, you can use divs with borders and/or background colors to draw lines.

phronmophobic18:06:00

there's also css to rotate divs for non vertical/horizontal lines, but at that point, SVG is probably a better fit

gklijs20:06:50

Canvas is pretty easy. https://gameoflife2d.gklijs.tech/ play/pause and you can turn cells active/dead. Source https://github.com/gklijs/game-of-life/blob/2d/www/index.js

sova-soars-the-sora22:06:02

Seems like a decent solution already if you're just capturing clicks and don't care too much about render time. Lots of divs = more repainting / processing on the DOM level, but it might be perfectly fine for what you're doing. Are you wondering what the fastest implementation might be? or the most convenient to code? or some balance point between/betwixt?

☝️ 2
Stuart23:06:54

Really more that I'm quite newish to front end stuff and I don't really have anyone to ask that has up to date experience. So I often sit and try to make things all the time wondering "Am I being a total idiot here" with my implementations.

djblue19:06:31

I built https://djblue.github.io/tetris/ in cljs as a table of divs and it works well enough 😆 10 * 24 = 240 elements in the grid.

pez13:06:45

You are not being an idiot. 😃 And there are lots of way to do it. I bet some CSS magician can do it with gradients or something.

Stuart13:06:27

well, i got somethign that sorta works. https://stuartstein777.github.io/maze-solver/ Guess what they say, if it works, it isn't stupid 🙂

🎉 5
Stuart09:06:09

I'm basically doing this for now:

Stuart09:06:22

So using flex container