Fork me on GitHub
#off-topic
<
2022-10-12
>
tengstrand07:10:51

We have a full day workshop at work where we are going to build https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life in different languages. I will choose Clojure of course, but is there a good library out there that allows me to animate the grid of cells. It doesn't have to be fancy, but flicker free animation (e.g. double buffering) would be to prefer.

tengstrand07:10:54

I want to do it as a backend project.

borkdude07:10:50

I've not used it myself yet, but perhaps #C033FTUBWH5?

tengstrand07:10:14

Okay cool, will have a look! Thanks.

mdiin07:10:34

How about http://www.quil.info/? I haven’t used it, but looking at the live sketch it seems like a good fit, with the abstraction of update-state transitioning to the next game state and draw-state to draw the game state.

6
tengstrand07:10:03

Yeah, remember that now, but haven't used it.

Martynas Maciulevičius08:10:33

You can also display the field directly by having a vector of vectors like this:

[[_ _ _ _ * _]
 [_ _ _ _ * _]
 [_ _ * * * _]
 [_ _ _ _ * _]
 [_ _ _ _ * _]]
Then you don't only have the UI, but you don't need any library at all (underscore and * could be symbols. You could also use space)

tengstrand08:10:37

Quil really looked great! E.g. http://nbeloglazov.com/2014/05/29/quil-intro.html intro. Only a couple of lines of setup code and then just use the rect function to draw squares, should solve the problem.

mdiin08:10:45

Cool! Sounds like a good workshop topic. Have fun! 🥳

Niki20:10:30

Humble UI with Canvas component should work. I don’t have minimal repo yet though

Niki23:10:18

Strike that, I now have Ants demo with Humble UI. Should be easy to adjust to do any drawing with Skija https://github.com/tonsky/humble-ants

metal 3
quoll22:10:39

I did this many years ago in https://github.com/quoll/life, and then https://quoll.github.io/life/ (same project). For the Clojure version https://github.com/quoll/life/blob/master/src/life/pic.clj, which I think was a reasonably small amount of code. (Well… the file with AWT was 90 lines long, which I guess it a lot of Clojure). The nice thing about the ClojureScript version is that it used svg, which meant that I could turn cells on and off with a mouse 🙂

quoll22:10:27

I actually did it to prove to myself that I could transliterate a video of Life using APL

quoll22:10:02

(The ClojureScript link above is a live page)

quoll22:10:34

Quil or Humble would make the Clojure version much easier 🙂

phronmophobic23:10:17

fwiw, I think https://github.com/phronmophobic/membrane would be a good fit. The benefit of using membrane is that views are values and the UI can run anywhere. I just added an example game of life project https://github.com/phronmophobic/membrane/tree/master/examples/gol which is originally from a https://github.com/phronmophobic/grease of running clojure on iOS. It's also easy to share. Try it:

clj -Sdeps {:deps\ {com.phronemophobic.membrane/gol\ {:mvn/version\ \"1.0\"}}} -M -m membrane.gol

quoll19:10:46

If you get time, I recommend watching the APL video. Just to freak yourself out, if nothing else 🙂 https://www.youtube.com/watch?v=a9xAKttWgP4

tengstrand02:10:24

Wow! Really cool!

quoll04:10:59

My motivation for my own version was to prove that I could duplicate it in Clojure. I learned a bit of APL in the process 🙂

👍 1
Drew Verlee22:10:51

i'm getting a 403 (forbidden) for a request response websocket handshake and i'm trying to understand if it's realted to cors. In short request url: https://foobar request origin: https://foo request method: get -------> response access-control-allow-origin: https://foo response access-control-allow-methods: get <-------------- my only thought is that the request url doesn't match the allowed origin in the response. But i thought that wouldn't matter, as in what were checking is if the request from this origin (foo) is ok, and the sever does say foo is ok.

phronmophobic22:10:16

I thought an error message would show up in the dev console. does it show any helpful info in the networking panel of the dev console?

p-himik22:10:38

403 and CORS should be unrelated.

👍 1
hiredman22:10:04

there is an Origin request header (which is different from the cors stuff) that is a thing with websockets, which some docs and sample websocket apps use in a sort of cors kind of way, and some servers might check it

Drew Verlee22:10:14

The response on the failed get request is "Unauthorized Origin" which originates in sente (which yea is websockets).

p-himik22:10:53

Dang it, beat me by a few seconds. :D

hiredman22:10:27

it is a pretty weak form of authorization, since Origin is set by the client, so the expectation is that the browser is trust worthy even though the js it runs might not be

👍 1
👀 1
Drew Verlee22:10:04

yeah. thanks hired 🙂 Thats what i'm using. I think i see the issue. it's not being surfaced in the networking tab (i think?) but if i trace the variables i'm likely doing this.

(allow-origin? #{""} {:headers {"origin" ""}})
  ;; => false            ^^^ this is what's set as allowed origin                       ^^^ this is the origin that gets passed in the request 

Drew Verlee22:10:14

i need to figure out how to drop into a running repl on my server. i shouldn't be guessing or tracing things if i don't have to be.

hiredman23:10:31

websockets are a nice way to expose a repl

👍 1