added neg
Document how the expression becomes an image
updated worgle amalgamation. it is worglite by default
Bitlang is a tiny stack-based DSL, designed for the sole purpose of producing procedurally generated 1-bit art.
It is implemented in ANSI-C, and written in a literate programming style.
In bitlang, this expression:
x y + abs x y - abs 1 + ^ 2 << 3 % !
can be used to generate the following image:
by writing a 256 by 256 loop in C that sets x and y to each coordinate, asking bitlang the value of the expression, and treating true values as black pixels and false values as white pixels.
example.c
shows how it works and is a good template to start from.
Bitlang and the example program can be built running the
build.sh
script.
./build.sh
In addition to building the program, this script will tangle the bitlang program using a local version of Worgle.
The program, once compiled can be run with:
./example
Running this program will generate a PBM file called
example.pbm
, which can
be converted to a PNG file using imagemagick.
convert example.pbm example.png
Bitlang is written in a literate style, meaning that the code needs to be generated before it can be compiled. This process is called tangling. The tangler program has been included in this repo.
The files for bitlang (bitlang.c, bitlang.h) can be tangled by compiling the tangler and the running it on bitlang.org:
gcc worgle.c -o worglite
./worglite -g -Werror bitlang.org
Bitlang is a stack-based language, similar to RPN calculators and programs like dc.
2 3 +
Adds 2 and 3 together and pushes 5 onto the stack.
Special variables x, y, w, h, and t correspond to XY position, width, height, and time (as a frame number).
The following operations are currently supported:
Basic arithmetic: +, -, *, /
Modulo: %
Left/right shift: <<, >>
Equals operation: =
Logical and Bitwise OR: ||, |
Bitwise AND: &
XOR: ^
Logical and Bitwise NOT: !, ~
Absolute Value: abs
Bitlang tangles out into 2 files bitlang.c
and
bitlang.h
. These can be dropped.
For API usage, see example.c.
Bitlang is written in a literate style. The woven HTML component can be found and read here.