Skip to content

orhanemree/aldrin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👩‍🦰 Aldrin

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.

Quick Start

  • Just copy and paste /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.

Build

  • Build to normal C program.
$ clang -DPLATFORM_C -o <filename> <filename>.c
# or
$ gcc <filename>.c -o <filename> -DPLATFORM_C
  • Build to .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
  • Note: Make sure you have clang and wasm-ld installed.

Examples

Running Tests

  • You need Python to run tests.
$ cd test
$ python main.py
  • Get more info:
$ python main.py help

Documentation

References

License