User:GreenThePear/Sandbox
rgbl is an esoteric graphical programming language created by User:GreenThePear as an experiment to see how logic can be represented in digital images.
It is written by drawing a bitmap image, the state of which can change throughout the process. The head of the program starts in the top left pixel and travels along the pixels. The level of each pixel's color corresponds to a different logic component:
- Red: instruction signature
- Green: value (v
)
- Blue: step direction
Outside the bitmap data itself, rgbl stores a single value in memory (m
). Keeping with the common RGB model, all of the colors are 8 bit, which makes the language itself 8 bit.
For each pixel, the logic can be abstracted with:
1. Read and execute instruction of R
2. Possibly change the value of G, possibly memorize a value
3. Move to the next pixel defined by B
Instructions
An instruction can draw a value into a pixel (modify G) or save a value to memory (it "mems"). Every instruction except cross is followed by moving the head in the direction defined by B.
R | Name | Draws | Mems | |
---|---|---|---|---|
255 | cross | m
|
m
| |
0 - 63: General | ||||
0 | exit | Terminates program | ||
1 | draw | m
|
m
| |
2 | mem | v
|
v
| |
3 | swap | m
|
v
| |
64 - 127: IO | ||||
64* | stdout | v
|
v
| |
65** | stdin | stdin | stdin | |
128 - 191: Arithmetic | ||||
128 | add | v
|
m+v
| |
129 | sub | v
|
m-v
| |
130 | mult | v
|
m*v
| |
131 | div | v
|
m//v
| |
132 | mod | v
|
m%v
| |
192 - 254: Boolean | ||||
192 | eq | v
|
m==v
| |
193 | lt | v
|
m<v
| |
194 | le | v
|
m<=v
| |
195 | gt | v
|
m>v
| |
196 | ge | v
|
m>=v
|
* stdout prints m
before meming v
** stdin reads a character from stdin and draws and mems it
In the table v
is always the value before any drawing, so drawing v
just means leaving the pixel unchanged. R outside of the defined instructions will just be looped through for the rest of the category, so for example one can call add
with 128 but also 133, 138, 143, 148 and so on until 188.
For the boolean operations, true is represented as 1, while false as 0.
Directions
After executing any R instruction between 0 and 254, the program head moves by one pixel for any value of B%8 with a pattern going clockwise starting from the top (north) in a Moore neighborhood:
7 | 0 | 1 |
6 | 2 | |
5 | 4 | 3 |
If a direction points to the edge of the image (a non existent pixel) it is looped to the other side.
Cross
The cross instruction will only move the tape to the direction defined by B if m%8
equals 1. If it equals 0, then the direction flips 180° degrees and continues in the following pattern for any m%8
, here assuming that B directs up:
4 | 1 | 6 |
2 | 3 | |
7 | 0 | 5 |
If B doesn't direct up, the pattern is rotated accordingly, where B defines the starting direction.