Demoscene-Type Obfuscated C Code Entry

This code did not win anything at the 2025 International Obfuscated C code competition (IOCCC29).

Code

Here is the code: demo.c




Video

As per tradition there's a typo on the title card. kdenlive could really use a spell-checker (or maybe it has one and I just shouldn't make movies in a rush).


Spoiler Warning

This is just four different demoscene effects, along with some bytebeat music.

Requirements

This requires a terminal emulator that supports 24-bit ANSI colors. These days most Linux terminal emulators do, including stock xterm (at least on Debian).

There is sound too! On a Debian system at least if you have
    /usr/bin/aplay
it will attempt to pipe the sound into it at the default 8kHz/8-bit unsigned.

Bugs

???

Obfuscation

I did this at the last minute and it ended up being mostly a size-coding exercise rather than any true obfuscation. All the graphics are the result of a very complex ternary expression though.

It is 681 bytes of C code, I had hoped to get it down to 512 bytes but ran out of time.

Background

The Audio

Bytebeat music is a genre where the music is made purely by math. One common form of it is just a C expression that takes a single argument, usually t for time, and it generates the sample for that timestep. The assumption is the output is treated as raw 8-bit audio to be played at 8kHz.

The bytebeat used here is:
buffer[t]=(t>>2|3*t|t>>8)*9+4*((t&t>>12)|t>>7);
This is based on a bytebeat by Tjoppen for use on 6502 processors, and was itself based on a combination of entries by viznut, xpansive, and varjohukka in a thread on pouet.net.

I took the baseline and modified the weights to be generated by a random number generator. Then I tried a large number of these randomly generated weights until I found one that I thought sounded interesting.

I had hoped to have a few more effects but the ones I tried did not really look that great at 80x24 resolution.

The Visuals

There are a series of four visuals that are cycled through. Each one the pattern can be generated solely based on the x and y co-ordinates. The idea for this is roughly based on the (much more impressive) 256-byte MS-DOS "Memories" demo by Hellmood.

There are two palette variants, so 8 visuals total. It would have been easy to add more but you're probably getting irritated by the music by that point.

Plasma

This is a plasma effect made with sine and cosine. It's why we have to link against -lm. This one if vaguely based on the low-res Apple II effect from the French Touch "Plasmagoria" demo.

Sierzoom

Rotozoom effect with Sierpinski triangles. You're only seeing small chunks of it here, due to low resolution, and also because what you see varies a lot based on the current frame.

Circles

A Memories-inspired effect. Nothing fancy here, just animated circles made with x**2+y**2

Moving Squares

This is done just with XOR

Back to my obfuscated C page