If you don't know the short story by Borges, you can read here.
So I wanted to model the infinite library in 3D with JavaSript, that is not at all suited for this task. It's not an accurate model of the library from the story, I mostly just kept the hexagonal rooms with three doors. It's a bit laggy and slow, but I'm really happy that it works. I had to methodically move and rotate things around again and again until everything was where it should be. It works better in Firefox, for some reason Chrome plays it very glitchy.
This is the 3D structure of the model. Four rooms, all have a hexagonal floor, three walls and three doors. It's only shown from the outside here. I had to mess around with the angles for hours to get them right.
Here you are inside the structure, but the illusion of infinity is only haflway done. It works the following way: when you start going into a room, you are teleported immediately into the room you are headed to, you get rotated by 180 degrees, and actually go back into the central room. And since all rooms look identical, if the program works correctly, you don't notice that you suddenly changed rooms and directions, it looks as if you just went into a completely new room. Well, here the floortiles have different bright colors, so you can see it. And the "new" rooms seem to appear out of nowhere. But if I change them around well, the illusion is perfect.
I constructed 30 floortiles in photoshop, this is only a page where they can be viewed as a collection. They are actually SVGs, because I love SVGs. This means that they don't need to be uploaded as images, they can be simply inserted as text into the code, and they can be scaled to any size without quality loss. The floortiles have to be radially symmertical, because only this way won't the position and direction change be noticable (if I want to avid messing with the floortile rotation).
The above mentioned floortiles applied to the floors of the library rooms. They change place when you go from one room into another, so it looks as if you enter a new room, instead of going into the very same central room. The two further rooms fade into view, and that was harder to solve that I first thought, because for some reason opacity can't be animated on complex 3D objects, so I had to go through all the walls and floors one by one.
The proof-of-concept for bookshelf generation. Refresh the page to generate a new pattern.
I'm really happy with how I solved this. The bookshelf itself is also an SVG, and all the books are originally colored to limegreen, a color not used in the floortiles at all. I wrote a function that takes a floortile SVG, and collect the colors from it (it actually just recognizes the parts of the text formatted as "rgb(something, something, something)"). And then a different function randomly recolors the books on the bookshelf one by one to one of the floortile colors. And that's still just text-editing, because SVGs can be handled and edited as text.
The implementation of the bookshelves above. This is the final version linked from the main page. The books match the color of the floor, and when you go from one room to an other, they move with the floortiles to kep the illusion up. And they work well!