/bf2iq3

Brainfuck to IQ3 compiler

Primary LanguageShellMIT LicenseMIT

Brainfuck to IQ3 Compiler

IQ3 is a brainfuck derivative featuring Fujiwara Chika from the anime Kaguya-sama wa Kokurasetai.

Perequisites

Usage

To use bf2iq3:

  1. Clone this repo or unpack a release.

  2. cd into the directory containing the script. (Patches are welcome to make this script work anywhere.)

  3. Run the script. Pass the -h flag to view usage information. Its output is reproduced below.

     $ ./bf2iq3 -h
     Usage: bf2iq3 <input> <montage args>
            bf2iq3 -h
     Compiles brainfuck code to IQ3 using the ImageMagick montage program.
     
     PARAMETERS
        <input>	 The file containing brainfuck code. Pass "-" for stdin.
        <montage args>	The arguments to pass to montage. It must have at least the output file.
     
     OPTIONS
        -h	Show this help message.
    

For example, given the following example brainfuck program (examples/hello.bf):

+[-->-[>>+>-----<<]<--<---]>-.>>>+.>>..+++[.>]<<<<.+++.------.<<-.>>>>+.

The following command will compile it to IQ3 and write the resulting image to examples/hello.png:

./bf2iq3 examples/hello.bf examples/hello.png

This is the output:

+[-->-[>>+>-----<<]<--<---]>-.>>>+.>>..+++[.>]<<<<.+++.------.<<-.>>>>+.

The program can also be fed in from stdin by giving - as the input file:

echo ',[.[-],]' | ./bf2iq3 - out.png

All characters other than the eight brainfuck operators are stripped before compilation, so comments can be included in the source file.

montage flags

The default flags given to montage are -geometry +4+12 -tile 16x -bordercolor black -border 1, which tells montage to add a 1px black border around each tile, make the final image 16 tiles wide, and add 4px of horizontal padding and 12px of vertical padding around each tile.

These flags may be overridden by passing them in as part of <montage args>.

Other flags that may be of interest are:

-background color
background color
-texture filename
name of texture to tile onto the image background
-title string
decorate the montage image with a title
-font name
render text with this font
-pointsize value
font point size

Read more about montage and its usage.

Language specification

IQ3 is a brainfuck derivative and has a one-to-one mapping of operators (in other words, it is a trivial brainfuck substitution). The table below gives the mapping.

BF IQ3 Filename
> > rangle.png
< < langle.png
+ + plus.png
- - minus.png
. . dot.png
, , comma.png
[ [ lbracket.png
] ] rbracket.png

Images are tiled in order from left to right, top to bottom.

Credits

IQ3 was created by bucket3432. It makes use of crops from the anime Kaguya-sama wa Kokurasetai: Tensai-tachi no Renai Zunousen by A-1 Pictures (2019).

hello.bf was written by KSab.

License

The IQ3 compiler bf2iq3 is licensed under the MIT license. See the LICENSE file for details.