Simple 2D Computer Graphics Library in C.
It stores some color codes of pixels in memory (called canvas here) and you are free to use this pixels wherever you want. You can write the pixels to .ppm
file or build .c
code to .wasm
and display the pixels on JavaScript Canvas. Keep reading to see examples on both platforms.
Visit orhanemree/aldrin.js to WebAssembly version.
Visit orhanemree/aldrin.py to Python wrapper.
Visit Playground to try online.
Visit Editor to try online editor project made with Aldrin.
/src/aldrin.c
file to your project.
#include "aldrin.c" // that's it!
Hello, World!
of Pixels#include <stdint.h>
#include "src/aldrin.c"
#define WIDTH 160
#define HEIGHT 90
static uint32_t pixels[WIDTH*HEIGHT];
int main() {
Aldrin_Canvas ac = { pixels, WIDTH, HEIGHT };
aldrin_fill(ac, 0xff00ff);
aldrin_save_ppm(ac, "img/hello_world.ppm");
return 0;
}
Output should look something like this:
Note that: aldrin_save_ppm()
function generates .ppm
output (see /img/hello_world.ppm
). The output converted to .png
format to be displayed here.
C
program.
$ clang -DPLATFORM_C -o <filename> <filename>.c
# or
$ gcc <filename>.c -o <filename> -DPLATFORM_C
.wasm
platform.
$ clang -DPLATFORM_WASM --target=wasm32 -o <filename>.o -c <filename>.c
$ wasm-ld --no-entry --allow-undefined --export-all -o <filename>.wasm <filename>.o
clang
and wasm-ld
installed./examples
.$ cd test
$ python main.py
$ python main.py help
docs/DOCUMENTATION.md
to read from file.website
to read from web and run examples live.