Membrane game - awesome game for autists in 20 lines of code

The game code is written entirely in the language of mathematics . Let's break it down.





  1. N is responsible for the size of the cells.





  2. pow (1.02, iTime) creates uniform animation of cells, 1.02 - animation speed; sooner or later this causes a buffer overflow, but the animation can be turned off by making t = 1 or made so that it slows down with time t = iTime.





  3. dx and dy - x and y offset of the cursor position.





  4. float f = float ((x-dx) * (x-dx) * t + (y-dy) * (y-dy) * t); // These are the rules of the game - in this function (not actually a function) you can make changes and get new game logic.





  5. float F = abs (f * sin ((x) / N) * sin ((y) / N)); // Creates a cell membrane for function (not function) f.





  6. int R = int (floor (F * pow (16.0, 6.0-ceil (log2 (F) /4.0)))); // Adapt membrane colors by adding zeros at the end of the hexadecimal notation or trimming it to the right. Basically it is a ready-made X11 color index used in HTML or Photoshop.





In short, everything is simple. I'm actually new to both math and GLSL, but my friends liked this game, and I'm wondering how Habr will rate it. If you have any ideas, you can fork it. For those who want to try to transfer to other programming languages, I will warn you that such calculations for each pixel are very difficult for the processor - you need to program shaders (well, personally, my experience, but in general I do not mind)








All Articles