Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ziglibs/painterz
Low-level implementation of different painting primitives (lines, rectangles, ...) without specialization on a certain draw target
https://github.com/ziglibs/painterz
2d-graphics canvas graphics painting zig zig-package ziglang
Last synced: about 2 months ago
JSON representation
Low-level implementation of different painting primitives (lines, rectangles, ...) without specialization on a certain draw target
- Host: GitHub
- URL: https://github.com/ziglibs/painterz
- Owner: ziglibs
- License: mit
- Created: 2020-07-16T09:35:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-18T11:25:32.000Z (3 months ago)
- Last Synced: 2024-09-18T16:10:23.823Z (3 months ago)
- Topics: 2d-graphics, canvas, graphics, painting, zig, zig-package, ziglang
- Language: Zig
- Homepage:
- Size: 23.4 KB
- Stars: 20
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - painterz🗒️Low-level implementation of different painting primitives (lines, rectangles, ...) without specialization on a certain draw target
README
# painterz
The idea of this library is to provide platform-independent, embedded-feasible implementations of several drawing primitives.
The library exports a generic `Canvas` type which is specialized on a `setPixel` function that will put pixels of type `Color` onto a `Framebuffer`.
It's currently not possible or planned to do blending, but alpha test could be implemented by ignoring certain color values in the `setPixel` function.## Usage Example
![Usage example rendering](docs/example.png)
See [`src/example.zig`](src/example.zig) for a full usage example.
```zig
const Pixel = packed struct {
r: u8, g: u8, b: u8, a: u8
};const Framebuffer = struct {
buffer: []Pixel,fn setPixel(fb: @This(), x: isize, y: isize, c: Pixel) void {
if (x < 0 or y < 0) return;
if (x >= 100 or y >= 100) return;
fb.buffer[100 * std.math.absCast(y) + std.math.absCast(x)] = c;
}
};var canvas = painterz.Canvas(Framebuffer, Pixel, Framebuffer.setPixel).init(Framebuffer{
.buffer = …,
});canvas.drawLine(100, 120, 110, 90, Pixel{
.r = 0xFF,
.g = 0x00,
.b = 0xFF,
.a = 0xFF,
});
```