-
Notifications
You must be signed in to change notification settings - Fork 1
/
027_stroke_bezier_tolerance.zig
42 lines (33 loc) · 1.22 KB
/
027_stroke_bezier_tolerance.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: 0BSD
// Copyright © 2024 Chris Marchesi
//! Case: Renders and strokes stacked beziers of varying thickness on a 300x300
//! surface, at varying levels of error tolerance.
//!
//! The beziers are not closed.
const mem = @import("std").mem;
const z2d = @import("z2d");
pub const filename = "027_bezier_tolerance";
pub fn render(alloc: mem.Allocator, aa_mode: z2d.options.AntiAliasMode) !z2d.Surface {
const width = 300;
const height = 300;
var sfc = try z2d.Surface.init(.image_surface_rgb, alloc, width, height);
var context = try z2d.Context.init(alloc, &sfc);
defer context.deinit();
context.setSource(.{ .rgb = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF } });
context.setAntiAliasingMode(aa_mode);
context.setLineWidth(5);
try context.moveTo(19, 149);
try context.curveTo(89, 0, 209, 0, 279, 149);
try context.stroke();
context.setTolerance(3);
context.resetPath();
try context.moveTo(19, 199);
try context.curveTo(89, 24, 209, 24, 279, 199);
try context.stroke();
context.setTolerance(10);
context.resetPath();
try context.moveTo(19, 249);
try context.curveTo(89, 49, 209, 49, 279, 249);
try context.stroke();
return sfc;
}