KaForkL - image programming language
KaForkL is an example for a two dimensional programming language based on image processing. After reading an article about Brainfuck2D, I thought that there should be a better way to program in a two dimensional way. You really miss something, when simply not using the additional dimension. After thinking some minutes about it, I wrote an initial design document and a simple interpreter in the next 2 - 3 hours.
Instead of using ASCII-documents, KaForkL bases on images, which give you a four-tuple for each node (or pixel) - you all know, the four channels: RGBA (red, green, blue, alpha). These four channels all have their special meanings:
-
Red
The red channel is considered as a bitmask describing in which directions the interpreter should walk from the current point. Each bit describes one direction, starting in the north with 1, north east with 2 etc. If more then one direction is given the interpreter will fork different processors with their own, independent stack.
-
Green
The green value is used to reference values on the processors stack. Each processor has 256 possible stack values. Mind, that their are not shared between the processors.
-
Blue
You can define values to use with processor in the blue channel. Depending on their context, they will be interpreted as a char (on output) or as an integer (with mathematical operations)
-
Alpha
In the alpha channel the command is defined. If set to 0 nothing special happens an the processor will only happily fork. A complete list of available commands can be found in doc/about in the repository. Their are several command categories:
-
Simple operations
Use to do nothing or to increase the processors step size temporary.
-
IO operations
Read or write from CLI, copy content into variables, or just copy variables on the stack.
-
Conditional statements
Conditions comparing value and stack content, which will continue or discontinue the processors operations.
-
Calculations
Everything like bit shifting, boolean operations and simple mathematical calculations.
-
Image manipulations
With this commands you can modify the image while executing a program. This can be used as global variables, but also to (interactively) create images or modify your program.
-
It is not really easy to create and debug images. To help with this you can use the IDE written with PHP-GTK available in the repository. It is described in more detail on the according subpage.
You want to see code? Here is the obligatory "Hello world!" example:
Another more interesting and more complex example is the code to output the text of the famous song "99 bottles of beer" on the left. The examples makes use of forking, conditions and loops. You perhaps want to try the IDE with this one to discover KaForkLs possibilities.
Btw.: KaForkL translates to "Kores awesome forking language" (after a suggestion by my colleague Kristan). :-)