npiet's gallery of piet programs - enjoy your visit


Click the pictures for a bigger version.
(please note: some of the png pictures seem to have a gamma value, so the colors maybe not correct).

Program Source TraceComments
The original Hello World! (from piet's page) bigger Hello world!
The Fibonacci Numbers example from piet's page Well, the execution seems to leave at the left upper yellow block erroneous in upper direction and not down, as intended.
A selfmade Fibonacci Numbers program
(36 trace steps)
Prints the Fibonacci Numbers below 1000. The large blue area (31 codels) is squared and used as upper limit. The 10 red codels (10 is ascii code for newline) in the upper middle are traversed one time left-to-right and in the loop then right-to-left (the second traversal is in the loop printing the values followed by a linefeed). The unused codels are filled with yellow.
A small example about crossing white areas gives an impression about traversing white blocks and the unpassable border.
A simple loop Counts from 10 to 1 in a loop. The decision is done in the lower line from right to left: The decremented loop value is duplicated, a 0 is pushed on the stack (push of a one followed by a not) and the test-result of a greater is the argument for the pointer: If it is 0 the loop is exited and if it is 1 the loop is reentered.
And here a straight forward hello world example This is done by a series of push and outchar commands.
The trace output shows the straight way with the black line from the upper-left codel to the right.
Not genious, but an easy way to output strings in piet.
Prime Number Tester

(This one is really a smile worth ;-)

The program starts with a in(number) and the read number is in a loop divided by the number-1 until 1 is reached. This is really the slowest way to do the prime test, but what the heck. The result of the test is printed as a Y if prime, or N if not.
The program really spents some of its time preparing and doing rolls of the stack, but thats the way if you can access only the top of the stack.
The big red color block represents the N result char and is the exit if the number is not prime. The block is traversed within the test loop too, but without a command to be executed.
The Y case is evaluated running into the green and dark-red color blocks at the right border (the Y is calculated there).
The white blocks traved through are used to seperate some of the evaluation steps and make it easier to code - i mean: easier to read.



Here some special created examples, differently interpreted by npiet and the Piet::Interpreter:

Program Source TraceComments
Toggle of dp and cc:

To enter the light red block, the first try is blocked and the cc has to be toggled. This sets dp=r and cc=r on entry of the light red block.
In the next step, again the way is blocked and the cc has to be toggled. The light blue block is entered with dp=r and cc=l .

Well, here the Piet::Interpreter proceeds from the light red block into the green block.

Black Blocks and Edges

Black colour blocks and the edges of the program restrict program flow. If the Piet interpreter attempts to move into a black block or off an edge, it is stopped and the CC is toggled. The interpreter then attempts to move from its current block again. If it fails a second time, the DP is moved clockwise one step. These attempts are repeated, with the CC and DP being changed between alternate attempts. If after eight attempts the interpreter cannot leave its current colour block, there is no way out and the program terminates.

I think, the Piet::Interpreter continues here into the wrong block.
Passing through white blocks The execution passes the white block towards the dp from the rightmost red codel. Again from the margenta codel the program flow passes straight right into the blue block.

Here the Piet::Interpreter passes through the green codel, which is imho wrong:

White Blocks

White colour blocks are "free" zones through which the interpreter passes unhindered. If it moves from a colour block into a white area, the interpreter "slides" through the white codels in the direction of the DP until it reaches a non-white colour block. If the interpreter slides into a black block or an edge, it is considered restricted (see above), otherwise it moves into the colour block so encountered. Sliding across white blocks does not cause a command to be executed (see below).

Well, yes, this leaves space for misinterpretion. But i think the interpretion of "slides" through the white codels in the direction of the DP until it reaches a non-white colour block describes more the npiet behavior (sliding straight through) and not the Piet::Interpreter behavior, which enters the white block like any color block and continues from there with respect to the dp/cc setting.



go back



Mon Jun 28 23:10:40 CEST 2004