There are two versions, but the first is merely the "better-looking" one, with unimportant squares filled in which colours instead of black. The effect of the program is to take in a number, and output either "PRIME" or "NOT PRIME" depending on which it is. The first part finds the whole number lower than the input's square root (a surprising amount of work in Piet) to save on runtime. Then, the program goes input-modulus-(2, 3, etc) to see if it has any factors. If it does, it goes through that big light magenta square to write out NOT, then into the dark cyan square. If none of the numbers below the square root are factors, it enters the dark cyan square. From there the program writes PRIME. It's strange that the text section takes up a lot more room than the calculation section.
This is similar code, but without the DP manipulation, since the black color block enforces program flow. Also included is an animated GIF consisting of 3 runnable variations of the static version. Note that the animated GIF can be run by the Piet interpreter! (Of course, I prefer the animated version.)
Program flow of these is obviously simple. They were made just to demonstrate how decorative Piet programs can be.
![]() Composition with Red, Yellow and Blue. 1921, Piet Mondrian. |
This was made with the goal of having a Piet program that really looks like a painting of Piet Mondrian. It prints "Piet".
I basically had it push 1, multiply a bunch of times (so as not to affect the stack) around the big blue block to get back to the beginning of the loop. That's where the majoriy of the steps come from. I could have had way fewer instructions by having only a few pushes/pops, but I figured I would make it pretty :-). It is a graphic language after all... I encourage everyone to try to write a Piet program, it's wonderfully mindbending.
Sylvain Tintillier provides a method of generating prime numbers using Piet. Figuring out how it works is easy, he says, "Just look at the bitmap!"
Richard Mitton supplies this amazing program which calculates an approximation of pi... literally by dividing a circular area by the radius twice.
Richard says:
The output is printed without the decimal point after the 3.Naturally, a more accurate value can be obtained by using a bigger program.