I saw this online somewhere and I just had to recreate it. This is my coding happy place.

You can see it live here: https://pong-wars.koenvangilst.nl/

Source code is just plain html, css and JavaScript, so you can see it in your browser.

Pong wars | Koen van Gilst

The eternal battle between day and night, good and bad. Written in JavaScript with some HTML & CSS in one index.html. Feel free to reuse the code and create your own version.

Since this is taking off, I have to give credit where it is due. I saw this first on Twitter here:

https://twitter.com/nicolasdnl/status/1749715070928433161

Nicolas Daniel (@nicolasdnl) on X

The endless fight for #genuary23 #genuary #genuary2024 It's not an original idea, I've seen this before but couldn't put a hand on it.

X (formerly Twitter)
@vnglst I like that you started your initial state with each having a tiny protrusion into the other, like two E.T.s 69ing.

@abananabag I didn't expect to read this today.

Another pixel of innocence lost, and I'm not sorry.

@vnglst the more I stare at this the more I think it could turn into a hashing algorithm. Maybe with 16 colors....
pong-wars/index.html at main ยท vnglst/pong-wars

Contribute to vnglst/pong-wars development by creating an account on GitHub.

GitHub
@vnglst Is there some way this could become a screen saver? Something moderately simple I could do, I mean, I'm not suggesting more work for you!

@vnglst Could you add an open source license to your repository?

I re-implemented your project in C++/OpenGL as a learning experience. I reused your updateSquareAndBounce method and would like to know with which license I can publish my implementation. Anything between MIT and GPL is fine with me :)

@carlschwan will do that, itโ€™s MIT, feel free to do whatever you want with it!
@vnglst Canโ€™t believe how exciting this is to stare at :D
@vnglst just plain html, css and javascript? no external physics library? Cool! How did you check for ball/wall collision? I'm currently writing Arkanoid in Svelte as my school project and would like some tips
@michaln You should be able to get pretty far with some math. The gist is in this function: https://github.com/vnglst/pong-wars/blob/d23262598cb20f124af9c0e2c80def59abc716af/index.html#L119
pong-wars/index.html at d23262598cb20f124af9c0e2c80def59abc716af ยท vnglst/pong-wars

Contribute to vnglst/pong-wars development by creating an account on GitHub.

GitHub
@vnglst @michaln really fascinating, game and code. Surprised about the random factor, during bounce, I first thought only initial state was random
@gerbrand @michaln That was an attempt to avoid balls from getting stuck in a loop. Not too happy about it, would prefer to have a deterministic version.

@vnglst @gerbrand @michaln Still got stuck in a loop but it got unstuck as soon as I took the screenshot (iOS). Maybe a small timing delay by the OS that caused the necessary conditions to exit the loop.

I can stare at this for hours!

@vnglst @gerbrand @michaln

Stable state!

Loved this, thanks 

@vnglst huh, checking several points around the ball for intersections. It's a lot more reallistic than what I went with ๐Ÿ˜…
I just check if the line between the current and future position crosses the block boundary (and I made the bricks have a gap). it was somewhat easy to calculate, but the corners will behave unreallistically with my approach ๐Ÿ˜…
well, I guess it's fine for a high school project, right?

@vnglst

Two player Arkanoid! Brilliant.

@vnglst Now I am just laying here watching and seeing how much day and night can get.
@vnglst Is there any stop condition, or does the war go on forever?

@vnglst I guess it never stops, right? One should be aware of that before starting to watchโ€ฆ

That said, it is really fascinating to watch. Especially after a while, when one player gets โ€œtrappedโ€ in a small area. But as the area is small, it does not take long before it has enlarged it again, and joined with nearby exclaves. Etc.

@vnglst This is getting exciting
@tml @vnglst at some point, it will go into a loop, at least for me (cannot upload video to mastodon, but here it is: https://github.com/vnglst/pong-wars/assets/86577857/433db503-9c39-4765-897c-82fdde8943da )
@tml @vnglst I found it incredibly engrossing, and rather than it being about one gaining ground over the other, I was watching them slowly rotate the whole playing area
@tml @vnglst as there is a finite number of states, it must enter into a loop at some point. Koen did you try to find loops?
@HydrePrever @tml @vnglst Fascinating indeed. I think you have to consider the transitions that depend on the position and direction of each ball too, and that sounds like many more possible combinations.
@HydrePrever @tml I did add little randomness to avoid that
@vnglst @tml cool! (or not, depending, short loops would be deceptive to watch but long loops would be cool) (also, nitpicking mode, you just multiply the number of possible states by the number of states of the PRNG so it's still finite ๐Ÿ˜)
@vnglst For me it has twice (out of maybe four runs over 10 minutes) gone into a state where one ball just moves almost perfectly vertically or horizontally, and the other one more diagonally, too. I wonder how stable such a state is.
@vnglst Canโ€˜t really tell whether you saved or ruined my Sunday. Itโ€™s so amazing and satisfying Iโ€˜ll spend the rest of the day watching.
@vnglst
More Breakout than Pong, right?

@vnglst
I like this so much.

*watch it and waiting for an end that doesn't exist

@vnglst "How did you spend your weekend?
I watched two dots making war at each other in a square".
@vnglst seems like dark side is winning.
@vnglst Nice. I spent 10 minutes considering whether the seemingly nondeterministic behavior was due to javascript implementation rounding errors and canvas size before realizing it calls Math.random()

@vnglst

What's the victory condition? Cause I don't see how one side will ever win?

@TobiWanKenobi Itโ€™s the eternal battle between day and night, good and bad
@vnglst @TobiWanKenobi
My immediate thought was Ukraine and Russia

@vnglst @TobiWanKenobi
Yin & Yang.

Just have to make the arena a circle.

@vnglst @TobiWanKenobi Worst thing ever Iโ€™ve just wasted 10 minutes of my life and Iโ€™m planning to waste another half an hour. But I like the idea of winning. What if area gets separated from the main area without the ball in it it will turn into the opposite color? And gaining more than 90% would mean winner?

Man this is so frustrating have to run it again.

@vnglst @vicgrinberg What a great idea! Might have to try and make my own versionโ€ฆ ๐Ÿ˜
@vnglst Mesmerizing! ๐Ÿ˜

@vnglst

Simple, brilliant idea!

@vnglst This is an amazingly cool idea. How could I never have heard/thought about it? Itโ€™ll make a great demo for old computers!
@vnglst this is great, guessing this was the inspiration https://x.com/nicolasdnl/status/1749715070928433161
Nicolas Daniel (@nicolasdnl) on X

The endless fight for #genuary23 #genuary #genuary2024 It's not an original idea, I've seen this before but couldn't put a hand on it.

X (formerly Twitter)
@andybaio @vnglst heh, the first thing that came to mind for me was https://mathgames.falj.net/2021/06/12/pong-bw/ , which I saw from @waxy
pong B&W โ€“ mathgames

@pronoiac @vnglst I found that link in the replies to that tweet!