📜 ⬆️ ⬇️

Rubik's Cube on canvas

Recent posts about the 5 × 5 cube assembly algorithm made me write a cube emulator for canvas . The author of articles about the assembly offered his cube on OpenGL, but I didn’t like it to many. I hope with my someone will be able to master the algorithm faster. Some features and benefits:
I do not know whether to talk about the features of the development. There were many difficulties, but all are quite minor. For some reason, I was too lazy to use homogeneous coordinates, which is why, in particular, the projection is orthogonal, and not perspective. The rendering model is also a bit strange. In general, the cube is represented as 6, 12 or 18 faces, and each face contains up to size ^ 2 elements, each element is a square. On the internal sections, which can be seen when rotating, the element is only one area on the entire face. 9 visible faces are signed here, the remaining 9 are arranged symmetrically to them:

It also took to sort the faces in the correct order so that the invisible parts were correctly removed. Here the correct order is along the axis of rotation (if there is no rotation, the order is unimportant).

The scope of the faces is unscientific: it is simply a circular gradient of canvas, the center of which deviates in the direction of the normal. Honestly considered illumination by BRDF seemed unreasonable for this task.

What else would you like to do, but laziness:
If anyone wants to do something, then please. If you have questions about the code, ask, I will answer with pleasure.

')

Source: https://habr.com/ru/post/100576/


All Articles