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
- Host: GitHub
- URL: https://github.com/bratpeki/grap.h
- Owner: bratpeki
- Created: 2021-10-20T18:11:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-15T12:18:19.000Z (over 2 years ago)
- Last Synced: 2024-01-15T15:48:33.466Z (over 2 years ago)
- Topics: c, graph, library, terminal
- Language: C
- Homepage:
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 |