Graphical Brainfuck

From Esolang
Jump to navigation Jump to search

Graphical Brainfuck (GBF) is a esoteric programming language created by juju2143 in Febuary 2017. It is a multi-dimensional extension of Brainfuck that maps each triad of cells to a graphical screen.

Language overview

What would be the tape in normal Brainfuck is a three-dimensional 320x240 array of pixels matching the size of a graphical display, each pixel containing 3 cells for each of the three RGB color components. The programs start at (0,0,R), the commands are mostly the same as in Brainfuck, with the > and < commands moving the pointer along the cells on the X-axis, the R cell of the next pixel going after the B cell and vice-versa, wrapping back to the beginning or the end of the line in a circular fashion. + and - similarly wraps around when 0 or 255 are reached.

To move between the lines, GBF introduces an additional command, @, which flips between horizontal and vertical modes. In vertical mode, < moves up along the Y-axis instead of left, likewise for > which moves to the pixel below's R cell instead of the right pixel's when the pointer is on a B cell.

GBF does not change the color of the display by itself, instead the . command is used to send each of the three RGB cells of the current pixel at the current pointer position on the screen. In the reference implementation, ! is used to wait for a key, but the value isn't written to the cell like , does.

The language can be adapted to run with screen of any size than 320x240 and cells going up to other values than 255 to accomodate for other color spaces such as RGB565 (R and B goes up to 31, G goes up to 63), CMYK (which would require 4 cells/pixel instead of 3 going from 0 to 100) and HSL (H goes from 0 to 359 and S and L goes from 0 to 100), or even monochrome (probably more akin normal brainfuck at this point with a single bit/pixel and + ends up doing the same thing as - as bit flippers, @ may still be useful). If the screen is unbounded, the language should be Turing-complete.

Commands

Command Description
> Move the pointer to the cell to the right in horizontal mode or down in vertical mode
< Move the pointer to the cell to the left in horizontal mode or up in vertical mode
+ Increment the memory cell under the pointer
- Decrement the memory cell under the pointer
. Output the pixel the cell at the pointer is part of at the current pointer position on the screen
, Waits for key input and store the character in the cell at the pointer, mod the maximum capacity of that cell
[ Jump past the matching ] if the cell under the pointer is 0
] Jump back to the matching [ if the cell under the pointer is nonzero
@ Flips between horizontal and vertical modes
! Waits for key input, but discards it (optional)

Examples

Paints screen white

+[[--.>+]@>>>@+]

Implementations

  • razetime/graphical-bf: Supports all commands. Infinite canvas(Down and left), RGB, single byte cells, character-by character input. Github