Endless pattern based on prime numbers
![image](https://habrastorage.org/webt/1y/-b/mn/1y-bmn-g2knaz4uzvzufwnpa-cu.png)
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 ++
longlong temp = x ^ y; // x и y координаты точки// Далее идет проверка temp на простоту одним из алгоритмов.// Например алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простотуif(isprime(temp) == true) {
// рисуем закрашенную точку
} else {
// оставляем точку пустой
}
This algorithm gives the following endless patterns:
Pictures with patterns![image](https://habrastorage.org/webt/pi/ob/o-/piobo-n-g1rvl60suyu9pdgxuie.jpeg)
![image](https://habrastorage.org/webt/mg/9k/mj/mg9kmjdiytj7fyohy0bdlxcj8ck.jpeg)
![image](https://habrastorage.org/webt/9l/7m/wv/9l7mwv54qcyiows1f3gvsbn6-l0.jpeg)
![image](https://habrastorage.org/webt/ik/y0/yr/iky0yrlz5hkqjgx14hxbkk6xphi.jpeg)
![image](https://habrastorage.org/webt/cp/rh/ph/cprhphwso163ft9tc6oo74pa4rw.jpeg)
![image](https://habrastorage.org/webt/qt/s-/eg/qts-eguisybu-6fqn4wvrm6cchu.jpeg)
![image](https://habrastorage.org/webt/pi/ob/o-/piobo-n-g1rvl60suyu9pdgxuie.jpeg)
![image](https://habrastorage.org/webt/mg/9k/mj/mg9kmjdiytj7fyohy0bdlxcj8ck.jpeg)
![image](https://habrastorage.org/webt/9l/7m/wv/9l7mwv54qcyiows1f3gvsbn6-l0.jpeg)
![image](https://habrastorage.org/webt/ik/y0/yr/iky0yrlz5hkqjgx14hxbkk6xphi.jpeg)
![image](https://habrastorage.org/webt/cp/rh/ph/cprhphwso163ft9tc6oo74pa4rw.jpeg)
![image](https://habrastorage.org/webt/qt/s-/eg/qts-eguisybu-6fqn4wvrm6cchu.jpeg)
You can also watch video with patterns:
Other designs
If you replace the XOR operation ( XOR ) with the operation OR or AND , you can get fractal triangles:
![image](https://habrastorage.org/webt/6o/ad/gs/6oadgs3z5fvz8nhtn8e_bmyakii.jpeg)
![image](https://habrastorage.org/webt/-q/5n/qb/-q5nqbkbgyrtuwyfmkwmaf4qv3c.jpeg)
You can also use any other checks instead of checking for a prime number, for example, division without remaining a certain 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.