# Endless pattern based on prime numbers

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**

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:

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.