Piet- an esoteric programming language.

. .

The rectangle images all represent the same program, written in the lamguage 'Piet' and named after the artist Piet Mondrian. Programs in Piet are intended to look like believable Mondrian pictures, but are executable code.

Execution starts at the top left and heads towards the right. Only 20 colours are used in Piet code, and it is the TRANSITION to the next colour that governs the operation that will be effected. For non-looping code you could stay on a single 1D line. To make it visible to human eyes, rather than individual colour pixels, we scale it up to blocks, typically 20x20, called codels. Motion is orthogonal- diagonals are not allowed.

Oerations are stack based, rather like FORTH. Push and pop, then add, subtract, multiple and divide, plus roll and dup. Pointer and switch help control the execution path through the colour areas, called codels. User interaction is terminal input/output.

The Liberty BASIC angle.

So far I've written code for choosing colours, and can use my old stack examples too. I'll be dipping back into this as I get it more complete!

Why??

Why would anyone create such a weird language? Well, partly simply 'because', but also to point out that humans have involved to make major use of language and carried that into progranm coding, but also have vision/colour recognotion that can be used instead. And life on earth is coded in a language based on DNA codons. We could even code a language using musical notes.Perhaps aliens- and future computers- will operate with symbols or media that we have not even thought of.

I was also inspired by a lovely YouTube video on inventing a language that takes the WORST aspects or many common computer language- again just because it can be done! There's also a good YouTube on the language Piet.


Code



    '   demoTransitions2.bas

    nomainwin

    WindowWidth  = 950
    WindowHeight = 530

    graphicbox #w.gb1,  10,  10, 620, 380
    graphicbox #w.gb2,  10, 400, 620,  30

    button #w.b1, "Save ", save,  LR, 100,  20
    button #w.b2, "Clear", clear, LR, 300,  20

    texteditor #w.te1, 630,  10, 300, 420

    dim entry$( 20, 10)

    global PC
    PC      =1

    global hdc, targetcolor, col$

    open "Demo of Piet Transitions- colours and codes" for window as #w

    #w     "trapclose quit"
    #w.gb1 "font Arial bold 10"
    #w.gb1 "down"
    #w.gb1 "when leftButtonUp drawCodel"
    #w.gb2 "down ; fill 80 80 80"
    #w.te1 "!font Courier 14"

    hw      =hwnd( #w.gb1)
    calldll #user32, "GetDC", hw as ulong, hdc as ulong

    call drawColourTable



wait

    sub drawCodel h$, x, y
        'get colour from palette
        calldll #gdi32, "GetPixel", hdc as ulong, x as long, y as long, pixcol as ulong
        bl              = int(  pixcol /( 256*256))
        gr              = int( (pixcol -bl *256*256) / 256)
        re              = int(  pixcol -bl *256*256 -gr *256)
        'targetcolor     =bl *2^16    +gr *2^8    +re

        codelCol$   =right$( "000" +str$( re), 3) +" " +right$( "000" +str$( gr), 3) +" " +right$( "000" +str$( bl), 3)
        #w.gb2 "backcolor "; codelCol$      'draw next codel
        #w.gb2 "    color    black"
        #w.gb2 "up ; goto "; PC *22 -15; " "; 2; " ; down ; boxfilled "; PC *22 +19 -15; " 20"
        #w.te1 codelCol$
        PC      =PC +1
    end sub



    sub drawColourTable
        for x =0 to 5
            for y =0 to 2
                read i$: entry$( x, y) =i$
                #w.te1 x; " "; y; " "; entry$( x, y)
                c$      =word$( entry$( x, y), 1, "_")

                #w.gb1 "backcolor "; c$
                #w.gb1 "up ; goto ";         10 +100 *x; " ";  20 +100 *y
                #w.gb1 "down ; boxfilled "; 108 +100 *x; " "; 118 +100 *y

                n$      =word$( entry$( x, y), 2, "_")
                #w.gb1 "up ; goto ";         20 +100 *x; " "; 110 +100 *y
                #w.gb1 "down ; color black ; backcolor white"
                #w.gb1 "\"; n$

            next y
        next x

        for x =1 to 4 step 3
            y =3
            read i$: entry$( x, y) =i$
            c$      =word$( entry$( x, y), 1, "_")
            n$      =word$( entry$( x, y), 2, "_")

            if c$ ="255 255 255" then #w.gb1 "backcolor white ; color black" else #w.gb1 "backcolor black ; color white"
            #w.gb1 "up ; goto ";         100 *x  -90; " ";  250 +30 *y
            #w.gb1 "down ; boxfilled ";  100 *x +210; " ";  280 +30 *y


            #w.gb1 "up ; goto ";         15 +100 *x; " "; 58 +100 *y
            #w.gb1 "down"
            if c$ ="255 255 255" then #w.gb1 "color black ; backcolor white" else #w.gb1 "color white ; backcolor black"
            #w.gb1 "\"; n$
        next x

        data "255 192 192_    lt red   "
        data "255   0   0_      red    "
        data "192   0   0_    dk red   "

        data "255 255 192_   lt yellow "
        data "255 255   0_     yellow  "
        data "192 192   0_   dk yellow "

        data "192 255 192_   lt green  "
        data "  0 255   0_     green   "
        data "  0 192   0_   dk green  "

        data "192 255 255_    lt cyan  "
        data "  0 255 255_      cyan   "
        data "  0 192 192_    dk cyan  "

        data "192 192 255_    lt blue  "
        data "  0   0 255_      blue   "
        data "  0   0 192_    dk blue  "

        data "255 192 255_  lt magenta "
        data "255   0 255_    magenta  "
        data "192   0 192_  dk magenta "

        data "255 255 255_     white   "
        data "  0   0   0_     black   "


    end sub

    sub clear h$
        #w.gb2 "cls ; fill 80 80 80"
        PC      =1
    end sub

    sub save h$
        #w.te1 "!contents? contents$"
        open "PietSequence.txt" for output as #fOut
            #fOut contents$
        close #fOut
        #w.gb2 "getbmp scr 0 0 619 23"
        filedialog "Save as..", "sequence.bmp", fn$
        bmpsave "scr", fn$
    end sub

    sub quit handle$
        #w.gb2 "flush"
        calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong, ret as void   'release the DC
        notice "Leaving.."
        close #w
        end
    end sub