Roger Antonsen
May 12, 2018

A Visual Quine for Processing

There is a small easter egg in the TED talk that I gave last weekend, and it is a visual quine for Processing.

A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are "self-replicating programs", "self-reproducing programs", and "self-copying programs".

By this definition, my program is strictly speaking not a quine, because the output is not the source code of the program, but a visualization of the source code. This program simply visualizes itself. In any case, it's fun.

Here is the code if you are interested! PS. If you do try it, you have to save it with the name “SelfDrawingSketch.pde”, otherwise it will not work.

String[] lines;
PFont font;
int counter;
float currentWidth, currentHeight;

void setup() {
  size(600, 800);
  lines = loadStrings("SelfDrawingSketch.pde");
  font = createFont("SourceCodePro-Regular", 12);
  stroke(0, 255, 0, 60);

void draw() {
  counter = 0;
  currentWidth = 40;
  currentHeight = g.textLeading;
  for (int i=0; i<lines.length; i++) {
    text(i+1, currentWidth-20, currentHeight);
    line(40, currentHeight, 40 + textWidth(lines[i]), currentHeight);
    for (int j=0; j<lines[i].length(); j++) {
      char c = lines[i].charAt(j);
      if (counter < frameCount) {
        text(c, currentWidth, currentHeight);
      currentWidth += textWidth(c);
    currentWidth = 40;
    currentHeight += g.textLeading;