Programmer [aemkei] Tweeted the formula `(x ^ y) % 9`

alongside code for more “alien art”. But how can a formula as simple as `(x ^ y) % 9`

result in a complex design? The combination of Bitwise XOR (`^`

) and Modulo (`%`

) generate a repeating pattern that’s still complex enough to satisfy the eye, and it’s ok if that doesn’t sound like an explanation. Bitwise operations are useful when working with memory and shift registers, but also worth learning if you want to drive lines or matrices of LEDs or interpret combinations of multiple switches, or in this case a great way to throw an interesting test pattern up on a new flip-dot display or low-res LED matrix. Are you into it? We are, so let’s jump in.

0b00 | 0b01 | 0b10 | 0b11 | |
---|---|---|---|---|

0b00 | 0b00 | 0b01 | 0b10 | 0b11 |

0b01 | 0b01 | 0b00 | 0b11 | 0b10 |

0b10 | 0b10 | 0b11 | 0b00 | 0b01 |

0b11 | 0b11 | 0b10 | 0b01 | 0b00 |

Bitwise XOR compares each binary digit of the two inputs. The XOR returns a 1 when only one of the two digits is a 1, otherwise, it returns a zero for that position. Let’s say the coordinates were 3, 2. Converted to binary we have 0b11 and 0b10. From this truth table, we can see the most-significant digits are both 1, returning a 0, while only one of the least-significant digits is a 1, so the comparison returns a 1.

Moving onto the %, which is the Modulo operator has nothing to do with percentages. This operator divides two numbers and returns the remainder if any. Take `9 % 5`

. When dividing 9 by 5, 5 goes in once with a remainder of 4 so `9 % 5 = 4`

. Now our original formula from the top will draw a black box for every ninth number except that the bitwise XOR throws a wrench into that count, varying how often a number divisible by 9 appears and supplying the complexity necessary for these awesome patterns.

What are the most interesting designs can you create in a simple formula?

Very nice! That reminds me of “Algorithmic symphonies from one line of code”: http://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html

(x ^ y) % 9 might also sound interesting :)

Me too. I actually wrote some BNF a while ago to randomly generate bytebeat strings. Never produced anything profound, unfortunately.

Could do something similar for these.

This makes me want to press play on Conway’s Game of Life. :)

Thanks for the art.

I still find z’ = z^2 + c pretty much interesting ;-) (that’s the one for the Mandelbrot fractal)

This is awesome!

I collected a few patterns of my own here: https://maumagnaguagno.github.io/colorex

Still converting my code to canvas to avoid downloading big image files and eventually letting people play with the formulas.

Rule 90 from Wolfram cellular automata is my preferred one:

https://en.wikipedia.org/wiki/Rule_90

Kinda lookslike taken straight from the copy protection code wheel from Indiana and the Fate of Atlantis.

Ooga booga!

I did a couple of the algorithms in CPC Basic (in CPCBox online emulator) whilst suffering some work teams training meeting.

https://twitter.com/sykobee/status/1381942991770763266

https://twitter.com/sykobee/status/1381953438590832643

How can i NFT this ? Lol!!!

But what about that pesky patent on the XOR operation?

How about posting interesting patterns that we come across…

Here’s one (x | y) % 9)

This reminds me of some minimal C programs with lots of % spitting out a waveform that sometimes did sound surprisingly well. A one dimensional sibling of the above?

…unluckily I haven’t bookmarked it.

Fortunately the very first reply mentions someone else doing the same. (“bytebeat”)

Very interesting, this class of pattern generators seem to be a form of numerical moire and there is a huge set of possible results. Generate 4 numeric sequences with any function you like so long as they generate a repeating sequence (even just one that is transformed before reuse), then use them to plot the interaction between x0,y0 and x1,y1 with any transform you like applied to x1,y1 sequences, such as scale or rotate, i.e. a simple matrix operation. Should be able to do it in assembler and compact enough for it to stay in a modern processors top level cache while using instructions intended for parallelization. Worth looking at how this would perform directly on a GPU too given how simple the entire class of pattern code is.

Kaliset fractals with their variations (like adding orbital trap calculations) can produce some rather surprisingly complicated designs with simple mathematics (though not as simple as the one described in the article):

http://www.fractalforums.com/new-theories-and-research/very-simple-formula-for-fractal-patterns/60/

Another similarly inspiring computer generated art pattern was this one, ‘Serendipitous Circles’ from BYTE August 1977.

The 6800 assembly code presented there gave a dynamically changing real-time output on a XY scope screen:

https://archive.org/details/byte-magazine-1977-08/page/n71/

Sorry but I’m new to all this.What does the b stand for? 9 is a number with synchronistic ties to aliens and the paranormal

Would like to be able to have a C program on Linux set pixels directly, to support explorations like these. Must be possible yet these days it’s so buried under 3D rendering, it’s been about impossible to find something like SetPixel(int x, int y, int rgb). Any links toward something like that?

you could check Sdl2, Cairo.

Or direct framebuffer access like this :

https://stackoverflow.com/questions/1830836/how-to-draw-the-graph-in-framebuffer-using-c-language

there is also Processing which is nice to make quick and dirty graphic stuff without boilerplate code, but it is not C, it is based on java.

There are also simple bitmap file formats like this :

https://en.m.wikipedia.org/wiki/X_PixMap

Inspired by this, I experimented with the code to see what happened when you varied the values over time to make an animation.

https://www.youtube.com/watch?v=qSCr95gs-pg