← Back to news

A quine in Piet – a GIF image that prints itself [video]

youtube.com|65 points|8 comments|by surprisetalk|Aug 3, 2026

A Visual Paradox: The Piet Quine GIF

In the realm of esoteric programming languages (esolangs), there exists a fascinating intersection where art meets logic. One of the most striking examples of this is the creation of a quine written in Piet, which manifests physically as a GIF image that, when executed, prints its own binary data.

Understanding the Components

To appreciate the complexity of this feat, we must first define the two primary concepts involved:

1. What is Piet?

Named after the abstract artist Piet Mondrian, Piet is a language where the source code is not text, but an image. The "instructions" are determined by the transitions between different colored blocks (called codels).

2. What is a Quine?

A quine is a non-trivial program that takes no input and produces a copy of its own source code as its only output. Mathematically, if PP is the program, the operation can be described as: Output(P)=P\text{Output}(P) = P


The Technical Challenge

Creating a quine in a text-based language like C or Python is difficult; doing it in Piet is a nightmare. Doing it while ensuring the file is also a valid GIF is an exercise in extreme precision.

The Conflict of Formats

The programmer had to navigate two entirely different ways of interpreting data:

FeaturePiet InterpretationGIF Interpretation
Primary UnitColor blocks (Codels)Binary bytes / LZW compression
LogicHue/Lightness changesHeader \rightarrow Logical Screen Descriptor \rightarrow Image Data
GoalExecute commandsRender a visual image

"The goal wasn't just to make a program that prints a picture, but to make a picture that is the program, which then prints itself."

How It Works: The Execution Flow

The process follows a recursive loop of interpretation. The following diagram illustrates the lifecycle of the Piet GIF quine:

The Implementation Strategy

To achieve this, the author had to ensure that the binary representation of the GIF header (starting with GIF89a) and the image data mapped perfectly to the color transitions required by the Piet interpreter.

Standard coding involves writing logic and compiling it. In this case, the "coding" involved meticulously choosing colors so that the resulting binary file remained a valid image while simultaneously acting as a set of instructions to output those same bytes.

Requirements for Success

  • Valid GIF header and footer.
  • Piet instructions that can generate arbitrary byte values.
  • A loop mechanism to iterate through the entire file size.
  • Precise color mapping to avoid "illegal" Piet transitions.

The "Code" Behind the Art

While the source is an image, the underlying logic behaves like a low-level assembly language. For example, a transition from light red to dark red might represent a push operation.

# Conceptual logic of the quine's output loop
while not end_of_file:
    current_byte = get_next_pixel_color()
    print(convert_color_to_binary(current_byte))

The actual binary output must be exact. Even a single bit of difference would mean the output is no longer a valid GIF or no longer the same program, failing the definition of a quine.

Conclusion

This project is more than just a technical curiosity; it is a piece of digital performance art. It proves that the boundaries between data (the GIF), instruction (the Piet code), and output (the resulting file) are entirely fluid. By leveraging the unique properties of an image-based language, the creator successfully built a digital mirror that reflects itself perfectly.