npiet 1.2

Version of implementation npiet of programming language Piet

Last (as of March 2011) version of npiet interpreter.

Examples:

Hello, World! - Piet (323):

This example uses only 2 commands — push and out (char). To print one character, one has to create a block of any color; the number of pixels in it should be equal to ASCII-code of this character. After this, one should create a block of color one shade darker of arbitrary size immediately to the right of that block (this will perform push command). Finally, a block of color one hue to the left of the original one of arbitrary size will perform out(char) command. After this, this sequence repeats for the next character.

To end program execution, we use a loop — a single-color block surrounded with black pixels. When the instruction pointer gets inside this block, it can’t leave in any direction.

The decorative version of the example shows that blocks can have any shape, even with pixels of other colors inside.

"Hello, World!" in Piet (basic)
"Hello, World!" in Piet (basic)

"Hello, World!" in Piet (basic, 5x scale)
"Hello, World!" in Piet (basic, 5x scale)

"Hello, World!" in Piet (decorative)
"Hello, World!" in Piet (decorative)

"Hello, World!" in Piet (decorative, 5x scale)
"Hello, World!" in Piet (decorative, 5x scale)

Hello, World! - Piet (373):

This example was generated using a translator by Sergei Lewis. It provides two tools — a translator from a simple C-like language into an assembler and from the assembler into the Piet image. In this case the original program looked like this:

main()
{
asm{ @"Hello, World!\r\n" }
}

Hello, World! in Piet (autogenerated)
Hello, World! in Piet (autogenerated)

Hello, World! in Piet (autogenerated, 5x scale)
Hello, World! in Piet (autogenerated, 5x scale)

Factorial - Piet (374):

This example was generated automatically. The original program translated into the image follows; it uses iterative factorial calculation. Note that values of 13! and larger are wrong due to overflow.

main()
{
  f = 1;
  for ( i = 0; i <= 16; i++ )
  {
    __outn(i);
    asm{ @"! = " }
    __outn(f);
    __out(10);
    f = f * (i+1);
  }
}

Factorial in Piet (autogenerated)
Factorial in Piet (autogenerated)

Factorial in Piet (autogenerated, 4x scale)
Factorial in Piet (autogenerated, 4x scale)

Fibonacci numbers - Piet (375):

This example was generated automatically. The original program translated into the image follows; it uses iterative calculation of Fibonacci numbers.

main()
{
  f1 = 0;
  f2 = 1;
  for ( i = 1; i <= 16; i++ )
  {
    __outn(f2);
    __out(44);
    __out(32);
    f2 = f1 + f2;
    f1 = f2 - f1;
  }
  __out(46);
  __out(46);
  __out(46);
  __out(10);
}

Fibonacci numbers in Piet (autogenerated)
Fibonacci numbers in Piet (autogenerated)

Fibonacci numbers in Piet (autogenerated, 4x scale)
Fibonacci numbers in Piet (autogenerated, 4x scale)