An open API service indexing awesome lists of open source software.

https://github.com/bratpeki/grap.h

A single-header text-based graphing library written in ANSI C
https://github.com/bratpeki/grap.h

c graph library terminal

Last synced: 12 months ago
JSON representation

A single-header text-based graphing library written in ANSI C

Awesome Lists containing this project

README

          

# A single-header text-based graphing library written in ANSI C

## Repo tree

```
.
├── ex
│ ├── cub.c
│ ├── lin.c
│ └── sqr.c
├── Makefile
├── README.md
└── src
└── grap.h
```

## What is it?

`grap.h` is an ANSI C single-header library for function graphing in the terminal.

## How does it work?

Below are the results of compiling the code examples from `ex` and running the output files.

### Linear function

```
$ make lin; ./lin
Linear function: y = -2*x + (3)
x.....................^......................
.xx...................|......................
...xx.................|......................
....xxx...............|......................
......xxx.............|......................
........xxx...........|......................
..........xx..........|......................
............xxx.......|......................
..............xx......|......................
................xx....|......................
..................xx..|......................
...................xxx|......................
----------------------xxx------------------->
......................|.xxx..................
......................|...xxx................
......................|.....xx...............
......................|.......xx.............
......................|.........xx...........
......................|...........xx.........
......................|.............xx.......
......................|..............xxx.....
......................|.................xx...
......................|..................xxx.
......................|....................x.
......................|......................
```

### Square function

```
$ make sqr; ./sqr
Square function: y=x^2
x.....................^......................
.x....................|....................x.
..x...................|...................x..
...x..................|..................x...
....x.................|.................x....
.....x................|................x.....
......xx..............|..............xx......
.......xx.............|.............xx.......
........xxx...........|...........xxx........
..........xx..........|..........xx..........
............xx........|........xx............
..............xxx.....|.....xxx..............
----------------xxxxxxxxxxxxx--------------->
......................|......................
......................|......................
......................|......................
......................|......................
......................|......................
......................|......................
......................|......................
......................|......................
......................|......................
......................|......................
......................|......................
......................|......................
```

### Cube function

```
$ make cub; ./cub
Cubic function: y=x^3
......................^......................
......................|....................x.
......................|....................x.
......................|...................x..
......................|..................x...
......................|.................x....
......................|................xx....
......................|...............xx.....
......................|..............xx......
......................|.............x........
......................|...........xx.........
......................|........xxx...........
-------------xxxxxxxxxxxxxxxxxxx------------>
...........xxx........|......................
.........xx...........|......................
........x.............|......................
......xx..............|......................
.....xx...............|......................
....xx................|......................
....x.................|......................
...x..................|......................
..x...................|......................
.x....................|......................
.x....................|......................
x.....................|......................
```

## How do I use it?

To use `grap.h`, simply import the library into your project and call the functions within it.

The functions are listed below:

| Function | Use case |
| ------------- | ---------------------------------------------- |
| `graphCreate` | Create the graph character array and return it |
| `graphDraw` | Display the graph character array |