https://github.com/jerr-it/canvas
Render images and videos directly using C
https://github.com/jerr-it/canvas
c c-language hacktoberfest netpbm rendering
Last synced: 11 months ago
JSON representation
Render images and videos directly using C
- Host: GitHub
- URL: https://github.com/jerr-it/canvas
- Owner: jerr-it
- License: mit
- Created: 2020-05-27T14:38:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-11T21:05:51.000Z (over 4 years ago)
- Last Synced: 2025-06-12T15:04:59.270Z (about 1 year ago)
- Topics: c, c-language, hacktoberfest, netpbm, rendering
- Language: C
- Homepage:
- Size: 1.45 MB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Canvas

Library for rendering images and videos directly using C and the NetPBM image format
How to use
Compile repo:
```
make
./render
or
g++ -o render main.cpp Artwork/Color.h Artwork/Artwork.h Artwork/Artwork.c
./render
```
Examples
Check main.cpp!
Include header:
```c
#include "Artwork/Artwork.h"
```
Create artwork and set values:
```c
Artwork art = newArt(400, 400);
```
Dont forget to free afterwards to avoid memory leaks!
```c
freeArt(art);
```
Set color scheme with stroke, fill and stroke width:
```c
art.strokeColor = Color { 255, 0, 0 };
art.strokeWidth = 5;
art.fillColor = Color { 200, 200, 200 };
```
Set individual pixel
```c
setPixel(art, , , Color {255, 255, 255});
```
Draw line (color determined by stroke color):
```c
drawLine(art, , , , );
```
Draw rect:
```c
drawRect(art, , , , );
```
Draw circle:
```c
drawCircle(art, , , );
```
Draw ellipse:
```c
drawEllipse(art, , , , );
```
Clear artwork / fill it entirely_
```c
clear(art, Color { 0, 0, 0 });
```
Save as a single image:
```c
char filename[] = "nicePic.ppm";
saveArt(art, filename);
```
Pipe it out (necessary for video creation):
```c
pipeArtTo(art, stdout);
```
Pipe it to VLC:
```
./ExecutableNameHere | ppmtoy4m -F60:1 | vlc -
```
Or render the complete video:
```
./ExecutableNameHere | ffmpeg -i pipe:0 -c:v libx264rgb VideoName.avi
```
SFML Tandem
The SFML_Artwork class is essentially a C++ wrapper for the standard rendering. It enables you to create Artworks from sf::Image objects, the entire window for example.
```c
#include "SFML_Artwork/SFML_Artwork.h"
```
Create your window and rendering:
```c
RenderWindow window(VideoMode(800, 800), "Rendering");
Rendering* rendering = createRendering(800, 800);
Texture texture;
Image image;
Vector2u windowsize;
```
Save your window as an image:
```c
windowsize = window.getSize();
texture.create(windowsize.x, windowsize.y);
texture.update(window);
image = texture.copyToImage();
Artwork art = SFML_Artwork::fromImage(image);
saveArt(art);
```