⬆️ ⬇️

Endless pattern based on prime numbers

image


Hi, Habr! One morning, I had the idea to find an " exclusive OR " between the coordinates of a point in space and check the resulting number for simplicity. The result of such a simple algorithm you can see in the picture. More under the cut.



Pattern Generation Algorithm



Algorithm in C ++



long long temp = x ^ y; // x  y   //    temp     . //   --- (BPSW)  n   if(isprime(temp) == true) { //    } else { //    } 


This algorithm gives the following endless patterns:



Pictures with patterns
image

image

image

image

image

image



You can also watch video with patterns:

')





Other designs



If you replace the XOR ( exclusive OR ) operation with the OR or AND operation, you can get fractal triangles:



image


image


You can also use any other checks instead of checking for a prime number, for example, division without remaining a number by any number. But such options give less varied patterns.



Program and source



To test the pattern generator, I wrote a simple program that can be downloaded along with the source here . To work with images using the library OpenCV.

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



All Articles