Piet: Programming language in which programs look like abstract paintings (2002)
dangermouse.net
dangermouse.net
A guy (called Piet!) saw an artwork that reminded him of Piet (the lang) and tried executing it¹.
> It ran! [...] This is probably the first time in history that a graphic artist has painted a functionally workable computer program by accident.
[0]: https://www.dangermouse.net/esoteric/piet/samples.html [1]: https://gitlab.fabcity.hamburg/hofalab/piet-get-together
> Naturally, a more accurate value can be obtained by using a bigger program.
I think that's a first for me.
Edit: Oh yes, it's "westley" from 1988: https://www.ioccc.org/years-spoiler.html#1988_westley
EDIT: Ah, nvm. It's truncating the result to 2 decimal places.
There are just too many ways in JS to say Math.floor
If I remember correctly, this program also calculates pi more precisely the larger the circle.
> Unless otherwise indicated, the code comes from the International Obfuscated C code contest.
> It ran! The code executes an infinite loop which reads in ASCII characters and prints out the corresponding numerical ASCII values.
Get out of town. Get right out of town.
While impressive organically, it sounds easy when targeted; we could design a programming language where an image of Mona Lisa prints "hello world" - and claim a similar feat.
Perhaps the reverse is more interesting - programmers accidentally wrote a language that could treat real world abstract art as valid input.
Isn't that what happened here?
I.e. that “programmers accidentally wrote a language that could treat real world abstract art as valid input” - and to me it’s more interesting than what grand-grandparent is describing.
I think in this case, there is a coincidence on both sides? Like, the language or the painting could have been different such that the painting would run, but what it would do wouldn't be a recognizable task.
- for Perl, OCR to a character set
- for Piet, manual “convert[ion] into a clean image file using close colours from the Piet palette”
I don't actually have much idea of how far, numerically, colors vary due to different illumination, or due to different digitization processes.
It's also interesting to note that, for Piet, the colors themselves don't have any particular meaning, the instructions are encoded by the differentials between one color and the "next" color in the program direction, with blocks of continuous colors encoding noops. So moving from red to light red is a [0,-1] change, (no hue, 1 step lightness), and moving from blue to dark red is a change of [4,1] (4 steps of hue, 1 step of darkness). So the exact colors don't matter too much
I think this truly deserves a CS Ig Nobel Prize, if there were one, for making people laugh and then making people think.
However, another question is how many of such random images would actually do something "meaningful".
> The interpreter now begins sliding from its current white codel, in the new direction of the DP, until it either enters a coloured block or encounters another restriction.
The npiet interpreter, instead, rewinds its position to the last colored codel upon peeking through whitespace. One of these days, I intend to add that behavior as an option to the lexer in my Piet compiler[1], but I haven't bothered yet.
Following the spec, the program is a trivial nonhalting loop because the extreme corners of almost all blocks are white-adjacent. Writing complex Piet programs to target multiple interpreters and compilers is quite the challenge, as they've all got subtly different undocumented interpretations of the spec. I think that the output of my Piet backend is more or less interpreter-agnostic, but I've only dug into the details of three or four other interpreters.
I wish the language structure were designed in a way that anything that’s “written” with it would look like a Mondrian painting.
>What does an algorithm look like?
Is there a real-world possibility of creating something like to _The Glass Bead Game_ from Herman Hesse's novel (originally published as _Magister Ludi_)?
As a visually oriented person, I'd like to think so, and have actually tried to use such tools:
https://community.carbide3d.com/uploads/default/original/3X/...
but the danger has been, for want of an unambiguous answer to the afore-mentioned question, they always run the risk of:
https://blueprintsfromhell.tumblr.com/
https://scriptsofanotherdimension.tumblr.com/
and it's hard striking a balance between visual expressiveness and modularity (which all-too readily results in the wall of text which one is presumably trying to avoid).
Writing Piet by hand is a fun way to explore this. Sergei Lewis[1] and I[2] have each written tools to generate Piet code. Sergei's assembler makes much nicer looking code than my Piet backend. All you can really see from my compiler's output is that I'm really lazy and used a trampoline[3]
[1] http://www.toothycat.net/wiki/wiki.pl?MoonShadow/Piet
It is easy similarly to say that a for loop is the mental conception of "one thing going over a bunch of other things", which has a visual representation like "100" -> "010" -> "001".
I wonder then if its possible to create a language where one defines these constructs purely as visual transformations.
What if my computing model rely on quantum phenomenon ? Maybe some of them don't have good visual representation. But it's a guess. I don't know...
Regarding the global idea of your comment: what about languages such as J it APL or BQN ? In such languages each character is an atomic part of algorithms (in j, two characters are used to implement dynamic IF for instance. One character only is used to define the dimensional depth of each part of algorithms). In this way, iversonnian languages can be seen as general and pure visual representation of algorithms once you consider each J or APL character as an arbitrary glyph.
If what I am saying is true (that human language maps to transformations of space-time) then this theoretical computer should be able to represent quantum phenomena.
Im not familiar at all with APL or BQN but I think I understand what youre saying. I think the main point here isnt simply that you can represent programs visually, but that the visuals do exactly what you see. A "combine" instruction for example would literally be the visual of two objects with empty space transforming to the two objects being together.
Everything that happens happens in space and time, so it makes total sense that we have this common denominator of reasoning spatially that ties together images, written language, and sound.
I don't make a distinction between "reality" and the mental conception of reality. By all pragmatic takes, my mental experience IS reality. Anything beyond the means of observation may as well not exist.
Now as to the question of whether language can represent any mental conception, I am not so sure, but merely being enough to represent any physical system is plenty, and of this ability I am sure. Surely if I show you a video of any random thing happening, you can describe in some words EXACTLY what is happening such that another person can recreate that state perfectly. Without any abstractions you could give a description of every single object/pixel in your view, and with "higher" level abstractions like "everything is moving" you can create a lossy representation (which is often enough depending on as depending on the purpose, we don't always care about the actually state of the exact state of system, but rather that it possesses some property. "Something is moving" vs "nothing is moving").
From there, we spatialize and logicize concepts like "mine," "like me," "unlike me," "other," "in front," "back," and "forward."
Additionally, at the risk of igniting flames, I find it interesting to ponder the significance of gender in the current zeitgeist. Could attacking gender at a political level be a form of assault on sense-making, tugging at the roots of ontological logic centers in the brain? Might this destabilize civilization centers deemed as enemies by some? Feels like the right exploit from a hacker mentality.
And we all thought QR codes were useful...
Now that's deep.
I'm dating myself with this reference, but some of us old data fogeys might be wondering (well, I am, at any rate) when Piet came out compared to Pentaho's OLAP engine called Mondrian (https://mondrian.pentaho.com/documentation/olap.php)...
Would make for a great present as print!
More accurately, a programmer accidentally came up with a language that can run on real world paintings
Simplified Piet interpreter written in Python - https://news.ycombinator.com/item?id=33130954 - Oct 2022 (2 comments)
Piet, a programming language in which programs look like abstract paintings - https://news.ycombinator.com/item?id=21913483 - Dec 2019 (19 comments)
Piet – A programming language in which programs look like abstract paintings - https://news.ycombinator.com/item?id=13503841 - Jan 2017 (12 comments)
Sample programs in the Piet programming language - https://news.ycombinator.com/item?id=11342442 - March 2016 (27 comments)
Piet – visual programming language - https://news.ycombinator.com/item?id=11266653 - March 2016 (1 comment)
Piet Program Gallery - https://news.ycombinator.com/item?id=7727702 - May 2014 (4 comments)
Enterprise Piet - https://news.ycombinator.com/item?id=4698737 - Oct 2012 (39 comments)
Piet: programming with pixels - https://news.ycombinator.com/item?id=2430357 - April 2011 (3 comments)
Piet is a programming language, whose programs look like abstract art. - https://news.ycombinator.com/item?id=1166462 - March 2010 (28 comments)
Piet: a programming language in which programs look like abstract paintings - https://news.ycombinator.com/item?id=235975 - July 2008 (1 comment)
And you thought BrainFk was hard to understand... - https://news.ycombinator.com/item?id=139872 - March 2008 (2 comments)
---
Bonus:
Mondrian painting has been hanging upside down for 75 years - https://news.ycombinator.com/item?id=33370228 - Oct 2022 (71 comments)
Wish the sample programs were shown in action.
Basically you have some basic shapes like lines, rectangles and you can "weld" them together to form a mold, which could be joined together with other molds.
Then I created a pattern sequence with some basic transitions, like swapping positions or colors. https://github.com/ando818/creativegen/blob/master/pattern.p...
The program would then draw all the molds, and every 4,8,16, or whatever beats apply the transition from the pattern sequence. Ie every 4 beats swap, every 8 bits change colors. The idea was that you could form the pattern sequence quite easily and create interesting visuals that synced with music. I have some videos somewhere of this thing running, just not sure where they are.
Then I started thinking rectangles are really just composition of lines, lines are just composition of points. Transitions are just compositions of other transitions and I wanted to make everything out of the same thing. 4 years later honestly I don't have much to show for it. Its proven incredibly difficult and my ideas are all over the place. I've created literally 10-20 different implementations and started all over again. This is one of them.
https://pastebin.com/4J8dgAWu The idea is that each node (pixel, object, or whatever) is a "transformer" which has a start and end which themselves are transformers with a start, end, next. Following a transformer's start transformer's next pointer should lead to its End (think input, transformation sequence, output). We run a transformer A with an instance of a different transformer B. We iterate through the nexts of A's transformer and Bs transformer concurrently, at each step we apply the transformation from the A sequence to the B sequence. So for example, image B.start = 0, B.start.next = 1. And A.start = SameTransformer (copies the same value to the output) -> Diff Transformer(flips the bit). So running A.run(B) = a new transformation that takes the sequence 0,1, and returns 0,0. This new transformer C could then of course be used elsewhere as a part of another transformation sequence. So to transform 0,0,0,0, one could simply apply C,C to get transformer whose output is 0,1,0,1.
Its both linear and hierarchical, so one has the ability to jump over large steps (by immediately accessing the output, and not running through Start->End) of transformations if one is only interested in the outputs and not the computational steps that lead to that output. The hierarchy also allows the sequence to be treated as a single node as part of another sequence (hence applying Same to a subsequence can call same on everything below to copy it).
Ive used 0s and 1s here but instead imagine 0=Right and 1=Up. Then you can have a sequence of nexts that is something like right->up->right-up->up and run this as the input to a transformer that simply applies Same, Diff, replicating the sequence, and then copying the last value to get right->up->right-up->up->up.
So now imagine we make a transformer that flips the current bit, and the next bit (Diff, diff) and run it through the sequence 1,0,0,0,0,0. If we look at the output at each transformation step, we get 0,1,0,0,0 -> 0,0,1,0,0,0... But since were simply following the next path of any arbitrary sequence, this transformer could be run over the right-up->right->-up->up sequence, producing a visual with each of these nodes changing color one at a time.
The bigger idea is to generate abstract sequences that make stuff bigger and bigger, or rotate them, or pull them apart, or replicate them in some projection etc.
Of course there is a simple way to do this in existing languages that would take short of 10 seconds :->
There's still plenty to think about it. If that's confusing welcome to my world.
Save the image of the program and import it (e.g. https://www.toothycat.net/~sham/fizzbuzz.png ). You can then step through it.
There are several other implementations listed at https://esolangs.org/wiki/Piet