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

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

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);
```